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