COIN-OR::LEMON - Graph Library

source: lemon/CMakeLists.txt

1.3 tip
Last change on this file was 1344:ca4e4a5e9b6e, checked in by Alpar Juttner <alpar@…>, 3 years ago

CMP0026 cmake policy setting (needed by cmake 3.2+ on WIN32)

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