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