1 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
4 CMAKE_POLICY(SET CMP0048 OLD)
8 CMAKE_POLICY(SET CMP0043 OLD)
12 #This is for copying the dll's needed by glpk (in lp_test and mip_test)
13 CMAKE_POLICY(SET CMP0026 OLD)
16 SET(PROJECT_NAME "LEMON")
17 PROJECT(${PROJECT_NAME})
19 INCLUDE(FindPythonInterp)
22 IF(EXISTS ${PROJECT_SOURCE_DIR}/cmake/version.cmake)
23 INCLUDE(${PROJECT_SOURCE_DIR}/cmake/version.cmake)
24 ELSEIF(DEFINED ENV{LEMON_VERSION})
25 SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.")
29 hg log -r. --template "{latesttag}"
30 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
31 OUTPUT_VARIABLE HG_REVISION_TAG
33 OUTPUT_STRIP_TRAILING_WHITESPACE
37 hg log -r. --template "{latesttagdistance}"
38 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
39 OUTPUT_VARIABLE HG_REVISION_DIST
41 OUTPUT_STRIP_TRAILING_WHITESPACE
45 hg log -r. --template "{node|short}"
46 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
47 OUTPUT_VARIABLE HG_REVISION_ID
49 OUTPUT_STRIP_TRAILING_WHITESPACE
52 IF(HG_REVISION_TAG STREQUAL "")
53 SET(HG_REVISION_ID "hg-tip")
55 IF(HG_REVISION_TAG STREQUAL "null")
56 SET(HG_REVISION_TAG "trunk")
57 ELSEIF(HG_REVISION_TAG MATCHES "^r")
58 STRING(SUBSTRING ${HG_REVISION_TAG} 1 -1 HG_REVISION_TAG)
60 IF(HG_REVISION_DIST STREQUAL "0")
61 SET(HG_REVISION ${HG_REVISION_TAG})
64 "${HG_REVISION_TAG}+${HG_REVISION_DIST}-${HG_REVISION_ID}")
68 SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.")
71 SET(PROJECT_VERSION ${LEMON_VERSION})
73 SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
76 FIND_PACKAGE(Ghostscript)
82 SET(LEMON_ENABLE_GLPK YES CACHE STRING "Enable GLPK solver backend.")
83 SET(LEMON_ENABLE_ILOG YES CACHE STRING "Enable ILOG (CPLEX) solver backend.")
84 SET(LEMON_ENABLE_COIN YES CACHE STRING "Enable COIN solver backend.")
85 SET(LEMON_ENABLE_SOPLEX YES CACHE STRING "Enable SoPlex solver backend.")
88 FIND_PACKAGE(GLPK 4.33)
90 SET(LEMON_HAVE_LP TRUE)
91 SET(LEMON_HAVE_MIP TRUE)
92 SET(LEMON_HAVE_GLPK TRUE)
94 ENDIF(LEMON_ENABLE_GLPK)
98 SET(LEMON_HAVE_LP TRUE)
99 SET(LEMON_HAVE_MIP TRUE)
100 SET(LEMON_HAVE_CPLEX TRUE)
102 ENDIF(LEMON_ENABLE_ILOG)
103 IF(LEMON_ENABLE_COIN)
106 SET(LEMON_HAVE_LP TRUE)
107 SET(LEMON_HAVE_MIP TRUE)
108 SET(LEMON_HAVE_CLP TRUE)
109 SET(LEMON_HAVE_CBC TRUE)
111 ENDIF(LEMON_ENABLE_COIN)
112 IF(LEMON_ENABLE_SOPLEX)
115 SET(LEMON_HAVE_LP TRUE)
116 SET(LEMON_HAVE_SOPLEX TRUE)
118 ENDIF(LEMON_ENABLE_SOPLEX)
121 SET(DEFAULT_LP "CPLEX")
122 SET(DEFAULT_MIP "CPLEX")
124 SET(DEFAULT_LP "CLP")
125 SET(DEFAULT_MIP "CBC")
127 SET(DEFAULT_LP "GLPK")
128 SET(DEFAULT_MIP "GLPK")
130 SET(DEFAULT_LP "SOPLEX")
133 IF(NOT LEMON_DEFAULT_LP OR
134 (NOT ILOG_FOUND AND (LEMON_DEFAULT_LP STREQUAL "CPLEX")) OR
135 (NOT COIN_FOUND AND (LEMON_DEFAULT_LP STREQUAL "CLP")) OR
136 (NOT GLPK_FOUND AND (LEMON_DEFAULT_LP STREQUAL "GLPK")) OR
137 (NOT SOPLEX_FOUND AND (LEMON_DEFAULT_LP STREQUAL "SOPLEX")))
138 SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
139 "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)" FORCE)
141 SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
142 "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)")
144 IF(NOT LEMON_DEFAULT_MIP OR
145 (NOT ILOG_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "CPLEX")) OR
146 (NOT COIN_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "CBC")) OR
147 (NOT GLPK_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "GLPK")))
148 SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING
149 "Default MIP solver backend (GLPK, CPLEX or CBC)" FORCE)
151 SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING
152 "Default MIP solver backend (GLPK, CPLEX or CBC)")
155 IF( ( ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") AND
156 ("${CMAKE_CXX_COMPILER_VERSION}" VERSION_GREATER_EQUAL "4.8") )
157 OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
158 OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
160 SET(LEMON_NO_UNUSED_LOCAL_TYPEDEF_WARNINGS TRUE)
163 IF(DEFINED ENV{LEMON_CXX_WARNING})
164 SET(CXX_WARNING $ENV{LEMON_CXX_WARNING})
166 IF( ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
167 OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
169 SET(CXX_WARNING "-Wall -W -Wunused -Wformat=2 -Wctor-dtor-privacy -Wnon-virtual-dtor -Wno-char-subscripts -Wwrite-strings -Wno-char-subscripts -Wreturn-type -Wcast-qual -Wcast-align -Wsign-promo -Woverloaded-virtual -fno-strict-aliasing -Wold-style-cast -Wno-unknown-pragmas")
170 SET(CMAKE_CXX_FLAGS_DEBUG CACHE STRING "-ggdb")
171 SET(CMAKE_C_FLAGS_DEBUG CACHE STRING "-ggdb")
172 ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
173 SET(CXX_WARNING "-Wall -W -Wunused -Wformat=2 -Wnon-virtual-dtor -Wno-char-subscripts -Wwrite-strings -Wno-char-subscripts -Wreturn-type -Wcast-qual -Wsign-promo -Woverloaded-virtual -fno-strict-aliasing -Wno-unknown-pragmas")
174 SET(CMAKE_CXX_FLAGS_DEBUG CACHE STRING "-ggdb")
175 SET(CMAKE_C_FLAGS_DEBUG CACHE STRING "-ggdb")
177 # This part is unnecessary 'casue the same is set by the lemon/core.h.
178 # Still kept as an example.
180 # SET(CXX_WARNING "/wd4250 /wd4267 /wd4355 /wd4503 /wd4800 /wd4996")
182 # Suppressed warnings:
183 # C4250: 'class1' : inherits 'class2::member' via dominance
184 # C4267: conversion from 'size_t' to 'type', possible loss of data
185 # C4355: 'this' : used in base member initializer list
186 # C4503: 'function' : decorated name length exceeded, name was truncated
187 # C4800: 'type' : forcing value to bool 'true' or 'false'
188 # (performance warning)
189 # C4996: 'function': was declared deprecated
191 SET(CXX_WARNING "-Wall")
194 SET(LEMON_CXX_WARNING_FLAGS ${CXX_WARNING} CACHE STRING "LEMON warning flags.")
196 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LEMON_CXX_WARNING_FLAGS}")
199 SET(CMAKE_CXX_FLAGS "/bigobj ${CMAKE_CXX_FLAGS}")
200 SET( CMAKE_CXX_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
201 "Flags used by the C++ compiler during maintainer builds."
203 SET( CMAKE_C_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
204 "Flags used by the C compiler during maintainer builds."
206 SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
207 "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
208 "Flags used for linking binaries during maintainer builds."
210 SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
211 "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING
212 "Flags used by the shared libraries linker during maintainer builds."
215 SET( CMAKE_CXX_FLAGS_MAINTAINER "-Werror -ggdb -O0" CACHE STRING
216 "Flags used by the C++ compiler during maintainer builds."
218 SET( CMAKE_C_FLAGS_MAINTAINER "-Werror -O0" CACHE STRING
219 "Flags used by the C compiler during maintainer builds."
221 SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
222 "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
223 "Flags used for linking binaries during maintainer builds."
225 SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
226 "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING
227 "Flags used by the shared libraries linker during maintainer builds."
232 CMAKE_CXX_FLAGS_MAINTAINER
233 CMAKE_C_FLAGS_MAINTAINER
234 CMAKE_EXE_LINKER_FLAGS_MAINTAINER
235 CMAKE_SHARED_LINKER_FLAGS_MAINTAINER )
237 IF(CMAKE_CONFIGURATION_TYPES)
238 LIST(APPEND CMAKE_CONFIGURATION_TYPES Maintainer)
239 LIST(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
240 SET(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
241 "Add the configurations that we need"
245 IF(NOT CMAKE_BUILD_TYPE)
246 SET(CMAKE_BUILD_TYPE "Release")
249 SET( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
250 "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel Maintainer."
253 SET_DIRECTORY_PROPERTIES(PROPERTIES
254 COMPILE_DEFINITIONS_DEBUG "LEMON_ENABLE_DEBUG"
255 COMPILE_DEFINITIONS_MAINTAINER "LEMON_ENABLE_DEBUG"
258 INCLUDE(CheckTypeSize)
259 CHECK_TYPE_SIZE("long long" LONG_LONG)
260 SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
264 IF(NOT LEMON_THREADING)
265 IF(CMAKE_USE_PTHREADS_INIT)
266 SET(LEMON_THREADING "Pthread")
267 ELSEIF(CMAKE_USE_WIN32_THREADS_INIT)
268 SET(LEMON_THREADING "Win32")
270 SET(LEMON_THREADING "None")
274 SET( LEMON_THREADING "${LEMON_THREADING}" CACHE STRING
275 "Choose the threading library, options are: Pthread Win32 None."
278 IF(LEMON_THREADING STREQUAL "Pthread")
279 SET(LEMON_USE_PTHREAD TRUE)
280 ELSEIF(LEMON_THREADING STREQUAL "Win32")
281 SET(LEMON_USE_WIN32_THREADS TRUE)
287 INCLUDE(CheckCXXCompilerFlag)
288 CHECK_CXX_COMPILER_FLAG("-std=c++11" LEMON_CXX11)
290 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
294 IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer")
295 ADD_CUSTOM_TARGET(check ALL COMMAND ${CMAKE_CTEST_COMMAND})
297 ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
300 ADD_SUBDIRECTORY(lemon)
301 IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
302 ADD_SUBDIRECTORY(contrib)
303 ADD_SUBDIRECTORY(demo)
304 ADD_SUBDIRECTORY(tools)
305 ADD_SUBDIRECTORY(doc)
306 ADD_SUBDIRECTORY(test)
310 ${PROJECT_SOURCE_DIR}/cmake/LEMONConfig.cmake.in
311 ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
316 FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
317 DESTINATION share/lemon/cmake
321 FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
327 ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in
328 ${PROJECT_BINARY_DIR}/cmake/version.cmake
332 SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME})
333 STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME)
334 SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION})
335 ADD_CUSTOM_TARGET(dist
336 COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
337 COMMAND hg archive ${ARCHIVE_NAME}
338 COMMAND cmake -E copy cmake/version.cmake ${ARCHIVE_NAME}/cmake/version.cmake
339 COMMAND tar -czf ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_NAME}
340 COMMAND zip -r ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.zip ${ARCHIVE_NAME}
341 COMMAND cmake -E copy_directory doc/html ${ARCHIVE_NAME}/doc/html
342 COMMAND tar -czf ${ARCHIVE_NAME}.tar.gz ${ARCHIVE_NAME}
343 COMMAND zip -r ${ARCHIVE_NAME}.zip ${ARCHIVE_NAME}
344 COMMAND cmake -E copy_directory doc/html ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
345 COMMAND tar -czf ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
346 COMMAND zip -r ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.zip ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
347 COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
348 COMMAND cmake -E remove_directory ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
350 WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
352 # CPACK config (Basically for NSIS)
353 IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
354 SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
355 SET(CPACK_PACKAGE_VENDOR "EGRES")
356 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
357 "LEMON - Library for Efficient Modeling and Optimization in Networks")
358 SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
360 SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
362 SET(CPACK_PACKAGE_INSTALL_DIRECTORY
363 "${PROJECT_NAME} ${PROJECT_VERSION}")
364 SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
365 "${PROJECT_NAME} ${PROJECT_VERSION}")
367 SET(CPACK_COMPONENTS_ALL headers library html_documentation bin)
369 SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers")
370 SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Dynamic-link library")
371 SET(CPACK_COMPONENT_BIN_DISPLAY_NAME "Command line utilities")
372 SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation")
374 SET(CPACK_COMPONENT_HEADERS_DESCRIPTION
376 SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION
377 "DLL and import library")
378 SET(CPACK_COMPONENT_BIN_DESCRIPTION
379 "Command line utilities")
380 SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION
381 "Doxygen generated documentation")
383 SET(CPACK_COMPONENT_HEADERS_DEPENDS library)
385 SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
386 SET(CPACK_COMPONENT_LIBRARY_GROUP "Development")
387 SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation")
389 SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
390 "Components needed to develop software using LEMON")
391 SET(CPACK_COMPONENT_GROUP_DOCUMENTATION_DESCRIPTION
392 "Documentation of LEMON")
394 SET(CPACK_ALL_INSTALL_TYPES Full Developer)
396 SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
397 SET(CPACK_COMPONENT_LIBRARY_INSTALL_TYPES Developer Full)
398 SET(CPACK_COMPONENT_HTML_DOCUMENTATION_INSTALL_TYPES Full)
400 SET(CPACK_GENERATOR "NSIS")
401 SET(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis/lemon.ico")
402 SET(CPACK_NSIS_MUI_UNIICON "${PROJECT_SOURCE_DIR}/cmake/nsis/uninstall.ico")
403 #SET(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis\\\\installer.bmp")
404 SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lemon.ico")
405 SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}")
406 SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\lemon.cs.elte.hu")
407 SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\lemon.cs.elte.hu")
408 SET(CPACK_NSIS_CONTACT "lemon-user@lemon.cs.elte.hu")
409 SET(CPACK_NSIS_CREATE_ICONS_EXTRA "
410 CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation.lnk\\\" \\\"$INSTDIR\\\\share\\\\doc\\\\index.html\\\"
412 SET(CPACK_NSIS_DELETE_ICONS_EXTRA "
413 !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
414 Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation.lnk\\\"