COIN-OR::LEMON - Graph Library

source: lemon/CMakeLists.txt @ 1343:20f95cd51aba

Last change on this file since 1343:20f95cd51aba was 1343:20f95cd51aba, checked in by Alpar Juttner <alpar@…>, 5 years ago

Merge bugfix #595

File size: 13.0 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
73IF(WIN32)
74  SET(LEMON_WIN32 TRUE)
75ENDIF(WIN32)
76
77SET(LEMON_ENABLE_GLPK YES CACHE STRING "Enable GLPK solver backend.")
78SET(LEMON_ENABLE_ILOG YES CACHE STRING "Enable ILOG (CPLEX) solver backend.")
79SET(LEMON_ENABLE_COIN YES CACHE STRING "Enable COIN solver backend.")
80SET(LEMON_ENABLE_SOPLEX YES CACHE STRING "Enable SoPlex solver backend.")
81
82IF(LEMON_ENABLE_GLPK)
83  FIND_PACKAGE(GLPK 4.33)
84ENDIF(LEMON_ENABLE_GLPK)
85IF(LEMON_ENABLE_ILOG)
86  FIND_PACKAGE(ILOG)
87ENDIF(LEMON_ENABLE_ILOG)
88IF(LEMON_ENABLE_COIN)
89  FIND_PACKAGE(COIN)
90ENDIF(LEMON_ENABLE_COIN)
91IF(LEMON_ENABLE_SOPLEX)
92  FIND_PACKAGE(SOPLEX)
93ENDIF(LEMON_ENABLE_SOPLEX)
94
95IF(GLPK_FOUND)
96  SET(LEMON_HAVE_LP TRUE)
97  SET(LEMON_HAVE_MIP TRUE)
98  SET(LEMON_HAVE_GLPK TRUE)
99ENDIF(GLPK_FOUND)
100IF(ILOG_FOUND)
101  SET(LEMON_HAVE_LP TRUE)
102  SET(LEMON_HAVE_MIP TRUE)
103  SET(LEMON_HAVE_CPLEX TRUE)
104ENDIF(ILOG_FOUND)
105IF(COIN_FOUND)
106  SET(LEMON_HAVE_LP TRUE)
107  SET(LEMON_HAVE_MIP TRUE)
108  SET(LEMON_HAVE_CLP TRUE)
109  SET(LEMON_HAVE_CBC TRUE)
110ENDIF(COIN_FOUND)
111IF(SOPLEX_FOUND)
112  SET(LEMON_HAVE_LP TRUE)
113  SET(LEMON_HAVE_SOPLEX TRUE)
114ENDIF(SOPLEX_FOUND)
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")
125ELSEIF(SOPLEX_FOUND)
126  SET(DEFAULT_LP "SOPLEX")
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
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)
136ELSE()
137  SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
138    "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)")
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)
146ELSE()
147  SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING
148    "Default MIP solver backend (GLPK, CPLEX or CBC)")
149ENDIF()
150
151
152IF(DEFINED ENV{LEMON_CXX_WARNING})
153  SET(CXX_WARNING $ENV{LEMON_CXX_WARNING})
154ELSE()
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")
159  ELSEIF(MSVC)
160    # This part is unnecessary 'casue the same is set by the lemon/core.h.
161    # Still kept as an example.
162
163    # SET(CXX_WARNING "/wd4250 /wd4267 /wd4355 /wd4503 /wd4800 /wd4996")
164
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
173  ELSE()
174    SET(CXX_WARNING "-Wall")
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
181IF(MSVC)
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."
185    )
186  SET( CMAKE_C_FLAGS_MAINTAINER "/WX ${CMAKE_CXX_FLAGS_DEBUG}" CACHE STRING
187    "Flags used by the C compiler during maintainer builds."
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
205    "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" CACHE STRING
206    "Flags used for linking binaries during maintainer builds."
207    )
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."
211    )
212ENDIF()
213
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
236SET_DIRECTORY_PROPERTIES(PROPERTIES
237  COMPILE_DEFINITIONS_DEBUG "LEMON_ENABLE_DEBUG"
238  COMPILE_DEFINITIONS_MAINTAINER "LEMON_ENABLE_DEBUG"
239)
240
241INCLUDE(CheckTypeSize)
242CHECK_TYPE_SIZE("long long" LONG_LONG)
243SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
244
245INCLUDE(FindThreads)
246
247IF(NOT LEMON_THREADING)
248  IF(CMAKE_USE_PTHREADS_INIT)
249    SET(LEMON_THREADING "Pthread")
250  ELSEIF(CMAKE_USE_WIN32_THREADS_INIT)
251    SET(LEMON_THREADING "Win32")
252  ELSE()
253    SET(LEMON_THREADING "None")
254  ENDIF()
255ENDIF()
256
257SET( LEMON_THREADING "${LEMON_THREADING}" CACHE STRING
258  "Choose the threading library, options are: Pthread Win32 None."
259  FORCE )
260
261IF(LEMON_THREADING STREQUAL "Pthread")
262  SET(LEMON_USE_PTHREAD TRUE)
263ELSEIF(LEMON_THREADING STREQUAL "Win32")
264  SET(LEMON_USE_WIN32_THREADS TRUE)
265ENDIF()
266
267ENABLE_TESTING()
268
269
270INCLUDE(CheckCXXCompilerFlag)
271CHECK_CXX_COMPILER_FLAG("-std=c++11" LEMON_CXX11)
272IF(LEMON_CXX11)
273  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
274ENDIF()
275
276
277IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer")
278  ADD_CUSTOM_TARGET(check ALL COMMAND ${CMAKE_CTEST_COMMAND})
279ELSE()
280  ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
281ENDIF()
282
283ADD_SUBDIRECTORY(lemon)
284IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
285  ADD_SUBDIRECTORY(contrib)
286  ADD_SUBDIRECTORY(demo)
287  ADD_SUBDIRECTORY(tools)
288  ADD_SUBDIRECTORY(doc)
289  ADD_SUBDIRECTORY(test)
290ENDIF()
291
292CONFIGURE_FILE(
293  ${PROJECT_SOURCE_DIR}/cmake/LEMONConfig.cmake.in
294  ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
295  @ONLY
296)
297IF(UNIX)
298  INSTALL(
299    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
300    DESTINATION share/lemon/cmake
301  )
302ELSEIF(WIN32)
303  INSTALL(
304    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
305    DESTINATION cmake
306  )
307ENDIF()
308
309CONFIGURE_FILE(
310  ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in
311  ${PROJECT_BINARY_DIR}/cmake/version.cmake
312  @ONLY
313)
314
315SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME})
316STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME)
317SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION})
318ADD_CUSTOM_TARGET(dist
319  COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
320  COMMAND hg archive ${ARCHIVE_NAME}
321  COMMAND cmake -E copy cmake/version.cmake ${ARCHIVE_NAME}/cmake/version.cmake
322  COMMAND tar -czf ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_NAME}
323  COMMAND zip -r ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.zip ${ARCHIVE_NAME}
324  COMMAND cmake -E copy_directory doc/html ${ARCHIVE_NAME}/doc/html
325  COMMAND tar -czf ${ARCHIVE_NAME}.tar.gz ${ARCHIVE_NAME}
326  COMMAND zip -r ${ARCHIVE_NAME}.zip ${ARCHIVE_NAME}
327  COMMAND cmake -E copy_directory doc/html ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
328  COMMAND tar -czf ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
329  COMMAND zip -r ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.zip ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
330  COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
331  COMMAND cmake -E remove_directory ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
332  DEPENDS html
333  WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
334
335# CPACK config (Basically for NSIS)
336IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
337  SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
338  SET(CPACK_PACKAGE_VENDOR "EGRES")
339  SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
340    "LEMON - Library for Efficient Modeling and Optimization in Networks")
341  SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
342
343  SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
344
345  SET(CPACK_PACKAGE_INSTALL_DIRECTORY
346    "${PROJECT_NAME} ${PROJECT_VERSION}")
347  SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
348    "${PROJECT_NAME} ${PROJECT_VERSION}")
349
350  SET(CPACK_COMPONENTS_ALL headers library html_documentation bin)
351
352  SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers")
353  SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Dynamic-link library")
354  SET(CPACK_COMPONENT_BIN_DISPLAY_NAME "Command line utilities")
355  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation")
356
357  SET(CPACK_COMPONENT_HEADERS_DESCRIPTION
358    "C++ header files")
359  SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION
360    "DLL and import library")
361  SET(CPACK_COMPONENT_BIN_DESCRIPTION
362    "Command line utilities")
363  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION
364    "Doxygen generated documentation")
365
366  SET(CPACK_COMPONENT_HEADERS_DEPENDS library)
367
368  SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
369  SET(CPACK_COMPONENT_LIBRARY_GROUP "Development")
370  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation")
371
372  SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
373    "Components needed to develop software using LEMON")
374  SET(CPACK_COMPONENT_GROUP_DOCUMENTATION_DESCRIPTION
375    "Documentation of LEMON")
376
377  SET(CPACK_ALL_INSTALL_TYPES Full Developer)
378
379  SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
380  SET(CPACK_COMPONENT_LIBRARY_INSTALL_TYPES Developer Full)
381  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_INSTALL_TYPES Full)
382
383  SET(CPACK_GENERATOR "NSIS")
384  SET(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis/lemon.ico")
385  SET(CPACK_NSIS_MUI_UNIICON "${PROJECT_SOURCE_DIR}/cmake/nsis/uninstall.ico")
386  #SET(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis\\\\installer.bmp")
387  SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lemon.ico")
388  SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}")
389  SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\lemon.cs.elte.hu")
390  SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\lemon.cs.elte.hu")
391  SET(CPACK_NSIS_CONTACT "lemon-user@lemon.cs.elte.hu")
392  SET(CPACK_NSIS_CREATE_ICONS_EXTRA "
393    CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation.lnk\\\" \\\"$INSTDIR\\\\share\\\\doc\\\\index.html\\\"
394    ")
395  SET(CPACK_NSIS_DELETE_ICONS_EXTRA "
396    !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
397    Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation.lnk\\\"
398    ")
399
400  INCLUDE(CPack)
401ENDIF()
Note: See TracBrowser for help on using the repository browser.