CMakeLists.txt
author Alpar Juttner <alpar@cs.elte.hu>
Tue, 14 Apr 2015 16:14:32 +0200
changeset 1132 0998f70d0b2d
parent 1130 0759d974de81
child 1136 20f95cd51aba
permissions -rw-r--r--
Clang -std=c++11 related fixes (#325)
     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 CMP0043) 
     8   CMAKE_POLICY(SET CMP0043 OLD) 
     9 ENDIF(POLICY CMP0043)
    10 
    11 SET(PROJECT_NAME "LEMON")
    12 PROJECT(${PROJECT_NAME})
    13 
    14 INCLUDE(FindPythonInterp)
    15 INCLUDE(FindWget)
    16 
    17 IF(EXISTS ${PROJECT_SOURCE_DIR}/cmake/version.cmake)
    18   INCLUDE(${PROJECT_SOURCE_DIR}/cmake/version.cmake)
    19 ELSEIF(DEFINED ENV{LEMON_VERSION})
    20   SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.")
    21 ELSE()
    22   EXECUTE_PROCESS(
    23     COMMAND
    24     hg log -r. --template "{latesttag}"
    25     WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
    26     OUTPUT_VARIABLE HG_REVISION_TAG
    27     ERROR_QUIET
    28     OUTPUT_STRIP_TRAILING_WHITESPACE
    29   )
    30   EXECUTE_PROCESS(
    31     COMMAND
    32     hg log -r. --template "{latesttagdistance}"
    33     WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
    34     OUTPUT_VARIABLE HG_REVISION_DIST
    35     ERROR_QUIET
    36     OUTPUT_STRIP_TRAILING_WHITESPACE
    37   )
    38   EXECUTE_PROCESS(
    39     COMMAND
    40     hg log -r. --template "{node|short}"
    41     WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
    42     OUTPUT_VARIABLE HG_REVISION_ID
    43     ERROR_QUIET
    44     OUTPUT_STRIP_TRAILING_WHITESPACE
    45   )
    46 
    47   IF(HG_REVISION_TAG STREQUAL "")
    48     SET(HG_REVISION_ID "hg-tip")
    49   ELSE()
    50     IF(HG_REVISION_TAG STREQUAL "null")
    51       SET(HG_REVISION_TAG "trunk")
    52     ELSEIF(HG_REVISION_TAG MATCHES "^r")
    53       STRING(SUBSTRING ${HG_REVISION_TAG} 1 -1 HG_REVISION_TAG)
    54     ENDIF()
    55     IF(HG_REVISION_DIST STREQUAL "0")
    56       SET(HG_REVISION ${HG_REVISION_TAG})
    57     ELSE()
    58       SET(HG_REVISION
    59 	"${HG_REVISION_TAG}+${HG_REVISION_DIST}-${HG_REVISION_ID}")
    60     ENDIF()
    61   ENDIF()
    62 
    63   SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.")
    64 ENDIF()
    65 
    66 SET(PROJECT_VERSION ${LEMON_VERSION})
    67 
    68 SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
    69 
    70 FIND_PACKAGE(Doxygen)
    71 FIND_PACKAGE(Ghostscript)
    72 
    73 SET(LEMON_ENABLE_GLPK YES CACHE STRING "Enable GLPK solver backend.")
    74 SET(LEMON_ENABLE_ILOG YES CACHE STRING "Enable ILOG (CPLEX) solver backend.")
    75 SET(LEMON_ENABLE_COIN YES CACHE STRING "Enable COIN solver backend.")
    76 SET(LEMON_ENABLE_SOPLEX YES CACHE STRING "Enable SoPlex solver backend.")
    77 
    78 IF(LEMON_ENABLE_GLPK) 
    79   FIND_PACKAGE(GLPK 4.33)
    80 ENDIF(LEMON_ENABLE_GLPK)
    81 IF(LEMON_ENABLE_ILOG)
    82   FIND_PACKAGE(ILOG)
    83 ENDIF(LEMON_ENABLE_ILOG)
    84 IF(LEMON_ENABLE_COIN)
    85   FIND_PACKAGE(COIN)
    86 ENDIF(LEMON_ENABLE_COIN)
    87 IF(LEMON_ENABLE_SOPLEX)
    88   FIND_PACKAGE(SOPLEX)
    89 ENDIF(LEMON_ENABLE_SOPLEX)
    90 
    91 IF(GLPK_FOUND)
    92   SET(LEMON_HAVE_LP TRUE)
    93   SET(LEMON_HAVE_MIP TRUE)
    94   SET(LEMON_HAVE_GLPK TRUE)
    95 ENDIF(GLPK_FOUND)
    96 IF(ILOG_FOUND)
    97   SET(LEMON_HAVE_LP TRUE)
    98   SET(LEMON_HAVE_MIP TRUE)
    99   SET(LEMON_HAVE_CPLEX TRUE)
   100 ENDIF(ILOG_FOUND)
   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 IF(SOPLEX_FOUND)
   108   SET(LEMON_HAVE_LP TRUE)
   109   SET(LEMON_HAVE_SOPLEX TRUE)
   110 ENDIF(SOPLEX_FOUND)
   111 
   112 IF(ILOG_FOUND)
   113   SET(DEFAULT_LP "CPLEX")
   114   SET(DEFAULT_MIP "CPLEX")
   115 ELSEIF(COIN_FOUND)
   116   SET(DEFAULT_LP "CLP")
   117   SET(DEFAULT_MIP "CBC")
   118 ELSEIF(GLPK_FOUND)
   119   SET(DEFAULT_LP "GLPK")
   120   SET(DEFAULT_MIP "GLPK")
   121 ELSEIF(SOPLEX_FOUND)
   122   SET(DEFAULT_LP "SOPLEX")
   123 ENDIF()
   124 
   125 IF(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)
   132 ELSE()
   133   SET(LEMON_DEFAULT_LP ${DEFAULT_LP} CACHE STRING
   134     "Default LP solver backend (GLPK, CPLEX, CLP or SOPLEX)")
   135 ENDIF()
   136 IF(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)
   142 ELSE()
   143   SET(LEMON_DEFAULT_MIP ${DEFAULT_MIP} CACHE STRING
   144     "Default MIP solver backend (GLPK, CPLEX or CBC)")
   145 ENDIF()
   146 
   147 
   148 IF(DEFINED ENV{LEMON_CXX_WARNING})
   149   SET(CXX_WARNING $ENV{LEMON_CXX_WARNING})
   150 ELSE()
   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()
   172 ENDIF()
   173 SET(LEMON_CXX_WARNING_FLAGS ${CXX_WARNING} CACHE STRING "LEMON warning flags.")
   174 
   175 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LEMON_CXX_WARNING_FLAGS}")
   176 
   177 IF(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     )
   193 ELSE()
   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     )
   208 ENDIF()
   209 
   210 MARK_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 
   216 IF(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 
   224 IF(NOT CMAKE_BUILD_TYPE)
   225   SET(CMAKE_BUILD_TYPE "Release")
   226 ENDIF()
   227 
   228 SET( 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 SET_DIRECTORY_PROPERTIES(PROPERTIES
   233   COMPILE_DEFINITIONS_DEBUG "LEMON_ENABLE_DEBUG"
   234   COMPILE_DEFINITIONS_MAINTAINER "LEMON_ENABLE_DEBUG"
   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 
   266 INCLUDE(CheckCXXCompilerFlag)
   267 CHECK_CXX_COMPILER_FLAG("-std=c++11" LEMON_CXX11)
   268 IF(LEMON_CXX11)
   269   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
   270 ENDIF()
   271 
   272 
   273 IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer")
   274   ADD_CUSTOM_TARGET(check ALL COMMAND ${CMAKE_CTEST_COMMAND})
   275 ELSE()
   276   ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
   277 ENDIF()
   278 
   279 ADD_SUBDIRECTORY(lemon)
   280 IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
   281   ADD_SUBDIRECTORY(contrib)
   282   ADD_SUBDIRECTORY(demo)
   283   ADD_SUBDIRECTORY(tools)
   284   ADD_SUBDIRECTORY(doc)
   285   ADD_SUBDIRECTORY(test)
   286 ENDIF()
   287 
   288 CONFIGURE_FILE(
   289   ${PROJECT_SOURCE_DIR}/cmake/LEMONConfig.cmake.in
   290   ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
   291   @ONLY
   292 )
   293 IF(UNIX)
   294   INSTALL(
   295     FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
   296     DESTINATION share/lemon/cmake
   297   )
   298 ELSEIF(WIN32)
   299   INSTALL(
   300     FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
   301     DESTINATION cmake
   302   )
   303 ENDIF()
   304 
   305 CONFIGURE_FILE(
   306   ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in
   307   ${PROJECT_BINARY_DIR}/cmake/version.cmake
   308   @ONLY
   309 )
   310 
   311 SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME})
   312 STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME)
   313 SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION})
   314 ADD_CUSTOM_TARGET(dist
   315   COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
   316   COMMAND hg archive ${ARCHIVE_NAME}
   317   COMMAND cmake -E copy cmake/version.cmake ${ARCHIVE_NAME}/cmake/version.cmake
   318   COMMAND tar -czf ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_NAME}
   319   COMMAND zip -r ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.zip ${ARCHIVE_NAME}
   320   COMMAND cmake -E copy_directory doc/html ${ARCHIVE_NAME}/doc/html
   321   COMMAND tar -czf ${ARCHIVE_NAME}.tar.gz ${ARCHIVE_NAME}
   322   COMMAND zip -r ${ARCHIVE_NAME}.zip ${ARCHIVE_NAME}
   323   COMMAND cmake -E copy_directory doc/html ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
   324   COMMAND tar -czf ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
   325   COMMAND zip -r ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.zip ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
   326   COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
   327   COMMAND cmake -E remove_directory ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
   328   DEPENDS html
   329   WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
   330 
   331 # CPACK config (Basically for NSIS)
   332 IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
   333   SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
   334   SET(CPACK_PACKAGE_VENDOR "EGRES")
   335   SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
   336     "LEMON - Library for Efficient Modeling and Optimization in Networks")
   337   SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
   338 
   339   SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
   340 
   341   SET(CPACK_PACKAGE_INSTALL_DIRECTORY
   342     "${PROJECT_NAME} ${PROJECT_VERSION}")
   343   SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
   344     "${PROJECT_NAME} ${PROJECT_VERSION}")
   345 
   346   SET(CPACK_COMPONENTS_ALL headers library html_documentation bin)
   347 
   348   SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers")
   349   SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Dynamic-link library")
   350   SET(CPACK_COMPONENT_BIN_DISPLAY_NAME "Command line utilities")
   351   SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation")
   352 
   353   SET(CPACK_COMPONENT_HEADERS_DESCRIPTION
   354     "C++ header files")
   355   SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION
   356     "DLL and import library")
   357   SET(CPACK_COMPONENT_BIN_DESCRIPTION
   358     "Command line utilities")
   359   SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION
   360     "Doxygen generated documentation")
   361 
   362   SET(CPACK_COMPONENT_HEADERS_DEPENDS library)
   363 
   364   SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
   365   SET(CPACK_COMPONENT_LIBRARY_GROUP "Development")
   366   SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation")
   367 
   368   SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
   369     "Components needed to develop software using LEMON")
   370   SET(CPACK_COMPONENT_GROUP_DOCUMENTATION_DESCRIPTION
   371     "Documentation of LEMON")
   372 
   373   SET(CPACK_ALL_INSTALL_TYPES Full Developer)
   374 
   375   SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
   376   SET(CPACK_COMPONENT_LIBRARY_INSTALL_TYPES Developer Full)
   377   SET(CPACK_COMPONENT_HTML_DOCUMENTATION_INSTALL_TYPES Full)
   378 
   379   SET(CPACK_GENERATOR "NSIS")
   380   SET(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis/lemon.ico")
   381   SET(CPACK_NSIS_MUI_UNIICON "${PROJECT_SOURCE_DIR}/cmake/nsis/uninstall.ico")
   382   #SET(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis\\\\installer.bmp")
   383   SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lemon.ico")
   384   SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}")
   385   SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\lemon.cs.elte.hu")
   386   SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\lemon.cs.elte.hu")
   387   SET(CPACK_NSIS_CONTACT "lemon-user@lemon.cs.elte.hu")
   388   SET(CPACK_NSIS_CREATE_ICONS_EXTRA "
   389     CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation.lnk\\\" \\\"$INSTDIR\\\\share\\\\doc\\\\index.html\\\"
   390     ")
   391   SET(CPACK_NSIS_DELETE_ICONS_EXTRA "
   392     !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
   393     Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation.lnk\\\"
   394     ")
   395 
   396   INCLUDE(CPack)
   397 ENDIF()