COIN-OR::LEMON - Graph Library

source: lemon/CMakeLists.txt @ 1335:39b6e65574c6

Last change on this file since 1335:39b6e65574c6 was 1335:39b6e65574c6, checked in by Alpar Juttner <alpar@…>, 5 years ago

Merge

File size: 12.8 KB
Line 
1CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2
3IF(POLICY CMP0048)
4  CMAKE_POLICY(SET CMP0048 OLD)
5ENDIF(POLICY CMP0048)
6
7IF(POLICY CMP0043)
8  CMAKE_POLICY(SET CMP0043 OLD)
9ENDIF(POLICY CMP0043)
10
11SET(PROJECT_NAME "LEMON")
12PROJECT(${PROJECT_NAME})
13
14INCLUDE(FindPythonInterp)
15INCLUDE(FindWget)
16
17IF(EXISTS ${PROJECT_SOURCE_DIR}/cmake/version.cmake)
18  INCLUDE(${PROJECT_SOURCE_DIR}/cmake/version.cmake)
19ELSEIF(DEFINED ENV{LEMON_VERSION})
20  SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.")
21ELSE()
22  EXECUTE_PROCESS(
23    COMMAND
24    hg log -r. --template "{latesttag}"
25    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
26    OUTPUT_VARIABLE HG_REVISION_TAG
27    ERROR_QUIET
28    OUTPUT_STRIP_TRAILING_WHITESPACE
29  )
30  EXECUTE_PROCESS(
31    COMMAND
32    hg log -r. --template "{latesttagdistance}"
33    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
34    OUTPUT_VARIABLE HG_REVISION_DIST
35    ERROR_QUIET
36    OUTPUT_STRIP_TRAILING_WHITESPACE
37  )
38  EXECUTE_PROCESS(
39    COMMAND
40    hg log -r. --template "{node|short}"
41    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
42    OUTPUT_VARIABLE HG_REVISION_ID
43    ERROR_QUIET
44    OUTPUT_STRIP_TRAILING_WHITESPACE
45  )
46
47  IF(HG_REVISION_TAG STREQUAL "")
48    SET(HG_REVISION_ID "hg-tip")
49  ELSE()
50    IF(HG_REVISION_TAG STREQUAL "null")
51      SET(HG_REVISION_TAG "trunk")
52    ELSEIF(HG_REVISION_TAG MATCHES "^r")
53      STRING(SUBSTRING ${HG_REVISION_TAG} 1 -1 HG_REVISION_TAG)
54    ENDIF()
55    IF(HG_REVISION_DIST STREQUAL "0")
56      SET(HG_REVISION ${HG_REVISION_TAG})
57    ELSE()
58      SET(HG_REVISION
59        "${HG_REVISION_TAG}+${HG_REVISION_DIST}-${HG_REVISION_ID}")
60    ENDIF()
61  ENDIF()
62
63  SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.")
64ENDIF()
65
66SET(PROJECT_VERSION ${LEMON_VERSION})
67
68SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
69
70FIND_PACKAGE(Doxygen)
71FIND_PACKAGE(Ghostscript)
72
73SET(LEMON_ENABLE_GLPK YES CACHE STRING "Enable GLPK solver backend.")
74SET(LEMON_ENABLE_ILOG YES CACHE STRING "Enable ILOG (CPLEX) solver backend.")
75SET(LEMON_ENABLE_COIN YES CACHE STRING "Enable COIN solver backend.")
76SET(LEMON_ENABLE_SOPLEX YES CACHE STRING "Enable SoPlex solver backend.")
77
78IF(LEMON_ENABLE_GLPK)
79  FIND_PACKAGE(GLPK 4.33)
80ENDIF(LEMON_ENABLE_GLPK)
81IF(LEMON_ENABLE_ILOG)
82  FIND_PACKAGE(ILOG)
83ENDIF(LEMON_ENABLE_ILOG)
84IF(LEMON_ENABLE_COIN)
85  FIND_PACKAGE(COIN)
86ENDIF(LEMON_ENABLE_COIN)
87IF(LEMON_ENABLE_SOPLEX)
88  FIND_PACKAGE(SOPLEX)
89ENDIF(LEMON_ENABLE_SOPLEX)
90
91IF(GLPK_FOUND)
92  SET(LEMON_HAVE_LP TRUE)
93  SET(LEMON_HAVE_MIP TRUE)
94  SET(LEMON_HAVE_GLPK TRUE)
95ENDIF(GLPK_FOUND)
96IF(ILOG_FOUND)
97  SET(LEMON_HAVE_LP TRUE)
98  SET(LEMON_HAVE_MIP TRUE)
99  SET(LEMON_HAVE_CPLEX TRUE)
100ENDIF(ILOG_FOUND)
101IF(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)
106ENDIF(COIN_FOUND)
107IF(SOPLEX_FOUND)
108  SET(LEMON_HAVE_LP TRUE)
109  SET(LEMON_HAVE_SOPLEX TRUE)
110ENDIF(SOPLEX_FOUND)
111
112IF(ILOG_FOUND)
113  SET(DEFAULT_LP "CPLEX")
114  SET(DEFAULT_MIP "CPLEX")
115ELSEIF(COIN_FOUND)
116  SET(DEFAULT_LP "CLP")
117  SET(DEFAULT_MIP "CBC")
118ELSEIF(GLPK_FOUND)
119  SET(DEFAULT_LP "GLPK")
120  SET(DEFAULT_MIP "GLPK")
121ELSEIF(SOPLEX_FOUND)
122  SET(DEFAULT_LP "SOPLEX")
123ENDIF()
124
125IF(NOT LEMON_DEFAULT_LP OR
126    (NOT ILOG_FOUND AND (LEMON_DEFAULT_LP STREQUAL "CPLEX")) OR
127    (NOT COIN_FOUND AND (LEMON_DEFAULT_LP STREQUAL "CLP")) OR
128    (NOT GLPK_FOUND AND (LEMON_DEFAULT_LP STREQUAL "GLPK")) OR
129    (NOT SOPLEX_FOUND AND (LEMON_DEFAULT_LP STREQUAL "SOPLEX")))
130  SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
131    "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)" FORCE)
132ELSE()
133  SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
134    "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)")
135ENDIF()
136IF(NOT LEMON_DEFAULT_MIP OR
137    (NOT ILOG_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "CPLEX")) OR
138    (NOT COIN_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "CBC")) OR
139    (NOT GLPK_FOUND AND (LEMON_DEFAULT_MIP STREQUAL "GLPK")))
140  SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING
141    "Default MIP solver backend (GLPK, CPLEX or CBC)" FORCE)
142ELSE()
143  SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING
144    "Default MIP solver backend (GLPK, CPLEX or CBC)")
145ENDIF()
146
147
148IF(DEFINED ENV{LEMON_CXX_WARNING})
149  SET(CXX_WARNING $ENV{LEMON_CXX_WARNING})
150ELSE()
151  IF(CMAKE_COMPILER_IS_GNUCXX)
152    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")
153    SET(CMAKE_CXX_FLAGS_DEBUG CACHE STRING "-ggdb")
154    SET(CMAKE_C_FLAGS_DEBUG CACHE STRING "-ggdb")
155  ELSEIF(MSVC)
156    # This part is unnecessary 'casue the same is set by the lemon/core.h.
157    # Still kept as an example.
158
159    # SET(CXX_WARNING "/wd4250 /wd4267 /wd4355 /wd4503 /wd4800 /wd4996")
160
161    # Suppressed warnings:
162    # C4250: 'class1' : inherits 'class2::member' via dominance
163    # C4267: conversion from 'size_t' to 'type', possible loss of data
164    # C4355: 'this' : used in base member initializer list
165    # C4503: 'function' : decorated name length exceeded, name was truncated
166    # C4800: 'type' : forcing value to bool 'true' or 'false'
167    #        (performance warning)
168    # C4996: 'function': was declared deprecated
169  ELSE()
170    SET(CXX_WARNING "-Wall")
171  ENDIF()
172ENDIF()
173SET(LEMON_CXX_WARNING_FLAGS ${CXX_WARNING} CACHE STRING "LEMON warning flags.")
174
175SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LEMON_CXX_WARNING_FLAGS}")
176
177IF(MSVC)
178  SET(CMAKE_CXX_FLAGS "/bigobj ${CMAKE_CXX_FLAGS}")
179  SET( CMAKE_CXX_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
180    "Flags used by the C++ compiler during maintainer builds."
181    )
182  SET( CMAKE_C_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
183    "Flags used by the C compiler during maintainer builds."
184    )
185  SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
186    "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
187    "Flags used for linking binaries during maintainer builds."
188    )
189  SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
190    "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING
191    "Flags used by the shared libraries linker during maintainer builds."
192    )
193ELSE()
194  SET( CMAKE_CXX_FLAGS_MAINTAINER "-Werror -ggdb -O0" CACHE STRING
195    "Flags used by the C++ compiler during maintainer builds."
196    )
197  SET( CMAKE_C_FLAGS_MAINTAINER "-Werror -O0" CACHE STRING
198    "Flags used by the C compiler during maintainer builds."
199    )
200  SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
201    "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
202    "Flags used for linking binaries during maintainer builds."
203    )
204  SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
205    "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" CACHE STRING
206    "Flags used by the shared libraries linker during maintainer builds."
207    )
208ENDIF()
209
210MARK_AS_ADVANCED(
211    CMAKE_CXX_FLAGS_MAINTAINER
212    CMAKE_C_FLAGS_MAINTAINER
213    CMAKE_EXE_LINKER_FLAGS_MAINTAINER
214    CMAKE_SHARED_LINKER_FLAGS_MAINTAINER )
215
216IF(CMAKE_CONFIGURATION_TYPES)
217  LIST(APPEND CMAKE_CONFIGURATION_TYPES Maintainer)
218  LIST(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
219  SET(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
220      "Add the configurations that we need"
221      FORCE)
222 endif()
223
224IF(NOT CMAKE_BUILD_TYPE)
225  SET(CMAKE_BUILD_TYPE "Release")
226ENDIF()
227
228SET( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
229    "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel Maintainer."
230    FORCE )
231
232SET_DIRECTORY_PROPERTIES(PROPERTIES
233  COMPILE_DEFINITIONS_DEBUG "LEMON_ENABLE_DEBUG"
234  COMPILE_DEFINITIONS_MAINTAINER "LEMON_ENABLE_DEBUG"
235)
236
237INCLUDE(CheckTypeSize)
238CHECK_TYPE_SIZE("long long" LONG_LONG)
239SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
240
241INCLUDE(FindThreads)
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()
262
263ENABLE_TESTING()
264
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
271ADD_SUBDIRECTORY(lemon)
272IF(${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)
278ENDIF()
279
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  )
295ENDIF()
296
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)
324IF(${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")
330
331  SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
332
333  SET(CPACK_PACKAGE_INSTALL_DIRECTORY
334    "${PROJECT_NAME} ${PROJECT_VERSION}")
335  SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
336    "${PROJECT_NAME} ${PROJECT_VERSION}")
337
338  SET(CPACK_COMPONENTS_ALL headers library html_documentation bin)
339
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")
344
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")
353
354  SET(CPACK_COMPONENT_HEADERS_DEPENDS library)
355
356  SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
357  SET(CPACK_COMPONENT_LIBRARY_GROUP "Development")
358  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation")
359
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")
364
365  SET(CPACK_ALL_INSTALL_TYPES Full Developer)
366
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)
370
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    ")
387
388  INCLUDE(CPack)
389ENDIF()
Note: See TracBrowser for help on using the repository browser.