COIN-OR::LEMON - Graph Library

source: lemon/CMakeLists.txt @ 1340:f70f688d9ef9

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

Replace #define WIN32 (#595)

File size: 12.7 KB
Line 
1CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2
3IF(POLICY CMP0048)
4  CMAKE_POLICY(SET CMP0048 OLD)
5ENDIF(POLICY CMP0048)
6
7SET(PROJECT_NAME "LEMON")
8PROJECT(${PROJECT_NAME})
9
10INCLUDE(FindPythonInterp)
11INCLUDE(FindWget)
12
13IF(EXISTS ${PROJECT_SOURCE_DIR}/cmake/version.cmake)
14  INCLUDE(${PROJECT_SOURCE_DIR}/cmake/version.cmake)
15ELSEIF(DEFINED ENV{LEMON_VERSION})
16  SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.")
17ELSE()
18  EXECUTE_PROCESS(
19    COMMAND
20    hg log -r. --template "{latesttag}"
21    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
22    OUTPUT_VARIABLE HG_REVISION_TAG
23    ERROR_QUIET
24    OUTPUT_STRIP_TRAILING_WHITESPACE
25  )
26  EXECUTE_PROCESS(
27    COMMAND
28    hg log -r. --template "{latesttagdistance}"
29    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
30    OUTPUT_VARIABLE HG_REVISION_DIST
31    ERROR_QUIET
32    OUTPUT_STRIP_TRAILING_WHITESPACE
33  )
34  EXECUTE_PROCESS(
35    COMMAND
36    hg log -r. --template "{node|short}"
37    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
38    OUTPUT_VARIABLE HG_REVISION_ID
39    ERROR_QUIET
40    OUTPUT_STRIP_TRAILING_WHITESPACE
41  )
42
43  IF(HG_REVISION_TAG STREQUAL "")
44    SET(HG_REVISION_ID "hg-tip")
45  ELSE()
46    IF(HG_REVISION_TAG STREQUAL "null")
47      SET(HG_REVISION_TAG "trunk")
48    ELSEIF(HG_REVISION_TAG MATCHES "^r")
49      STRING(SUBSTRING ${HG_REVISION_TAG} 1 -1 HG_REVISION_TAG)
50    ENDIF()
51    IF(HG_REVISION_DIST STREQUAL "0")
52      SET(HG_REVISION ${HG_REVISION_TAG})
53    ELSE()
54      SET(HG_REVISION
55        "${HG_REVISION_TAG}+${HG_REVISION_DIST}-${HG_REVISION_ID}")
56    ENDIF()
57  ENDIF()
58
59  SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.")
60ENDIF()
61
62SET(PROJECT_VERSION ${LEMON_VERSION})
63
64SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
65
66FIND_PACKAGE(Doxygen)
67FIND_PACKAGE(Ghostscript)
68
69IF(WIN32)
70  SET(LEMON_WIN32 TRUE)
71ENDIF(WIN32)
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
232
233INCLUDE(CheckTypeSize)
234CHECK_TYPE_SIZE("long long" LONG_LONG)
235SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
236
237INCLUDE(FindThreads)
238
239IF(NOT LEMON_THREADING)
240  IF(CMAKE_USE_PTHREADS_INIT)
241    SET(LEMON_THREADING "Pthread")
242  ELSEIF(CMAKE_USE_WIN32_THREADS_INIT)
243    SET(LEMON_THREADING "Win32")
244  ELSE()
245    SET(LEMON_THREADING "None")
246  ENDIF()
247ENDIF()
248
249SET( LEMON_THREADING "${LEMON_THREADING}" CACHE STRING
250  "Choose the threading library, options are: Pthread Win32 None."
251  FORCE )
252
253IF(LEMON_THREADING STREQUAL "Pthread")
254  SET(LEMON_USE_PTHREAD TRUE)
255ELSEIF(LEMON_THREADING STREQUAL "Win32")
256  SET(LEMON_USE_WIN32_THREADS TRUE)
257ENDIF()
258
259ENABLE_TESTING()
260
261IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer")
262  ADD_CUSTOM_TARGET(check ALL COMMAND ${CMAKE_CTEST_COMMAND})
263ELSE()
264  ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
265ENDIF()
266
267ADD_SUBDIRECTORY(lemon)
268IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
269  ADD_SUBDIRECTORY(contrib)
270  ADD_SUBDIRECTORY(demo)
271  ADD_SUBDIRECTORY(tools)
272  ADD_SUBDIRECTORY(doc)
273  ADD_SUBDIRECTORY(test)
274ENDIF()
275
276CONFIGURE_FILE(
277  ${PROJECT_SOURCE_DIR}/cmake/LEMONConfig.cmake.in
278  ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
279  @ONLY
280)
281IF(UNIX)
282  INSTALL(
283    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
284    DESTINATION share/lemon/cmake
285  )
286ELSEIF(WIN32)
287  INSTALL(
288    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
289    DESTINATION cmake
290  )
291ENDIF()
292
293CONFIGURE_FILE(
294  ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in
295  ${PROJECT_BINARY_DIR}/cmake/version.cmake
296  @ONLY
297)
298
299SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME})
300STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME)
301SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION})
302ADD_CUSTOM_TARGET(dist
303  COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
304  COMMAND hg archive ${ARCHIVE_NAME}
305  COMMAND cmake -E copy cmake/version.cmake ${ARCHIVE_NAME}/cmake/version.cmake
306  COMMAND tar -czf ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_NAME}
307  COMMAND zip -r ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.zip ${ARCHIVE_NAME}
308  COMMAND cmake -E copy_directory doc/html ${ARCHIVE_NAME}/doc/html
309  COMMAND tar -czf ${ARCHIVE_NAME}.tar.gz ${ARCHIVE_NAME}
310  COMMAND zip -r ${ARCHIVE_NAME}.zip ${ARCHIVE_NAME}
311  COMMAND cmake -E copy_directory doc/html ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
312  COMMAND tar -czf ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
313  COMMAND zip -r ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.zip ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
314  COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
315  COMMAND cmake -E remove_directory ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
316  DEPENDS html
317  WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
318
319# CPACK config (Basically for NSIS)
320IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
321  SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
322  SET(CPACK_PACKAGE_VENDOR "EGRES")
323  SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
324    "LEMON - Library for Efficient Modeling and Optimization in Networks")
325  SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
326
327  SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
328
329  SET(CPACK_PACKAGE_INSTALL_DIRECTORY
330    "${PROJECT_NAME} ${PROJECT_VERSION}")
331  SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
332    "${PROJECT_NAME} ${PROJECT_VERSION}")
333
334  SET(CPACK_COMPONENTS_ALL headers library html_documentation bin)
335
336  SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers")
337  SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Dynamic-link library")
338  SET(CPACK_COMPONENT_BIN_DISPLAY_NAME "Command line utilities")
339  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation")
340
341  SET(CPACK_COMPONENT_HEADERS_DESCRIPTION
342    "C++ header files")
343  SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION
344    "DLL and import library")
345  SET(CPACK_COMPONENT_BIN_DESCRIPTION
346    "Command line utilities")
347  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION
348    "Doxygen generated documentation")
349
350  SET(CPACK_COMPONENT_HEADERS_DEPENDS library)
351
352  SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
353  SET(CPACK_COMPONENT_LIBRARY_GROUP "Development")
354  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation")
355
356  SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
357    "Components needed to develop software using LEMON")
358  SET(CPACK_COMPONENT_GROUP_DOCUMENTATION_DESCRIPTION
359    "Documentation of LEMON")
360
361  SET(CPACK_ALL_INSTALL_TYPES Full Developer)
362
363  SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
364  SET(CPACK_COMPONENT_LIBRARY_INSTALL_TYPES Developer Full)
365  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_INSTALL_TYPES Full)
366
367  SET(CPACK_GENERATOR "NSIS")
368  SET(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis/lemon.ico")
369  SET(CPACK_NSIS_MUI_UNIICON "${PROJECT_SOURCE_DIR}/cmake/nsis/uninstall.ico")
370  #SET(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis\\\\installer.bmp")
371  SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lemon.ico")
372  SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}")
373  SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\lemon.cs.elte.hu")
374  SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\lemon.cs.elte.hu")
375  SET(CPACK_NSIS_CONTACT "lemon-user@lemon.cs.elte.hu")
376  SET(CPACK_NSIS_CREATE_ICONS_EXTRA "
377    CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation.lnk\\\" \\\"$INSTDIR\\\\share\\\\doc\\\\index.html\\\"
378    ")
379  SET(CPACK_NSIS_DELETE_ICONS_EXTRA "
380    !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
381    Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation.lnk\\\"
382    ")
383
384  INCLUDE(CPack)
385ENDIF()
Note: See TracBrowser for help on using the repository browser.