CMakeLists.txt
author Balazs Dezso <deba@google.com>
Wed, 17 Oct 2018 17:52:11 +0200
changeset 1182 6b79d93e812f
parent 1137 ca4e4a5e9b6e
child 1185 c8d0179a32a2
child 1197 f179aa1045a4
permissions -rw-r--r--
Planar drawing algorithm now works for less than 3 nodes (#611)
     1 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
     2 
     3 IF(POLICY CMP0048) 
     4   CMAKE_POLICY(SET CMP0048 OLD) 
     5 ENDIF(POLICY CMP0048)
     6 
     7 IF(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) 
    10 ENDIF(POLICY CMP0026)
    11 
    12 SET(PROJECT_NAME "LEMON")
    13 PROJECT(${PROJECT_NAME})
    14 
    15 INCLUDE(FindPythonInterp)
    16 INCLUDE(FindWget)
    17 
    18 IF(EXISTS ${PROJECT_SOURCE_DIR}/cmake/version.cmake)
    19   INCLUDE(${PROJECT_SOURCE_DIR}/cmake/version.cmake)
    20 ELSEIF(DEFINED ENV{LEMON_VERSION})
    21   SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.")
    22 ELSE()
    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.")
    65 ENDIF()
    66 
    67 SET(PROJECT_VERSION ${LEMON_VERSION})
    68 
    69 SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
    70 
    71 FIND_PACKAGE(Doxygen)
    72 FIND_PACKAGE(Ghostscript)
    73 
    74 IF(WIN32)
    75   SET(LEMON_WIN32 TRUE)
    76 ENDIF(WIN32)
    77 
    78 SET(LEMON_ENABLE_GLPK YES CACHE STRING "Enable GLPK solver backend.")
    79 SET(LEMON_ENABLE_ILOG YES CACHE STRING "Enable ILOG (CPLEX) solver backend.")
    80 SET(LEMON_ENABLE_COIN YES CACHE STRING "Enable COIN solver backend.")
    81 SET(LEMON_ENABLE_SOPLEX YES CACHE STRING "Enable SoPlex solver backend.")
    82 
    83 IF(LEMON_ENABLE_GLPK) 
    84   FIND_PACKAGE(GLPK 4.33)
    85   IF(GLPK_FOUND)
    86     SET(LEMON_HAVE_LP TRUE)
    87     SET(LEMON_HAVE_MIP TRUE)
    88     SET(LEMON_HAVE_GLPK TRUE)
    89   ENDIF(GLPK_FOUND)
    90 ENDIF(LEMON_ENABLE_GLPK)
    91 IF(LEMON_ENABLE_ILOG)
    92   FIND_PACKAGE(ILOG)
    93   IF(ILOG_FOUND)
    94     SET(LEMON_HAVE_LP TRUE)
    95     SET(LEMON_HAVE_MIP TRUE)
    96     SET(LEMON_HAVE_CPLEX TRUE)
    97   ENDIF(ILOG_FOUND)
    98 ENDIF(LEMON_ENABLE_ILOG)
    99 IF(LEMON_ENABLE_COIN)
   100   FIND_PACKAGE(COIN)
   101   IF(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)
   106   ENDIF(COIN_FOUND)
   107 ENDIF(LEMON_ENABLE_COIN)
   108 IF(LEMON_ENABLE_SOPLEX)
   109   FIND_PACKAGE(SOPLEX)
   110   IF(SOPLEX_FOUND)
   111     SET(LEMON_HAVE_LP TRUE)
   112     SET(LEMON_HAVE_SOPLEX TRUE)
   113   ENDIF(SOPLEX_FOUND)
   114 ENDIF(LEMON_ENABLE_SOPLEX)
   115 
   116 IF(ILOG_FOUND)
   117   SET(DEFAULT_LP "CPLEX")
   118   SET(DEFAULT_MIP "CPLEX")
   119 ELSEIF(COIN_FOUND)
   120   SET(DEFAULT_LP "CLP")
   121   SET(DEFAULT_MIP "CBC")
   122 ELSEIF(GLPK_FOUND)
   123   SET(DEFAULT_LP "GLPK")
   124   SET(DEFAULT_MIP "GLPK")
   125 ELSEIF(SOPLEX_FOUND)
   126   SET(DEFAULT_LP "SOPLEX")
   127 ENDIF()
   128 
   129 IF(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)
   136 ELSE()
   137   SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
   138     "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)")
   139 ENDIF()
   140 IF(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)
   146 ELSE()
   147   SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING
   148     "Default MIP solver backend (GLPK, CPLEX or CBC)")
   149 ENDIF()
   150 
   151 
   152 IF(DEFINED ENV{LEMON_CXX_WARNING})
   153   SET(CXX_WARNING $ENV{LEMON_CXX_WARNING})
   154 ELSE()
   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()
   176 ENDIF()
   177 SET(LEMON_CXX_WARNING_FLAGS ${CXX_WARNING} CACHE STRING "LEMON warning flags.")
   178 
   179 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LEMON_CXX_WARNING_FLAGS}")
   180 
   181 IF(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     )
   197 ELSE()
   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     )
   212 ENDIF()
   213 
   214 MARK_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 
   220 IF(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 
   228 IF(NOT CMAKE_BUILD_TYPE)
   229   SET(CMAKE_BUILD_TYPE "Release")
   230 ENDIF()
   231 
   232 SET( 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 
   236 
   237 INCLUDE(CheckTypeSize)
   238 CHECK_TYPE_SIZE("long long" LONG_LONG)
   239 SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
   240 
   241 INCLUDE(FindThreads)
   242 
   243 IF(NOT LEMON_THREADING)
   244   IF(CMAKE_USE_PTHREADS_INIT)
   245     SET(LEMON_THREADING "Pthread")
   246   ELSEIF(CMAKE_USE_WIN32_THREADS_INIT)
   247     SET(LEMON_THREADING "Win32")
   248   ELSE()
   249     SET(LEMON_THREADING "None")
   250   ENDIF()
   251 ENDIF()
   252 
   253 SET( LEMON_THREADING "${LEMON_THREADING}" CACHE STRING
   254   "Choose the threading library, options are: Pthread Win32 None."
   255   FORCE )
   256 
   257 IF(LEMON_THREADING STREQUAL "Pthread")
   258   SET(LEMON_USE_PTHREAD TRUE)
   259 ELSEIF(LEMON_THREADING STREQUAL "Win32")
   260   SET(LEMON_USE_WIN32_THREADS TRUE)
   261 ENDIF()
   262 
   263 ENABLE_TESTING()
   264 
   265 IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer")
   266   ADD_CUSTOM_TARGET(check ALL COMMAND ${CMAKE_CTEST_COMMAND})
   267 ELSE()
   268   ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
   269 ENDIF()
   270 
   271 ADD_SUBDIRECTORY(lemon)
   272 IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
   273   ADD_SUBDIRECTORY(contrib)
   274   ADD_SUBDIRECTORY(demo)
   275   ADD_SUBDIRECTORY(tools)
   276   ADD_SUBDIRECTORY(doc)
   277   ADD_SUBDIRECTORY(test)
   278 ENDIF()
   279 
   280 CONFIGURE_FILE(
   281   ${PROJECT_SOURCE_DIR}/cmake/LEMONConfig.cmake.in
   282   ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
   283   @ONLY
   284 )
   285 IF(UNIX)
   286   INSTALL(
   287     FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
   288     DESTINATION share/lemon/cmake
   289   )
   290 ELSEIF(WIN32)
   291   INSTALL(
   292     FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
   293     DESTINATION cmake
   294   )
   295 ENDIF()
   296 
   297 CONFIGURE_FILE(
   298   ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in
   299   ${PROJECT_BINARY_DIR}/cmake/version.cmake
   300   @ONLY
   301 )
   302 
   303 SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME})
   304 STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME)
   305 SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION})
   306 ADD_CUSTOM_TARGET(dist
   307   COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
   308   COMMAND hg archive ${ARCHIVE_NAME}
   309   COMMAND cmake -E copy cmake/version.cmake ${ARCHIVE_NAME}/cmake/version.cmake
   310   COMMAND tar -czf ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_NAME}
   311   COMMAND zip -r ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.zip ${ARCHIVE_NAME}
   312   COMMAND cmake -E copy_directory doc/html ${ARCHIVE_NAME}/doc/html
   313   COMMAND tar -czf ${ARCHIVE_NAME}.tar.gz ${ARCHIVE_NAME}
   314   COMMAND zip -r ${ARCHIVE_NAME}.zip ${ARCHIVE_NAME}
   315   COMMAND cmake -E copy_directory doc/html ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
   316   COMMAND tar -czf ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
   317   COMMAND zip -r ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.zip ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
   318   COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
   319   COMMAND cmake -E remove_directory ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
   320   DEPENDS html
   321   WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
   322 
   323 # CPACK config (Basically for NSIS)
   324 IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
   325   SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
   326   SET(CPACK_PACKAGE_VENDOR "EGRES")
   327   SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
   328     "LEMON - Library for Efficient Modeling and Optimization in Networks")
   329   SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
   330 
   331   SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
   332 
   333   SET(CPACK_PACKAGE_INSTALL_DIRECTORY
   334     "${PROJECT_NAME} ${PROJECT_VERSION}")
   335   SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
   336     "${PROJECT_NAME} ${PROJECT_VERSION}")
   337 
   338   SET(CPACK_COMPONENTS_ALL headers library html_documentation bin)
   339 
   340   SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers")
   341   SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Dynamic-link library")
   342   SET(CPACK_COMPONENT_BIN_DISPLAY_NAME "Command line utilities")
   343   SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation")
   344 
   345   SET(CPACK_COMPONENT_HEADERS_DESCRIPTION
   346     "C++ header files")
   347   SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION
   348     "DLL and import library")
   349   SET(CPACK_COMPONENT_BIN_DESCRIPTION
   350     "Command line utilities")
   351   SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION
   352     "Doxygen generated documentation")
   353 
   354   SET(CPACK_COMPONENT_HEADERS_DEPENDS library)
   355 
   356   SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
   357   SET(CPACK_COMPONENT_LIBRARY_GROUP "Development")
   358   SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation")
   359 
   360   SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
   361     "Components needed to develop software using LEMON")
   362   SET(CPACK_COMPONENT_GROUP_DOCUMENTATION_DESCRIPTION
   363     "Documentation of LEMON")
   364 
   365   SET(CPACK_ALL_INSTALL_TYPES Full Developer)
   366 
   367   SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
   368   SET(CPACK_COMPONENT_LIBRARY_INSTALL_TYPES Developer Full)
   369   SET(CPACK_COMPONENT_HTML_DOCUMENTATION_INSTALL_TYPES Full)
   370 
   371   SET(CPACK_GENERATOR "NSIS")
   372   SET(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis/lemon.ico")
   373   SET(CPACK_NSIS_MUI_UNIICON "${PROJECT_SOURCE_DIR}/cmake/nsis/uninstall.ico")
   374   #SET(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis\\\\installer.bmp")
   375   SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lemon.ico")
   376   SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}")
   377   SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\lemon.cs.elte.hu")
   378   SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\lemon.cs.elte.hu")
   379   SET(CPACK_NSIS_CONTACT "lemon-user@lemon.cs.elte.hu")
   380   SET(CPACK_NSIS_CREATE_ICONS_EXTRA "
   381     CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation.lnk\\\" \\\"$INSTDIR\\\\share\\\\doc\\\\index.html\\\"
   382     ")
   383   SET(CPACK_NSIS_DELETE_ICONS_EXTRA "
   384     !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
   385     Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation.lnk\\\"
   386     ")
   387 
   388   INCLUDE(CPack)
   389 ENDIF()