COIN-OR::LEMON - Graph Library

source: lemon/CMakeLists.txt @ 1270:dceba191c00d

Last change on this file since 1270:dceba191c00d was 1264:4000b7ef4e01, checked in by Alpar Juttner <alpar@…>, 12 years ago

Add cmake config to find SoPlex? (#460)

Based on the patch sent by ax487

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