COIN-OR::LEMON - Graph Library

source: lemon/CMakeLists.txt @ 1313:fe4ff72e2f14

Last change on this file since 1313:fe4ff72e2f14 was 1313:fe4ff72e2f14, checked in by Alpar Juttner <alpar@…>, 4 years ago

CMAKE backward compatibility policy setting

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