CMakeLists.txt
author Alpar Juttner <alpar@cs.elte.hu>
Thu, 22 Dec 2011 20:55:43 +0100
changeset 992 78434a448b5e
parent 982 0b9a94956916
child 1000 404b98971e1f
permissions -rw-r--r--
Update INSTALL to use CMAKE. Also update AUTHORS and LICENSE
alpar@225
     1
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
alpar@225
     2
ladanyi@678
     3
SET(PROJECT_NAME "LEMON")
ladanyi@678
     4
PROJECT(${PROJECT_NAME})
alpar@225
     5
alpar@927
     6
INCLUDE(FindPythonInterp)
alpar@927
     7
INCLUDE(FindWget)
alpar@927
     8
ladanyi@678
     9
IF(EXISTS ${PROJECT_SOURCE_DIR}/cmake/version.cmake)
ladanyi@678
    10
  INCLUDE(${PROJECT_SOURCE_DIR}/cmake/version.cmake)
ladanyi@678
    11
ELSEIF(DEFINED ENV{LEMON_VERSION})
ladanyi@678
    12
  SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.")
ladanyi@678
    13
ELSE()
ladanyi@678
    14
  EXECUTE_PROCESS(
alpar@982
    15
    COMMAND
alpar@982
    16
    hg log -r. --template "{latesttag}"
alpar@927
    17
    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
alpar@982
    18
    OUTPUT_VARIABLE HG_REVISION_TAG
alpar@927
    19
    ERROR_QUIET
alpar@927
    20
    OUTPUT_STRIP_TRAILING_WHITESPACE
alpar@927
    21
  )
alpar@927
    22
  EXECUTE_PROCESS(
alpar@982
    23
    COMMAND
alpar@982
    24
    hg log -r. --template "{latesttagdistance}"
ladanyi@678
    25
    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
alpar@982
    26
    OUTPUT_VARIABLE HG_REVISION_DIST
ladanyi@678
    27
    ERROR_QUIET
ladanyi@678
    28
    OUTPUT_STRIP_TRAILING_WHITESPACE
ladanyi@678
    29
  )
alpar@982
    30
  EXECUTE_PROCESS(
alpar@982
    31
    COMMAND
alpar@982
    32
    hg log -r. --template "{node|short}"
alpar@982
    33
    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
alpar@982
    34
    OUTPUT_VARIABLE HG_REVISION_ID
alpar@982
    35
    ERROR_QUIET
alpar@982
    36
    OUTPUT_STRIP_TRAILING_WHITESPACE
alpar@982
    37
  )
alpar@982
    38
alpar@982
    39
  IF(HG_REVISION_TAG STREQUAL "")
alpar@927
    40
    SET(HG_REVISION_ID "hg-tip")
alpar@927
    41
  ELSE()
alpar@982
    42
    IF(HG_REVISION_TAG STREQUAL "null")
alpar@982
    43
      SET(HG_REVISION_TAG "trunk")
alpar@982
    44
    ELSEIF(HG_REVISION_TAG MATCHES "^r")
alpar@982
    45
      STRING(SUBSTRING ${HG_REVISION_TAG} 1 -1 HG_REVISION_TAG)
alpar@982
    46
    ENDIF()
alpar@982
    47
    IF(HG_REVISION_DIST STREQUAL "0")
alpar@982
    48
      SET(HG_REVISION ${HG_REVISION_TAG})
alpar@927
    49
    ELSE()
alpar@982
    50
      SET(HG_REVISION
alpar@982
    51
	"${HG_REVISION_TAG}+${HG_REVISION_DIST}-${HG_REVISION_ID}")
alpar@927
    52
    ENDIF()
ladanyi@680
    53
  ENDIF()
alpar@982
    54
alpar@982
    55
  SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.")
ladanyi@678
    56
ENDIF()
ladanyi@678
    57
ladanyi@678
    58
SET(PROJECT_VERSION ${LEMON_VERSION})
alpar@225
    59
ladanyi@549
    60
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
alpar@225
    61
ladanyi@679
    62
FIND_PACKAGE(Doxygen)
ladanyi@679
    63
FIND_PACKAGE(Ghostscript)
ladanyi@473
    64
FIND_PACKAGE(GLPK 4.33)
ladanyi@620
    65
FIND_PACKAGE(CPLEX)
ladanyi@621
    66
FIND_PACKAGE(COIN)
ladanyi@473
    67
alpar@927
    68
IF(DEFINED ENV{LEMON_CXX_WARNING})
alpar@927
    69
  SET(CXX_WARNING $ENV{LEMON_CXX_WARNING})
alpar@927
    70
ELSE()
alpar@927
    71
  IF(CMAKE_COMPILER_IS_GNUCXX)
alpar@940
    72
    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")
alpar@927
    73
    SET(CMAKE_CXX_FLAGS_DEBUG CACHE STRING "-ggdb")
alpar@927
    74
    SET(CMAKE_C_FLAGS_DEBUG CACHE STRING "-ggdb")
alpar@927
    75
  ELSEIF(MSVC)
alpar@927
    76
    # This part is unnecessary 'casue the same is set by the lemon/core.h.
alpar@927
    77
    # Still keep it as an example.
alpar@927
    78
    SET(CXX_WARNING "/wd4250 /wd4355 /wd4503 /wd4800 /wd4996")
alpar@927
    79
    # Suppressed warnings:
alpar@927
    80
    # C4250: 'class1' : inherits 'class2::member' via dominance
alpar@927
    81
    # C4355: 'this' : used in base member initializer list
alpar@927
    82
    # C4503: 'function' : decorated name length exceeded, name was truncated
alpar@927
    83
    # C4800: 'type' : forcing value to bool 'true' or 'false'
alpar@927
    84
    #        (performance warning)
alpar@927
    85
    # C4996: 'function': was declared deprecated
alpar@927
    86
  ELSE()
alpar@975
    87
    SET(CXX_WARNING "-Wall")
alpar@927
    88
  ENDIF()
alpar@927
    89
ENDIF()
alpar@927
    90
SET(LEMON_CXX_WARNING_FLAGS ${CXX_WARNING} CACHE STRING "LEMON warning flags.")
alpar@927
    91
alpar@927
    92
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LEMON_CXX_WARNING_FLAGS}")
alpar@927
    93
alpar@975
    94
SET( CMAKE_CXX_FLAGS_MAINTAINER "-Werror -ggdb -O0" CACHE STRING
alpar@927
    95
    "Flags used by the C++ compiler during maintainer builds."
alpar@927
    96
    FORCE )
alpar@975
    97
SET( CMAKE_C_FLAGS_MAINTAINER "-Werror -O0" CACHE STRING
alpar@927
    98
    "Flags used by the C compiler during maintainer builds."
alpar@927
    99
    FORCE )
alpar@927
   100
SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
alpar@927
   101
    "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
alpar@927
   102
    "Flags used for linking binaries during maintainer builds."
alpar@927
   103
    FORCE )
alpar@927
   104
SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
alpar@927
   105
    "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
alpar@927
   106
    "Flags used by the shared libraries linker during maintainer builds."
alpar@927
   107
    FORCE )
alpar@927
   108
MARK_AS_ADVANCED(
alpar@927
   109
    CMAKE_CXX_FLAGS_MAINTAINER
alpar@927
   110
    CMAKE_C_FLAGS_MAINTAINER
alpar@927
   111
    CMAKE_EXE_LINKER_FLAGS_MAINTAINER
alpar@927
   112
    CMAKE_SHARED_LINKER_FLAGS_MAINTAINER )
alpar@927
   113
alpar@927
   114
IF(CMAKE_CONFIGURATION_TYPES)
alpar@927
   115
  LIST(APPEND CMAKE_CONFIGURATION_TYPES Maintainer)
alpar@927
   116
  LIST(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
alpar@927
   117
  SET(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
alpar@927
   118
      "Add the configurations that we need"
alpar@927
   119
      FORCE)
alpar@927
   120
 endif()
alpar@927
   121
alpar@927
   122
IF(NOT CMAKE_BUILD_TYPE)
alpar@927
   123
  SET(CMAKE_BUILD_TYPE "Release")
alpar@927
   124
ENDIF()
alpar@927
   125
alpar@927
   126
SET( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
alpar@927
   127
    "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel Maintainer."
alpar@927
   128
    FORCE )
alpar@927
   129
alpar@927
   130
alpar@496
   131
INCLUDE(CheckTypeSize)
ladanyi@677
   132
CHECK_TYPE_SIZE("long long" LONG_LONG)
ladanyi@677
   133
SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
alpar@496
   134
deba@979
   135
INCLUDE(FindThreads)
alpar@980
   136
alpar@980
   137
IF(NOT LEMON_THREADING)
alpar@980
   138
  IF(CMAKE_USE_PTHREADS_INIT)
alpar@980
   139
    SET(LEMON_THREADING "Pthread")
alpar@980
   140
  ELSEIF(CMAKE_USE_WIN32_THREADS_INIT)
alpar@980
   141
    SET(LEMON_THREADING "Win32")
alpar@980
   142
  ELSE()
alpar@980
   143
    SET(LEMON_THREADING "None")
alpar@980
   144
  ENDIF()
alpar@980
   145
ENDIF()
alpar@980
   146
alpar@980
   147
SET( LEMON_THREADING "${LEMON_THREADING}" CACHE STRING
alpar@980
   148
  "Choose the threading library, options are: Pthread Win32 None."
alpar@980
   149
  FORCE )
alpar@980
   150
alpar@980
   151
IF(LEMON_THREADING STREQUAL "Pthread")
alpar@980
   152
  SET(LEMON_USE_PTHREAD TRUE)
alpar@980
   153
ELSEIF(LEMON_THREADING STREQUAL "Win32")
alpar@980
   154
  SET(LEMON_USE_WIN32_THREADS TRUE)
alpar@980
   155
ENDIF()
deba@979
   156
alpar@225
   157
ENABLE_TESTING()
alpar@225
   158
alpar@927
   159
IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer")
alpar@927
   160
  ADD_CUSTOM_TARGET(check ALL COMMAND ${CMAKE_CTEST_COMMAND})
alpar@927
   161
ELSE()
alpar@927
   162
  ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
alpar@927
   163
ENDIF()
alpar@927
   164
alpar@225
   165
ADD_SUBDIRECTORY(lemon)
ladanyi@549
   166
IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
alpar@925
   167
  ADD_SUBDIRECTORY(contrib)
ladanyi@549
   168
  ADD_SUBDIRECTORY(demo)
ladanyi@549
   169
  ADD_SUBDIRECTORY(tools)
ladanyi@549
   170
  ADD_SUBDIRECTORY(doc)
ladanyi@549
   171
  ADD_SUBDIRECTORY(test)
ladanyi@679
   172
ENDIF()
alpar@225
   173
ladanyi@675
   174
CONFIGURE_FILE(
ladanyi@675
   175
  ${PROJECT_SOURCE_DIR}/cmake/LEMONConfig.cmake.in
ladanyi@675
   176
  ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
ladanyi@675
   177
  @ONLY
ladanyi@675
   178
)
ladanyi@675
   179
IF(UNIX)
ladanyi@675
   180
  INSTALL(
ladanyi@675
   181
    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
ladanyi@675
   182
    DESTINATION share/lemon/cmake
ladanyi@675
   183
  )
ladanyi@675
   184
ELSEIF(WIN32)
ladanyi@675
   185
  INSTALL(
ladanyi@675
   186
    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
ladanyi@675
   187
    DESTINATION cmake
ladanyi@675
   188
  )
ladanyi@679
   189
ENDIF()
ladanyi@675
   190
alpar@983
   191
CONFIGURE_FILE(
alpar@983
   192
  ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in
alpar@983
   193
  ${PROJECT_BINARY_DIR}/cmake/version.cmake
alpar@983
   194
  @ONLY
alpar@983
   195
)
alpar@983
   196
alpar@983
   197
SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME})
alpar@983
   198
STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME)
alpar@983
   199
SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION})
alpar@983
   200
ADD_CUSTOM_TARGET(dist
alpar@983
   201
  COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
alpar@983
   202
  COMMAND hg archive ${ARCHIVE_NAME}
alpar@983
   203
  COMMAND cmake -E copy cmake/version.cmake ${ARCHIVE_NAME}/cmake/version.cmake
alpar@983
   204
  COMMAND tar -czf ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_NAME}
alpar@983
   205
  COMMAND zip -r ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.zip ${ARCHIVE_NAME}
alpar@983
   206
  COMMAND cmake -E copy_directory doc/html ${ARCHIVE_NAME}/doc/html
alpar@983
   207
  COMMAND tar -czf ${ARCHIVE_NAME}.tar.gz ${ARCHIVE_NAME}
alpar@983
   208
  COMMAND zip -r ${ARCHIVE_NAME}.zip ${ARCHIVE_NAME}
alpar@983
   209
  COMMAND cmake -E copy_directory doc/html ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
alpar@983
   210
  COMMAND tar -czf ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
alpar@983
   211
  COMMAND zip -r ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.zip ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
alpar@983
   212
  COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
alpar@983
   213
  COMMAND cmake -E remove_directory ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
alpar@983
   214
  DEPENDS html
alpar@983
   215
  WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
alpar@983
   216
alpar@983
   217
# CPACK config (Basically for NSIS)
alpar@927
   218
IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
ladanyi@679
   219
  SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
ladanyi@679
   220
  SET(CPACK_PACKAGE_VENDOR "EGRES")
ladanyi@679
   221
  SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
ladanyi@679
   222
    "LEMON - Library for Efficient Modeling and Optimization in Networks")
ladanyi@679
   223
  SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
alpar@225
   224
ladanyi@679
   225
  SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
alpar@225
   226
ladanyi@679
   227
  SET(CPACK_PACKAGE_INSTALL_DIRECTORY
ladanyi@679
   228
    "${PROJECT_NAME} ${PROJECT_VERSION}")
ladanyi@679
   229
  SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
ladanyi@679
   230
    "${PROJECT_NAME} ${PROJECT_VERSION}")
alpar@225
   231
ladanyi@679
   232
  SET(CPACK_COMPONENTS_ALL headers library html_documentation bin)
alpar@225
   233
ladanyi@679
   234
  SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers")
ladanyi@679
   235
  SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Dynamic-link library")
ladanyi@679
   236
  SET(CPACK_COMPONENT_BIN_DISPLAY_NAME "Command line utilities")
ladanyi@679
   237
  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation")
alpar@225
   238
ladanyi@679
   239
  SET(CPACK_COMPONENT_HEADERS_DESCRIPTION
ladanyi@679
   240
    "C++ header files")
ladanyi@679
   241
  SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION
ladanyi@679
   242
    "DLL and import library")
ladanyi@679
   243
  SET(CPACK_COMPONENT_BIN_DESCRIPTION
ladanyi@679
   244
    "Command line utilities")
ladanyi@679
   245
  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION
ladanyi@679
   246
    "Doxygen generated documentation")
alpar@225
   247
ladanyi@679
   248
  SET(CPACK_COMPONENT_HEADERS_DEPENDS library)
alpar@225
   249
ladanyi@679
   250
  SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
ladanyi@679
   251
  SET(CPACK_COMPONENT_LIBRARY_GROUP "Development")
ladanyi@679
   252
  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation")
alpar@225
   253
ladanyi@679
   254
  SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
ladanyi@679
   255
    "Components needed to develop software using LEMON")
ladanyi@679
   256
  SET(CPACK_COMPONENT_GROUP_DOCUMENTATION_DESCRIPTION
ladanyi@679
   257
    "Documentation of LEMON")
alpar@225
   258
ladanyi@679
   259
  SET(CPACK_ALL_INSTALL_TYPES Full Developer)
alpar@225
   260
ladanyi@679
   261
  SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
ladanyi@679
   262
  SET(CPACK_COMPONENT_LIBRARY_INSTALL_TYPES Developer Full)
ladanyi@679
   263
  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_INSTALL_TYPES Full)
alpar@225
   264
ladanyi@679
   265
  SET(CPACK_GENERATOR "NSIS")
ladanyi@679
   266
  SET(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis/lemon.ico")
ladanyi@679
   267
  SET(CPACK_NSIS_MUI_UNIICON "${PROJECT_SOURCE_DIR}/cmake/nsis/uninstall.ico")
ladanyi@679
   268
  #SET(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis\\\\installer.bmp")
ladanyi@679
   269
  SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lemon.ico")
ladanyi@679
   270
  SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}")
ladanyi@679
   271
  SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\lemon.cs.elte.hu")
ladanyi@679
   272
  SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\lemon.cs.elte.hu")
ladanyi@679
   273
  SET(CPACK_NSIS_CONTACT "lemon-user@lemon.cs.elte.hu")
ladanyi@679
   274
  SET(CPACK_NSIS_CREATE_ICONS_EXTRA "
ladanyi@679
   275
    CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation.lnk\\\" \\\"$INSTDIR\\\\share\\\\doc\\\\index.html\\\"
ladanyi@679
   276
    ")
ladanyi@679
   277
  SET(CPACK_NSIS_DELETE_ICONS_EXTRA "
ladanyi@679
   278
    !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
ladanyi@679
   279
    Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation.lnk\\\"
ladanyi@679
   280
    ")
alpar@225
   281
ladanyi@679
   282
  INCLUDE(CPack)
ladanyi@679
   283
ENDIF()