COIN-OR::LEMON - Graph Library

source: lemon-main/CMakeLists.txt @ 1108:e00d7b681d8e

Last change on this file since 1108:e00d7b681d8e was 1107:e937009e4c5f, checked in by Alpar Juttner <alpar@…>, 11 years ago

Require CMAKE 2.8 (#484)

File size: 12.4 KB
RevLine 
[1107]1CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
[225]2
[678]3SET(PROJECT_NAME "LEMON")
4PROJECT(${PROJECT_NAME})
[225]5
[927]6INCLUDE(FindPythonInterp)
7INCLUDE(FindWget)
8
[678]9IF(EXISTS ${PROJECT_SOURCE_DIR}/cmake/version.cmake)
10  INCLUDE(${PROJECT_SOURCE_DIR}/cmake/version.cmake)
11ELSEIF(DEFINED ENV{LEMON_VERSION})
12  SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.")
13ELSE()
14  EXECUTE_PROCESS(
[982]15    COMMAND
16    hg log -r. --template "{latesttag}"
[927]17    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
[982]18    OUTPUT_VARIABLE HG_REVISION_TAG
[927]19    ERROR_QUIET
20    OUTPUT_STRIP_TRAILING_WHITESPACE
21  )
22  EXECUTE_PROCESS(
[982]23    COMMAND
24    hg log -r. --template "{latesttagdistance}"
[678]25    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
[982]26    OUTPUT_VARIABLE HG_REVISION_DIST
[678]27    ERROR_QUIET
28    OUTPUT_STRIP_TRAILING_WHITESPACE
29  )
[982]30  EXECUTE_PROCESS(
31    COMMAND
32    hg log -r. --template "{node|short}"
33    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
34    OUTPUT_VARIABLE HG_REVISION_ID
35    ERROR_QUIET
36    OUTPUT_STRIP_TRAILING_WHITESPACE
37  )
38
39  IF(HG_REVISION_TAG STREQUAL "")
[927]40    SET(HG_REVISION_ID "hg-tip")
41  ELSE()
[982]42    IF(HG_REVISION_TAG STREQUAL "null")
43      SET(HG_REVISION_TAG "trunk")
44    ELSEIF(HG_REVISION_TAG MATCHES "^r")
45      STRING(SUBSTRING ${HG_REVISION_TAG} 1 -1 HG_REVISION_TAG)
46    ENDIF()
47    IF(HG_REVISION_DIST STREQUAL "0")
48      SET(HG_REVISION ${HG_REVISION_TAG})
[927]49    ELSE()
[982]50      SET(HG_REVISION
51        "${HG_REVISION_TAG}+${HG_REVISION_DIST}-${HG_REVISION_ID}")
[927]52    ENDIF()
[680]53  ENDIF()
[982]54
55  SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.")
[678]56ENDIF()
57
58SET(PROJECT_VERSION ${LEMON_VERSION})
[225]59
[549]60SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
[225]61
[679]62FIND_PACKAGE(Doxygen)
63FIND_PACKAGE(Ghostscript)
[1064]64
65SET(LEMON_ENABLE_GLPK YES CACHE STRING "Enable GLPK solver backend.")
66SET(LEMON_ENABLE_ILOG YES CACHE STRING "Enable ILOG (CPLEX) solver backend.")
67SET(LEMON_ENABLE_COIN YES CACHE STRING "Enable COIN solver backend.")
[1088]68SET(LEMON_ENABLE_SOPLEX YES CACHE STRING "Enable SoPlex solver backend.")
[1064]69
70IF(LEMON_ENABLE_GLPK)
71  FIND_PACKAGE(GLPK 4.33)
72ENDIF(LEMON_ENABLE_GLPK)
73IF(LEMON_ENABLE_ILOG)
74  FIND_PACKAGE(ILOG)
75ENDIF(LEMON_ENABLE_ILOG)
76IF(LEMON_ENABLE_COIN)
77  FIND_PACKAGE(COIN)
78ENDIF(LEMON_ENABLE_COIN)
[1088]79IF(LEMON_ENABLE_SOPLEX)
80  FIND_PACKAGE(SOPLEX)
81ENDIF(LEMON_ENABLE_SOPLEX)
[1064]82
83IF(GLPK_FOUND)
84  SET(LEMON_HAVE_LP TRUE)
85  SET(LEMON_HAVE_MIP TRUE)
86  SET(LEMON_HAVE_GLPK TRUE)
87ENDIF(GLPK_FOUND)
88IF(ILOG_FOUND)
89  SET(LEMON_HAVE_LP TRUE)
90  SET(LEMON_HAVE_MIP TRUE)
[1066]91  SET(LEMON_HAVE_CPLEX TRUE)
[1064]92ENDIF(ILOG_FOUND)
93IF(COIN_FOUND)
94  SET(LEMON_HAVE_LP TRUE)
95  SET(LEMON_HAVE_MIP TRUE)
96  SET(LEMON_HAVE_CLP TRUE)
97  SET(LEMON_HAVE_CBC TRUE)
98ENDIF(COIN_FOUND)
[1088]99IF(SOPLEX_FOUND)
100  SET(LEMON_HAVE_LP TRUE)
101  SET(LEMON_HAVE_SOPLEX TRUE)
102ENDIF(SOPLEX_FOUND)
[1064]103
104IF(ILOG_FOUND)
105  SET(DEFAULT_LP "CPLEX")
106  SET(DEFAULT_MIP "CPLEX")
107ELSEIF(COIN_FOUND)
108  SET(DEFAULT_LP "CLP")
109  SET(DEFAULT_MIP "CBC")
110ELSEIF(GLPK_FOUND)
111  SET(DEFAULT_LP "GLPK")
112  SET(DEFAULT_MIP "GLPK")
[1088]113ELSEIF(SOPLEX_FOUND)
114  SET(DEFAULT_LP "SOPLEX")
[1064]115ENDIF()
116
117IF(NOT LEMON_DEFAULT_LP OR
118    (NOT ILOG_FOUND AND (LEMON_DEFAULT_LP STREQUAL "CPLEX")) OR
119    (NOT COIN_FOUND AND (LEMON_DEFAULT_LP STREQUAL "CLP")) OR
[1088]120    (NOT GLPK_FOUND AND (LEMON_DEFAULT_LP STREQUAL "GLPK")) OR
121    (NOT SOPLEX_FOUND AND (LEMON_DEFAULT_LP STREQUAL "SOPLEX")))
[1064]122  SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
[1088]123    "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)" FORCE)
[1105]124ELSE()
125  SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
126    "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)")
[1064]127ENDIF()
128IF(NOT LEMON_DEFAULT_MIP OR
129    (NOT ILOG_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "CPLEX")) OR
130    (NOT COIN_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "CBC")) OR
131    (NOT GLPK_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "GLPK")))
132  SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING
133    "Default MIP solver backend (GLPK, CPLEX or CBC)" FORCE)
[1105]134ELSE()
135  SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING
136    "Default MIP solver backend (GLPK, CPLEX or CBC)")
[1064]137ENDIF()
138
[473]139
[927]140IF(DEFINED ENV{LEMON_CXX_WARNING})
141  SET(CXX_WARNING $ENV{LEMON_CXX_WARNING})
142ELSE()
143  IF(CMAKE_COMPILER_IS_GNUCXX)
[940]144    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")
[927]145    SET(CMAKE_CXX_FLAGS_DEBUG CACHE STRING "-ggdb")
146    SET(CMAKE_C_FLAGS_DEBUG CACHE STRING "-ggdb")
147  ELSEIF(MSVC)
148    # This part is unnecessary 'casue the same is set by the lemon/core.h.
149    # Still keep it as an example.
150    SET(CXX_WARNING "/wd4250 /wd4355 /wd4503 /wd4800 /wd4996")
151    # Suppressed warnings:
152    # C4250: 'class1' : inherits 'class2::member' via dominance
153    # C4355: 'this' : used in base member initializer list
154    # C4503: 'function' : decorated name length exceeded, name was truncated
155    # C4800: 'type' : forcing value to bool 'true' or 'false'
156    #        (performance warning)
157    # C4996: 'function': was declared deprecated
158  ELSE()
[975]159    SET(CXX_WARNING "-Wall")
[927]160  ENDIF()
161ENDIF()
162SET(LEMON_CXX_WARNING_FLAGS ${CXX_WARNING} CACHE STRING "LEMON warning flags.")
163
164SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LEMON_CXX_WARNING_FLAGS}")
165
[1017]166IF(MSVC)
167  SET( CMAKE_CXX_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
[927]168    "Flags used by the C++ compiler during maintainer builds."
[1017]169    )
170  SET( CMAKE_C_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
[927]171    "Flags used by the C compiler during maintainer builds."
[1017]172    )
173  SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
174    "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
175    "Flags used for linking binaries during maintainer builds."
176    )
177  SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
178    "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING
179    "Flags used by the shared libraries linker during maintainer builds."
180    )
181ELSE()
182  SET( CMAKE_CXX_FLAGS_MAINTAINER "-Werror -ggdb -O0" CACHE STRING
183    "Flags used by the C++ compiler during maintainer builds."
184    )
185  SET( CMAKE_C_FLAGS_MAINTAINER "-Werror -O0" CACHE STRING
186    "Flags used by the C compiler during maintainer builds."
187    )
188  SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
[927]189    "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
190    "Flags used for linking binaries during maintainer builds."
[1017]191    )
192  SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
[927]193    "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
194    "Flags used by the shared libraries linker during maintainer builds."
[1017]195    )
196ENDIF()
197
[927]198MARK_AS_ADVANCED(
199    CMAKE_CXX_FLAGS_MAINTAINER
200    CMAKE_C_FLAGS_MAINTAINER
201    CMAKE_EXE_LINKER_FLAGS_MAINTAINER
202    CMAKE_SHARED_LINKER_FLAGS_MAINTAINER )
203
204IF(CMAKE_CONFIGURATION_TYPES)
205  LIST(APPEND CMAKE_CONFIGURATION_TYPES Maintainer)
206  LIST(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
207  SET(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
208      "Add the configurations that we need"
209      FORCE)
210 endif()
211
212IF(NOT CMAKE_BUILD_TYPE)
213  SET(CMAKE_BUILD_TYPE "Release")
214ENDIF()
215
216SET( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
217    "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel Maintainer."
218    FORCE )
219
220
[496]221INCLUDE(CheckTypeSize)
[677]222CHECK_TYPE_SIZE("long long" LONG_LONG)
223SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
[496]224
[979]225INCLUDE(FindThreads)
[980]226
227IF(NOT LEMON_THREADING)
228  IF(CMAKE_USE_PTHREADS_INIT)
229    SET(LEMON_THREADING "Pthread")
230  ELSEIF(CMAKE_USE_WIN32_THREADS_INIT)
231    SET(LEMON_THREADING "Win32")
232  ELSE()
233    SET(LEMON_THREADING "None")
234  ENDIF()
235ENDIF()
236
237SET( LEMON_THREADING "${LEMON_THREADING}" CACHE STRING
238  "Choose the threading library, options are: Pthread Win32 None."
239  FORCE )
240
241IF(LEMON_THREADING STREQUAL "Pthread")
242  SET(LEMON_USE_PTHREAD TRUE)
243ELSEIF(LEMON_THREADING STREQUAL "Win32")
244  SET(LEMON_USE_WIN32_THREADS TRUE)
245ENDIF()
[744]246
[225]247ENABLE_TESTING()
248
[927]249IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer")
250  ADD_CUSTOM_TARGET(check ALL COMMAND ${CMAKE_CTEST_COMMAND})
251ELSE()
252  ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
253ENDIF()
254
[225]255ADD_SUBDIRECTORY(lemon)
[549]256IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
[925]257  ADD_SUBDIRECTORY(contrib)
[549]258  ADD_SUBDIRECTORY(demo)
259  ADD_SUBDIRECTORY(tools)
260  ADD_SUBDIRECTORY(doc)
261  ADD_SUBDIRECTORY(test)
[679]262ENDIF()
[225]263
[675]264CONFIGURE_FILE(
265  ${PROJECT_SOURCE_DIR}/cmake/LEMONConfig.cmake.in
266  ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
267  @ONLY
268)
269IF(UNIX)
270  INSTALL(
271    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
272    DESTINATION share/lemon/cmake
273  )
274ELSEIF(WIN32)
275  INSTALL(
276    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
277    DESTINATION cmake
278  )
[679]279ENDIF()
[675]280
[983]281CONFIGURE_FILE(
282  ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in
283  ${PROJECT_BINARY_DIR}/cmake/version.cmake
284  @ONLY
285)
286
287SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME})
288STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME)
289SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION})
290ADD_CUSTOM_TARGET(dist
291  COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
292  COMMAND hg archive ${ARCHIVE_NAME}
293  COMMAND cmake -E copy cmake/version.cmake ${ARCHIVE_NAME}/cmake/version.cmake
294  COMMAND tar -czf ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_NAME}
295  COMMAND zip -r ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.zip ${ARCHIVE_NAME}
296  COMMAND cmake -E copy_directory doc/html ${ARCHIVE_NAME}/doc/html
297  COMMAND tar -czf ${ARCHIVE_NAME}.tar.gz ${ARCHIVE_NAME}
298  COMMAND zip -r ${ARCHIVE_NAME}.zip ${ARCHIVE_NAME}
299  COMMAND cmake -E copy_directory doc/html ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
300  COMMAND tar -czf ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
301  COMMAND zip -r ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.zip ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
302  COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
303  COMMAND cmake -E remove_directory ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
304  DEPENDS html
305  WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
306
307# CPACK config (Basically for NSIS)
[927]308IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
[679]309  SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
310  SET(CPACK_PACKAGE_VENDOR "EGRES")
311  SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
312    "LEMON - Library for Efficient Modeling and Optimization in Networks")
313  SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
[225]314
[679]315  SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
[225]316
[679]317  SET(CPACK_PACKAGE_INSTALL_DIRECTORY
318    "${PROJECT_NAME} ${PROJECT_VERSION}")
319  SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
320    "${PROJECT_NAME} ${PROJECT_VERSION}")
[225]321
[679]322  SET(CPACK_COMPONENTS_ALL headers library html_documentation bin)
[225]323
[679]324  SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers")
325  SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Dynamic-link library")
326  SET(CPACK_COMPONENT_BIN_DISPLAY_NAME "Command line utilities")
327  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation")
[225]328
[679]329  SET(CPACK_COMPONENT_HEADERS_DESCRIPTION
330    "C++ header files")
331  SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION
332    "DLL and import library")
333  SET(CPACK_COMPONENT_BIN_DESCRIPTION
334    "Command line utilities")
335  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION
336    "Doxygen generated documentation")
[225]337
[679]338  SET(CPACK_COMPONENT_HEADERS_DEPENDS library)
[225]339
[679]340  SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
341  SET(CPACK_COMPONENT_LIBRARY_GROUP "Development")
342  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation")
[225]343
[679]344  SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
345    "Components needed to develop software using LEMON")
346  SET(CPACK_COMPONENT_GROUP_DOCUMENTATION_DESCRIPTION
347    "Documentation of LEMON")
[225]348
[679]349  SET(CPACK_ALL_INSTALL_TYPES Full Developer)
[225]350
[679]351  SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
352  SET(CPACK_COMPONENT_LIBRARY_INSTALL_TYPES Developer Full)
353  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_INSTALL_TYPES Full)
[225]354
[679]355  SET(CPACK_GENERATOR "NSIS")
356  SET(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis/lemon.ico")
357  SET(CPACK_NSIS_MUI_UNIICON "${PROJECT_SOURCE_DIR}/cmake/nsis/uninstall.ico")
358  #SET(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis\\\\installer.bmp")
359  SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lemon.ico")
360  SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}")
361  SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\lemon.cs.elte.hu")
362  SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\lemon.cs.elte.hu")
363  SET(CPACK_NSIS_CONTACT "lemon-user@lemon.cs.elte.hu")
364  SET(CPACK_NSIS_CREATE_ICONS_EXTRA "
365    CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation.lnk\\\" \\\"$INSTDIR\\\\share\\\\doc\\\\index.html\\\"
366    ")
367  SET(CPACK_NSIS_DELETE_ICONS_EXTRA "
368    !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
369    Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation.lnk\\\"
370    ")
[225]371
[679]372  INCLUDE(CPack)
373ENDIF()
Note: See TracBrowser for help on using the repository browser.