1 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
4 CMAKE_POLICY(SET CMP0048 OLD)
8 #This is for copying the dll's needed by glpk (in lp_test and mip_test)
9 CMAKE_POLICY(SET CMP0026 OLD)
12 SET(PROJECT_NAME "LEMON")
13 PROJECT(${PROJECT_NAME})
15 INCLUDE(FindPythonInterp)
18 IF(EXISTS ${PROJECT_SOURCE_DIR}/cmake/version.cmake)
19 INCLUDE(${PROJECT_SOURCE_DIR}/cmake/version.cmake)
20 ELSEIF(DEFINED ENV{LEMON_VERSION})
21 SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.")
25 hg log -r. --template "{latesttag}"
26 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
27 OUTPUT_VARIABLE HG_REVISION_TAG
29 OUTPUT_STRIP_TRAILING_WHITESPACE
33 hg log -r. --template "{latesttagdistance}"
34 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
35 OUTPUT_VARIABLE HG_REVISION_DIST
37 OUTPUT_STRIP_TRAILING_WHITESPACE
41 hg log -r. --template "{node|short}"
42 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
43 OUTPUT_VARIABLE HG_REVISION_ID
45 OUTPUT_STRIP_TRAILING_WHITESPACE
48 IF(HG_REVISION_TAG STREQUAL "")
49 SET(HG_REVISION_ID "hg-tip")
51 IF(HG_REVISION_TAG STREQUAL "null")
52 SET(HG_REVISION_TAG "trunk")
53 ELSEIF(HG_REVISION_TAG MATCHES "^r")
54 STRING(SUBSTRING ${HG_REVISION_TAG} 1 -1 HG_REVISION_TAG)
56 IF(HG_REVISION_DIST STREQUAL "0")
57 SET(HG_REVISION ${HG_REVISION_TAG})
60 "${HG_REVISION_TAG}+${HG_REVISION_DIST}-${HG_REVISION_ID}")
64 SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.")
67 SET(PROJECT_VERSION ${LEMON_VERSION})
69 SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
72 FIND_PACKAGE(Ghostscript)
78 SET(LEMON_ENABLE_GLPK YES CACHE STRING "Enable GLPK solver backend.")
79 SET(LEMON_ENABLE_ILOG YES CACHE STRING "Enable ILOG (CPLEX) solver backend.")
80 SET(LEMON_ENABLE_COIN YES CACHE STRING "Enable COIN solver backend.")
81 SET(LEMON_ENABLE_SOPLEX YES CACHE STRING "Enable SoPlex solver backend.")
84 FIND_PACKAGE(GLPK 4.33)
86 SET(LEMON_HAVE_LP TRUE)
87 SET(LEMON_HAVE_MIP TRUE)
88 SET(LEMON_HAVE_GLPK TRUE)
90 ENDIF(LEMON_ENABLE_GLPK)
94 SET(LEMON_HAVE_LP TRUE)
95 SET(LEMON_HAVE_MIP TRUE)
96 SET(LEMON_HAVE_CPLEX TRUE)
98 ENDIF(LEMON_ENABLE_ILOG)
102 SET(LEMON_HAVE_LP TRUE)
103 SET(LEMON_HAVE_MIP TRUE)
104 SET(LEMON_HAVE_CLP TRUE)
105 SET(LEMON_HAVE_CBC TRUE)
107 ENDIF(LEMON_ENABLE_COIN)
108 IF(LEMON_ENABLE_SOPLEX)
111 SET(LEMON_HAVE_LP TRUE)
112 SET(LEMON_HAVE_SOPLEX TRUE)
114 ENDIF(LEMON_ENABLE_SOPLEX)
117 SET(DEFAULT_LP "CPLEX")
118 SET(DEFAULT_MIP "CPLEX")
120 SET(DEFAULT_LP "CLP")
121 SET(DEFAULT_MIP "CBC")
123 SET(DEFAULT_LP "GLPK")
124 SET(DEFAULT_MIP "GLPK")
126 SET(DEFAULT_LP "SOPLEX")
129 IF(NOT LEMON_DEFAULT_LP OR
130 (NOT ILOG_FOUND AND (LEMON_DEFAULT_LP STREQUAL "CPLEX")) OR
131 (NOT COIN_FOUND AND (LEMON_DEFAULT_LP STREQUAL "CLP")) OR
132 (NOT GLPK_FOUND AND (LEMON_DEFAULT_LP STREQUAL "GLPK")) OR
133 (NOT SOPLEX_FOUND AND (LEMON_DEFAULT_LP STREQUAL "SOPLEX")))
134 SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
135 "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)" FORCE)
137 SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
138 "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)")
140 IF(NOT LEMON_DEFAULT_MIP OR
141 (NOT ILOG_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "CPLEX")) OR
142 (NOT COIN_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "CBC")) OR
143 (NOT GLPK_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "GLPK")))
144 SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING
145 "Default MIP solver backend (GLPK, CPLEX or CBC)" FORCE)
147 SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING
148 "Default MIP solver backend (GLPK, CPLEX or CBC)")
152 IF(DEFINED ENV{LEMON_CXX_WARNING})
153 SET(CXX_WARNING $ENV{LEMON_CXX_WARNING})
155 IF(CMAKE_COMPILER_IS_GNUCXX)
156 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")
157 SET(CMAKE_CXX_FLAGS_DEBUG CACHE STRING "-ggdb")
158 SET(CMAKE_C_FLAGS_DEBUG CACHE STRING "-ggdb")
160 # This part is unnecessary 'casue the same is set by the lemon/core.h.
161 # Still kept as an example.
163 # SET(CXX_WARNING "/wd4250 /wd4267 /wd4355 /wd4503 /wd4800 /wd4996")
165 # Suppressed warnings:
166 # C4250: 'class1' : inherits 'class2::member' via dominance
167 # C4267: conversion from 'size_t' to 'type', possible loss of data
168 # C4355: 'this' : used in base member initializer list
169 # C4503: 'function' : decorated name length exceeded, name was truncated
170 # C4800: 'type' : forcing value to bool 'true' or 'false'
171 # (performance warning)
172 # C4996: 'function': was declared deprecated
174 SET(CXX_WARNING "-Wall")
177 SET(LEMON_CXX_WARNING_FLAGS ${CXX_WARNING} CACHE STRING "LEMON warning flags.")
179 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LEMON_CXX_WARNING_FLAGS}")
182 SET(CMAKE_CXX_FLAGS "/bigobj ${CMAKE_CXX_FLAGS}")
183 SET( CMAKE_CXX_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
184 "Flags used by the C++ compiler during maintainer builds."
186 SET( CMAKE_C_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
187 "Flags used by the C compiler during maintainer builds."
189 SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
190 "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
191 "Flags used for linking binaries during maintainer builds."
193 SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
194 "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING
195 "Flags used by the shared libraries linker during maintainer builds."
198 SET( CMAKE_CXX_FLAGS_MAINTAINER "-Werror -ggdb -O0" CACHE STRING
199 "Flags used by the C++ compiler during maintainer builds."
201 SET( CMAKE_C_FLAGS_MAINTAINER "-Werror -O0" CACHE STRING
202 "Flags used by the C compiler during maintainer builds."
204 SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
205 "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
206 "Flags used for linking binaries during maintainer builds."
208 SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
209 "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING
210 "Flags used by the shared libraries linker during maintainer builds."
215 CMAKE_CXX_FLAGS_MAINTAINER
216 CMAKE_C_FLAGS_MAINTAINER
217 CMAKE_EXE_LINKER_FLAGS_MAINTAINER
218 CMAKE_SHARED_LINKER_FLAGS_MAINTAINER )
220 IF(CMAKE_CONFIGURATION_TYPES)
221 LIST(APPEND CMAKE_CONFIGURATION_TYPES Maintainer)
222 LIST(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
223 SET(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
224 "Add the configurations that we need"
228 IF(NOT CMAKE_BUILD_TYPE)
229 SET(CMAKE_BUILD_TYPE "Release")
232 SET( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
233 "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel Maintainer."
237 INCLUDE(CheckTypeSize)
238 CHECK_TYPE_SIZE("long long" LONG_LONG)
239 SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
243 IF(NOT LEMON_THREADING)
244 IF(CMAKE_USE_PTHREADS_INIT)
245 SET(LEMON_THREADING "Pthread")
246 ELSEIF(CMAKE_USE_WIN32_THREADS_INIT)
247 SET(LEMON_THREADING "Win32")
249 SET(LEMON_THREADING "None")
253 SET( LEMON_THREADING "${LEMON_THREADING}" CACHE STRING
254 "Choose the threading library, options are: Pthread Win32 None."
257 IF(LEMON_THREADING STREQUAL "Pthread")
258 SET(LEMON_USE_PTHREAD TRUE)
259 ELSEIF(LEMON_THREADING STREQUAL "Win32")
260 SET(LEMON_USE_WIN32_THREADS TRUE)
265 IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer")
266 ADD_CUSTOM_TARGET(check ALL COMMAND ${CMAKE_CTEST_COMMAND})
268 ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
271 ADD_SUBDIRECTORY(lemon)
272 IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
273 ADD_SUBDIRECTORY(contrib)
274 ADD_SUBDIRECTORY(demo)
275 ADD_SUBDIRECTORY(tools)
276 ADD_SUBDIRECTORY(doc)
277 ADD_SUBDIRECTORY(test)
281 ${PROJECT_SOURCE_DIR}/cmake/LEMONConfig.cmake.in
282 ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
287 FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
288 DESTINATION share/lemon/cmake
292 FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
298 ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in
299 ${PROJECT_BINARY_DIR}/cmake/version.cmake
303 SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME})
304 STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME)
305 SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION})
306 ADD_CUSTOM_TARGET(dist
307 COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
308 COMMAND hg archive ${ARCHIVE_NAME}
309 COMMAND cmake -E copy cmake/version.cmake ${ARCHIVE_NAME}/cmake/version.cmake
310 COMMAND tar -czf ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_NAME}
311 COMMAND zip -r ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.zip ${ARCHIVE_NAME}
312 COMMAND cmake -E copy_directory doc/html ${ARCHIVE_NAME}/doc/html
313 COMMAND tar -czf ${ARCHIVE_NAME}.tar.gz ${ARCHIVE_NAME}
314 COMMAND zip -r ${ARCHIVE_NAME}.zip ${ARCHIVE_NAME}
315 COMMAND cmake -E copy_directory doc/html ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
316 COMMAND tar -czf ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
317 COMMAND zip -r ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.zip ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
318 COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
319 COMMAND cmake -E remove_directory ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
321 WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
323 # CPACK config (Basically for NSIS)
324 IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
325 SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
326 SET(CPACK_PACKAGE_VENDOR "EGRES")
327 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
328 "LEMON - Library for Efficient Modeling and Optimization in Networks")
329 SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
331 SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
333 SET(CPACK_PACKAGE_INSTALL_DIRECTORY
334 "${PROJECT_NAME} ${PROJECT_VERSION}")
335 SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
336 "${PROJECT_NAME} ${PROJECT_VERSION}")
338 SET(CPACK_COMPONENTS_ALL headers library html_documentation bin)
340 SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers")
341 SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Dynamic-link library")
342 SET(CPACK_COMPONENT_BIN_DISPLAY_NAME "Command line utilities")
343 SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation")
345 SET(CPACK_COMPONENT_HEADERS_DESCRIPTION
347 SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION
348 "DLL and import library")
349 SET(CPACK_COMPONENT_BIN_DESCRIPTION
350 "Command line utilities")
351 SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION
352 "Doxygen generated documentation")
354 SET(CPACK_COMPONENT_HEADERS_DEPENDS library)
356 SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
357 SET(CPACK_COMPONENT_LIBRARY_GROUP "Development")
358 SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation")
360 SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
361 "Components needed to develop software using LEMON")
362 SET(CPACK_COMPONENT_GROUP_DOCUMENTATION_DESCRIPTION
363 "Documentation of LEMON")
365 SET(CPACK_ALL_INSTALL_TYPES Full Developer)
367 SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
368 SET(CPACK_COMPONENT_LIBRARY_INSTALL_TYPES Developer Full)
369 SET(CPACK_COMPONENT_HTML_DOCUMENTATION_INSTALL_TYPES Full)
371 SET(CPACK_GENERATOR "NSIS")
372 SET(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis/lemon.ico")
373 SET(CPACK_NSIS_MUI_UNIICON "${PROJECT_SOURCE_DIR}/cmake/nsis/uninstall.ico")
374 #SET(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis\\\\installer.bmp")
375 SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lemon.ico")
376 SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}")
377 SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\lemon.cs.elte.hu")
378 SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\lemon.cs.elte.hu")
379 SET(CPACK_NSIS_CONTACT "lemon-user@lemon.cs.elte.hu")
380 SET(CPACK_NSIS_CREATE_ICONS_EXTRA "
381 CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation.lnk\\\" \\\"$INSTDIR\\\\share\\\\doc\\\\index.html\\\"
383 SET(CPACK_NSIS_DELETE_ICONS_EXTRA "
384 !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
385 Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation.lnk\\\"