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