CMakeLists.txt
author Alpar Juttner <alpar@cs.elte.hu>
Mon, 07 Jul 2014 15:58:07 +0200
branch1.3
changeset 1319 11de70cf8550
parent 1310 fc35e3ff4bea
child 1322 1552352f9798
permissions -rw-r--r--
Merge bugfix #474 to branch 1.3
     1 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
     2 
     3 CMAKE_POLICY(SET CMP0048 OLD)
     4 
     5 SET(PROJECT_NAME "LEMON")
     6 PROJECT(${PROJECT_NAME})
     7 
     8 INCLUDE(FindPythonInterp)
     9 INCLUDE(FindWget)
    10 
    11 IF(EXISTS ${PROJECT_SOURCE_DIR}/cmake/version.cmake)
    12   INCLUDE(${PROJECT_SOURCE_DIR}/cmake/version.cmake)
    13 ELSEIF(DEFINED ENV{LEMON_VERSION})
    14   SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.")
    15 ELSE()
    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.")
    58 ENDIF()
    59 
    60 SET(PROJECT_VERSION ${LEMON_VERSION})
    61 
    62 SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
    63 
    64 FIND_PACKAGE(Doxygen)
    65 FIND_PACKAGE(Ghostscript)
    66 
    67 SET(LEMON_ENABLE_GLPK YES CACHE STRING "Enable GLPK solver backend.")
    68 SET(LEMON_ENABLE_ILOG YES CACHE STRING "Enable ILOG (CPLEX) solver backend.")
    69 SET(LEMON_ENABLE_COIN YES CACHE STRING "Enable COIN solver backend.")
    70 SET(LEMON_ENABLE_SOPLEX YES CACHE STRING "Enable SoPlex solver backend.")
    71 
    72 IF(LEMON_ENABLE_GLPK) 
    73   FIND_PACKAGE(GLPK 4.33)
    74 ENDIF(LEMON_ENABLE_GLPK)
    75 IF(LEMON_ENABLE_ILOG)
    76   FIND_PACKAGE(ILOG)
    77 ENDIF(LEMON_ENABLE_ILOG)
    78 IF(LEMON_ENABLE_COIN)
    79   FIND_PACKAGE(COIN)
    80 ENDIF(LEMON_ENABLE_COIN)
    81 IF(LEMON_ENABLE_SOPLEX)
    82   FIND_PACKAGE(SOPLEX)
    83 ENDIF(LEMON_ENABLE_SOPLEX)
    84 
    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 IF(ILOG_FOUND)
    91   SET(LEMON_HAVE_LP TRUE)
    92   SET(LEMON_HAVE_MIP TRUE)
    93   SET(LEMON_HAVE_CPLEX TRUE)
    94 ENDIF(ILOG_FOUND)
    95 IF(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)
   100 ENDIF(COIN_FOUND)
   101 IF(SOPLEX_FOUND)
   102   SET(LEMON_HAVE_LP TRUE)
   103   SET(LEMON_HAVE_SOPLEX TRUE)
   104 ENDIF(SOPLEX_FOUND)
   105 
   106 IF(ILOG_FOUND)
   107   SET(DEFAULT_LP "CPLEX")
   108   SET(DEFAULT_MIP "CPLEX")
   109 ELSEIF(COIN_FOUND)
   110   SET(DEFAULT_LP "CLP")
   111   SET(DEFAULT_MIP "CBC")
   112 ELSEIF(GLPK_FOUND)
   113   SET(DEFAULT_LP "GLPK")
   114   SET(DEFAULT_MIP "GLPK")
   115 ELSEIF(SOPLEX_FOUND)
   116   SET(DEFAULT_LP "SOPLEX")
   117 ENDIF()
   118 
   119 IF(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)
   126 ELSE()
   127   SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
   128     "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)")
   129 ENDIF()
   130 IF(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)
   136 ELSE()
   137   SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING
   138     "Default MIP solver backend (GLPK, CPLEX or CBC)")
   139 ENDIF()
   140 
   141 
   142 IF(DEFINED ENV{LEMON_CXX_WARNING})
   143   SET(CXX_WARNING $ENV{LEMON_CXX_WARNING})
   144 ELSE()
   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()
   163 ENDIF()
   164 SET(LEMON_CXX_WARNING_FLAGS ${CXX_WARNING} CACHE STRING "LEMON warning flags.")
   165 
   166 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LEMON_CXX_WARNING_FLAGS}")
   167 
   168 IF(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     )
   183 ELSE()
   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     )
   198 ENDIF()
   199 
   200 MARK_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 
   206 IF(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 
   214 IF(NOT CMAKE_BUILD_TYPE)
   215   SET(CMAKE_BUILD_TYPE "Release")
   216 ENDIF()
   217 
   218 SET( 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 
   223 INCLUDE(CheckTypeSize)
   224 CHECK_TYPE_SIZE("long long" LONG_LONG)
   225 SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
   226 
   227 INCLUDE(FindThreads)
   228 
   229 IF(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()
   237 ENDIF()
   238 
   239 SET( LEMON_THREADING "${LEMON_THREADING}" CACHE STRING
   240   "Choose the threading library, options are: Pthread Win32 None."
   241   FORCE )
   242 
   243 IF(LEMON_THREADING STREQUAL "Pthread")
   244   SET(LEMON_USE_PTHREAD TRUE)
   245 ELSEIF(LEMON_THREADING STREQUAL "Win32")
   246   SET(LEMON_USE_WIN32_THREADS TRUE)
   247 ENDIF()
   248 
   249 ENABLE_TESTING()
   250 
   251 IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer")
   252   ADD_CUSTOM_TARGET(check ALL COMMAND ${CMAKE_CTEST_COMMAND})
   253 ELSE()
   254   ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
   255 ENDIF()
   256 
   257 ADD_SUBDIRECTORY(lemon)
   258 IF(${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)
   264 ENDIF()
   265 
   266 CONFIGURE_FILE(
   267   ${PROJECT_SOURCE_DIR}/cmake/LEMONConfig.cmake.in
   268   ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
   269   @ONLY
   270 )
   271 IF(UNIX)
   272   INSTALL(
   273     FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
   274     DESTINATION share/lemon/cmake
   275   )
   276 ELSEIF(WIN32)
   277   INSTALL(
   278     FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
   279     DESTINATION cmake
   280   )
   281 ENDIF()
   282 
   283 CONFIGURE_FILE(
   284   ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in
   285   ${PROJECT_BINARY_DIR}/cmake/version.cmake
   286   @ONLY
   287 )
   288 
   289 SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME})
   290 STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME)
   291 SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION})
   292 ADD_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)
   310 IF(${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)
   375 ENDIF()