COIN-OR::LEMON - Graph Library

source: lemon-main/CMakeLists.txt @ 1181:1e5da3fc4fbc

Last change on this file since 1181:1e5da3fc4fbc was 1180:389416f8a995, checked in by Alpar Juttner <alpar@…>, 6 years ago

Better MIP solver discovery and support linking to CLP/CBC on Windows (#614)

File size: 12.9 KB
RevLine 
[1107]1CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
[225]2
[1119]3IF(POLICY CMP0048)
4  CMAKE_POLICY(SET CMP0048 OLD)
5ENDIF(POLICY CMP0048)
[1114]6
[1137]7IF(POLICY CMP0026)
8  #This is for copying the dll's needed by glpk (in lp_test and mip_test)
9  CMAKE_POLICY(SET CMP0026 OLD)
10ENDIF(POLICY CMP0026)
11
[678]12SET(PROJECT_NAME "LEMON")
13PROJECT(${PROJECT_NAME})
[225]14
[927]15INCLUDE(FindPythonInterp)
16INCLUDE(FindWget)
17
[678]18IF(EXISTS ${PROJECT_SOURCE_DIR}/cmake/version.cmake)
19  INCLUDE(${PROJECT_SOURCE_DIR}/cmake/version.cmake)
20ELSEIF(DEFINED ENV{LEMON_VERSION})
21  SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.")
22ELSE()
23  EXECUTE_PROCESS(
[982]24    COMMAND
25    hg log -r. --template "{latesttag}"
[927]26    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
[982]27    OUTPUT_VARIABLE HG_REVISION_TAG
[927]28    ERROR_QUIET
29    OUTPUT_STRIP_TRAILING_WHITESPACE
30  )
31  EXECUTE_PROCESS(
[982]32    COMMAND
33    hg log -r. --template "{latesttagdistance}"
[678]34    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
[982]35    OUTPUT_VARIABLE HG_REVISION_DIST
[678]36    ERROR_QUIET
37    OUTPUT_STRIP_TRAILING_WHITESPACE
38  )
[982]39  EXECUTE_PROCESS(
40    COMMAND
41    hg log -r. --template "{node|short}"
42    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
43    OUTPUT_VARIABLE HG_REVISION_ID
44    ERROR_QUIET
45    OUTPUT_STRIP_TRAILING_WHITESPACE
46  )
47
48  IF(HG_REVISION_TAG STREQUAL "")
[927]49    SET(HG_REVISION_ID "hg-tip")
50  ELSE()
[982]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)
55    ENDIF()
56    IF(HG_REVISION_DIST STREQUAL "0")
57      SET(HG_REVISION ${HG_REVISION_TAG})
[927]58    ELSE()
[982]59      SET(HG_REVISION
60        "${HG_REVISION_TAG}+${HG_REVISION_DIST}-${HG_REVISION_ID}")
[927]61    ENDIF()
[680]62  ENDIF()
[982]63
64  SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.")
[678]65ENDIF()
66
67SET(PROJECT_VERSION ${LEMON_VERSION})
[225]68
[549]69SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
[225]70
[679]71FIND_PACKAGE(Doxygen)
72FIND_PACKAGE(Ghostscript)
[1064]73
[1134]74IF(WIN32)
75  SET(LEMON_WIN32 TRUE)
76ENDIF(WIN32)
77
[1064]78SET(LEMON_ENABLE_GLPK YES CACHE STRING "Enable GLPK solver backend.")
79SET(LEMON_ENABLE_ILOG YES CACHE STRING "Enable ILOG (CPLEX) solver backend.")
80SET(LEMON_ENABLE_COIN YES CACHE STRING "Enable COIN solver backend.")
[1088]81SET(LEMON_ENABLE_SOPLEX YES CACHE STRING "Enable SoPlex solver backend.")
[1064]82
83IF(LEMON_ENABLE_GLPK)
84  FIND_PACKAGE(GLPK 4.33)
[1180]85  IF(GLPK_FOUND)
86    SET(LEMON_HAVE_LP TRUE)
87    SET(LEMON_HAVE_MIP TRUE)
88    SET(LEMON_HAVE_GLPK TRUE)
89  ENDIF(GLPK_FOUND)
[1064]90ENDIF(LEMON_ENABLE_GLPK)
91IF(LEMON_ENABLE_ILOG)
92  FIND_PACKAGE(ILOG)
[1180]93  IF(ILOG_FOUND)
94    SET(LEMON_HAVE_LP TRUE)
95    SET(LEMON_HAVE_MIP TRUE)
96    SET(LEMON_HAVE_CPLEX TRUE)
97  ENDIF(ILOG_FOUND)
[1064]98ENDIF(LEMON_ENABLE_ILOG)
99IF(LEMON_ENABLE_COIN)
100  FIND_PACKAGE(COIN)
[1180]101  IF(COIN_FOUND)
102    SET(LEMON_HAVE_LP TRUE)
103    SET(LEMON_HAVE_MIP TRUE)
104    SET(LEMON_HAVE_CLP TRUE)
105    SET(LEMON_HAVE_CBC TRUE)
106  ENDIF(COIN_FOUND)
[1064]107ENDIF(LEMON_ENABLE_COIN)
[1088]108IF(LEMON_ENABLE_SOPLEX)
109  FIND_PACKAGE(SOPLEX)
[1180]110  IF(SOPLEX_FOUND)
111    SET(LEMON_HAVE_LP TRUE)
112    SET(LEMON_HAVE_SOPLEX TRUE)
113  ENDIF(SOPLEX_FOUND)
[1088]114ENDIF(LEMON_ENABLE_SOPLEX)
[1064]115
116IF(ILOG_FOUND)
117  SET(DEFAULT_LP "CPLEX")
118  SET(DEFAULT_MIP "CPLEX")
119ELSEIF(COIN_FOUND)
120  SET(DEFAULT_LP "CLP")
121  SET(DEFAULT_MIP "CBC")
122ELSEIF(GLPK_FOUND)
123  SET(DEFAULT_LP "GLPK")
124  SET(DEFAULT_MIP "GLPK")
[1088]125ELSEIF(SOPLEX_FOUND)
126  SET(DEFAULT_LP "SOPLEX")
[1064]127ENDIF()
128
129IF(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
[1088]132    (NOT GLPK_FOUND AND (LEMON_DEFAULT_LP STREQUAL "GLPK")) OR
133    (NOT SOPLEX_FOUND AND (LEMON_DEFAULT_LP STREQUAL "SOPLEX")))
[1064]134  SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
[1088]135    "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)" FORCE)
[1105]136ELSE()
137  SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
138    "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)")
[1064]139ENDIF()
140IF(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)
[1105]146ELSE()
147  SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING
148    "Default MIP solver backend (GLPK, CPLEX or CBC)")
[1064]149ENDIF()
150
[473]151
[927]152IF(DEFINED ENV{LEMON_CXX_WARNING})
153  SET(CXX_WARNING $ENV{LEMON_CXX_WARNING})
154ELSE()
155  IF(CMAKE_COMPILER_IS_GNUCXX)
[940]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")
[927]157    SET(CMAKE_CXX_FLAGS_DEBUG CACHE STRING "-ggdb")
158    SET(CMAKE_C_FLAGS_DEBUG CACHE STRING "-ggdb")
159  ELSEIF(MSVC)
160    # This part is unnecessary 'casue the same is set by the lemon/core.h.
[1123]161    # Still kept as an example.
162
163    # SET(CXX_WARNING "/wd4250 /wd4267 /wd4355 /wd4503 /wd4800 /wd4996")
164
[927]165    # Suppressed warnings:
166    # C4250: 'class1' : inherits 'class2::member' via dominance
[1123]167    # C4267: conversion from 'size_t' to 'type', possible loss of data
[927]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
173  ELSE()
[975]174    SET(CXX_WARNING "-Wall")
[927]175  ENDIF()
176ENDIF()
177SET(LEMON_CXX_WARNING_FLAGS ${CXX_WARNING} CACHE STRING "LEMON warning flags.")
178
179SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LEMON_CXX_WARNING_FLAGS}")
180
[1017]181IF(MSVC)
[1122]182  SET(CMAKE_CXX_FLAGS "/bigobj ${CMAKE_CXX_FLAGS}")
[1017]183  SET( CMAKE_CXX_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
[927]184    "Flags used by the C++ compiler during maintainer builds."
[1017]185    )
186  SET( CMAKE_C_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
[927]187    "Flags used by the C compiler during maintainer builds."
[1017]188    )
189  SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
190    "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
191    "Flags used for linking binaries during maintainer builds."
192    )
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."
196    )
197ELSE()
198  SET( CMAKE_CXX_FLAGS_MAINTAINER "-Werror -ggdb -O0" CACHE STRING
199    "Flags used by the C++ compiler during maintainer builds."
200    )
201  SET( CMAKE_C_FLAGS_MAINTAINER "-Werror -O0" CACHE STRING
202    "Flags used by the C compiler during maintainer builds."
203    )
204  SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
[1111]205    "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
[927]206    "Flags used for linking binaries during maintainer builds."
[1017]207    )
208  SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
[1111]209    "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING
[927]210    "Flags used by the shared libraries linker during maintainer builds."
[1017]211    )
212ENDIF()
213
[927]214MARK_AS_ADVANCED(
215    CMAKE_CXX_FLAGS_MAINTAINER
216    CMAKE_C_FLAGS_MAINTAINER
217    CMAKE_EXE_LINKER_FLAGS_MAINTAINER
218    CMAKE_SHARED_LINKER_FLAGS_MAINTAINER )
219
220IF(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"
225      FORCE)
226 endif()
227
228IF(NOT CMAKE_BUILD_TYPE)
229  SET(CMAKE_BUILD_TYPE "Release")
230ENDIF()
231
232SET( 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."
234    FORCE )
235
236
[496]237INCLUDE(CheckTypeSize)
[677]238CHECK_TYPE_SIZE("long long" LONG_LONG)
239SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
[496]240
[979]241INCLUDE(FindThreads)
[980]242
243IF(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")
248  ELSE()
249    SET(LEMON_THREADING "None")
250  ENDIF()
251ENDIF()
252
253SET( LEMON_THREADING "${LEMON_THREADING}" CACHE STRING
254  "Choose the threading library, options are: Pthread Win32 None."
255  FORCE )
256
257IF(LEMON_THREADING STREQUAL "Pthread")
258  SET(LEMON_USE_PTHREAD TRUE)
259ELSEIF(LEMON_THREADING STREQUAL "Win32")
260  SET(LEMON_USE_WIN32_THREADS TRUE)
261ENDIF()
[744]262
[225]263ENABLE_TESTING()
264
[927]265IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer")
266  ADD_CUSTOM_TARGET(check ALL COMMAND ${CMAKE_CTEST_COMMAND})
267ELSE()
268  ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
269ENDIF()
270
[225]271ADD_SUBDIRECTORY(lemon)
[549]272IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
[925]273  ADD_SUBDIRECTORY(contrib)
[549]274  ADD_SUBDIRECTORY(demo)
275  ADD_SUBDIRECTORY(tools)
276  ADD_SUBDIRECTORY(doc)
277  ADD_SUBDIRECTORY(test)
[679]278ENDIF()
[225]279
[675]280CONFIGURE_FILE(
281  ${PROJECT_SOURCE_DIR}/cmake/LEMONConfig.cmake.in
282  ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
283  @ONLY
284)
285IF(UNIX)
286  INSTALL(
287    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
288    DESTINATION share/lemon/cmake
289  )
290ELSEIF(WIN32)
291  INSTALL(
292    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
293    DESTINATION cmake
294  )
[679]295ENDIF()
[675]296
[983]297CONFIGURE_FILE(
298  ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in
299  ${PROJECT_BINARY_DIR}/cmake/version.cmake
300  @ONLY
301)
302
303SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME})
304STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME)
305SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION})
306ADD_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}
320  DEPENDS html
321  WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
322
323# CPACK config (Basically for NSIS)
[927]324IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
[679]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")
[225]330
[679]331  SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
[225]332
[679]333  SET(CPACK_PACKAGE_INSTALL_DIRECTORY
334    "${PROJECT_NAME} ${PROJECT_VERSION}")
335  SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
336    "${PROJECT_NAME} ${PROJECT_VERSION}")
[225]337
[679]338  SET(CPACK_COMPONENTS_ALL headers library html_documentation bin)
[225]339
[679]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")
[225]344
[679]345  SET(CPACK_COMPONENT_HEADERS_DESCRIPTION
346    "C++ header files")
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")
[225]353
[679]354  SET(CPACK_COMPONENT_HEADERS_DEPENDS library)
[225]355
[679]356  SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
357  SET(CPACK_COMPONENT_LIBRARY_GROUP "Development")
358  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation")
[225]359
[679]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")
[225]364
[679]365  SET(CPACK_ALL_INSTALL_TYPES Full Developer)
[225]366
[679]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)
[225]370
[679]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\\\"
382    ")
383  SET(CPACK_NSIS_DELETE_ICONS_EXTRA "
384    !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
385    Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation.lnk\\\"
386    ")
[225]387
[679]388  INCLUDE(CPack)
389ENDIF()
Note: See TracBrowser for help on using the repository browser.