COIN-OR::LEMON - Graph Library

source: lemon-main/CMakeLists.txt @ 1162:881e4168c65f

Last change on this file since 1162:881e4168c65f was 1138:f95b18d99843, checked in by Alpar Juttner <alpar@…>, 10 years ago

Merge CMP0026 setting

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