CMakeLists.txt
author Alpar Juttner <alpar@cs.elte.hu>
Fri, 22 Feb 2013 16:49:41 +0100
changeset 1184 97975184f4aa
parent 1135 fc1aa7c01c55
parent 1159 7fdaa05a69a1
child 1185 b4f4c08e1210
permissions -rw-r--r--
Merge bugfix #445
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@1125
    94
SET( CMAKE_CXX_FLAGS_MAINTAINER "-Werror -ggdb -O0" CACHE STRING
alpar@1033
    95
    "Flags used by the C++ compiler during maintainer builds."
alpar@1033
    96
    FORCE )
alpar@1125
    97
SET( CMAKE_C_FLAGS_MAINTAINER "-Werror -O0" CACHE STRING
alpar@1033
    98
    "Flags used by the C compiler during maintainer builds."
alpar@1033
    99
    FORCE )
alpar@1033
   100
SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
alpar@1033
   101
    "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
alpar@1033
   102
    "Flags used for linking binaries during maintainer builds."
alpar@1033
   103
    FORCE )
alpar@1033
   104
SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
alpar@1033
   105
    "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
alpar@1033
   106
    "Flags used by the shared libraries linker during maintainer builds."
alpar@1033
   107
    FORCE )
alpar@1033
   108
MARK_AS_ADVANCED(
alpar@1033
   109
    CMAKE_CXX_FLAGS_MAINTAINER
alpar@1033
   110
    CMAKE_C_FLAGS_MAINTAINER
alpar@1033
   111
    CMAKE_EXE_LINKER_FLAGS_MAINTAINER
alpar@1033
   112
    CMAKE_SHARED_LINKER_FLAGS_MAINTAINER )
alpar@1033
   113
alpar@1033
   114
IF(CMAKE_CONFIGURATION_TYPES)
alpar@1033
   115
  LIST(APPEND CMAKE_CONFIGURATION_TYPES Maintainer)
alpar@1033
   116
  LIST(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
alpar@1033
   117
  SET(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
alpar@1033
   118
      "Add the configurations that we need"
alpar@1033
   119
      FORCE)
alpar@1033
   120
 endif()
alpar@1033
   121
alpar@1033
   122
IF(NOT CMAKE_BUILD_TYPE)
alpar@1033
   123
  SET(CMAKE_BUILD_TYPE "Release")
alpar@1033
   124
ENDIF()
alpar@1033
   125
alpar@1033
   126
SET( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
alpar@1033
   127
    "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel Maintainer."
alpar@1033
   128
    FORCE )
alpar@1033
   129
alpar@1033
   130
alpar@515
   131
INCLUDE(CheckTypeSize)
ladanyi@724
   132
CHECK_TYPE_SIZE("long long" LONG_LONG)
ladanyi@724
   133
SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
alpar@515
   134
deba@1131
   135
INCLUDE(FindThreads)
alpar@1132
   136
alpar@1132
   137
IF(NOT LEMON_THREADING)
alpar@1132
   138
  IF(CMAKE_USE_PTHREADS_INIT)
alpar@1132
   139
    SET(LEMON_THREADING "Pthread")
alpar@1132
   140
  ELSEIF(CMAKE_USE_WIN32_THREADS_INIT)
alpar@1132
   141
    SET(LEMON_THREADING "Win32")
alpar@1132
   142
  ELSE()
alpar@1132
   143
    SET(LEMON_THREADING "None")
alpar@1132
   144
  ENDIF()
alpar@1132
   145
ENDIF()
alpar@1132
   146
alpar@1132
   147
SET( LEMON_THREADING "${LEMON_THREADING}" CACHE STRING
alpar@1132
   148
  "Choose the threading library, options are: Pthread Win32 None."
alpar@1132
   149
  FORCE )
alpar@1132
   150
alpar@1132
   151
IF(LEMON_THREADING STREQUAL "Pthread")
alpar@1132
   152
  SET(LEMON_USE_PTHREAD TRUE)
alpar@1132
   153
ELSEIF(LEMON_THREADING STREQUAL "Win32")
alpar@1132
   154
  SET(LEMON_USE_WIN32_THREADS TRUE)
alpar@1132
   155
ENDIF()
alpar@791
   156
alpar@225
   157
ENABLE_TESTING()
alpar@225
   158
alpar@1033
   159
IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer")
alpar@1033
   160
  ADD_CUSTOM_TARGET(check ALL COMMAND ${CMAKE_CTEST_COMMAND})
alpar@1033
   161
ELSE()
alpar@1033
   162
  ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
alpar@1033
   163
ENDIF()
alpar@1033
   164
alpar@225
   165
ADD_SUBDIRECTORY(lemon)
ladanyi@596
   166
IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
alpar@1031
   167
  ADD_SUBDIRECTORY(contrib)
ladanyi@596
   168
  ADD_SUBDIRECTORY(demo)
ladanyi@596
   169
  ADD_SUBDIRECTORY(tools)
ladanyi@596
   170
  ADD_SUBDIRECTORY(doc)
ladanyi@596
   171
  ADD_SUBDIRECTORY(test)
ladanyi@726
   172
ENDIF()
alpar@225
   173
ladanyi@722
   174
CONFIGURE_FILE(
ladanyi@722
   175
  ${PROJECT_SOURCE_DIR}/cmake/LEMONConfig.cmake.in
ladanyi@722
   176
  ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
ladanyi@722
   177
  @ONLY
ladanyi@722
   178
)
ladanyi@722
   179
IF(UNIX)
ladanyi@722
   180
  INSTALL(
ladanyi@722
   181
    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
ladanyi@722
   182
    DESTINATION share/lemon/cmake
ladanyi@722
   183
  )
ladanyi@722
   184
ELSEIF(WIN32)
ladanyi@722
   185
  INSTALL(
ladanyi@722
   186
    FILES ${PROJECT_BINARY_DIR}/cmake/LEMONConfig.cmake
ladanyi@722
   187
    DESTINATION cmake
ladanyi@722
   188
  )
ladanyi@726
   189
ENDIF()
ladanyi@722
   190
alpar@1135
   191
CONFIGURE_FILE(
alpar@1135
   192
  ${PROJECT_SOURCE_DIR}/cmake/version.cmake.in
alpar@1135
   193
  ${PROJECT_BINARY_DIR}/cmake/version.cmake
alpar@1135
   194
  @ONLY
alpar@1135
   195
)
alpar@1135
   196
alpar@1135
   197
SET(ARCHIVE_BASE_NAME ${CMAKE_PROJECT_NAME})
alpar@1135
   198
STRING(TOLOWER ${ARCHIVE_BASE_NAME} ARCHIVE_BASE_NAME)
alpar@1135
   199
SET(ARCHIVE_NAME ${ARCHIVE_BASE_NAME}-${PROJECT_VERSION})
alpar@1135
   200
ADD_CUSTOM_TARGET(dist
alpar@1135
   201
  COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
alpar@1135
   202
  COMMAND hg archive ${ARCHIVE_NAME}
alpar@1135
   203
  COMMAND cmake -E copy cmake/version.cmake ${ARCHIVE_NAME}/cmake/version.cmake
alpar@1135
   204
  COMMAND tar -czf ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_NAME}
alpar@1135
   205
  COMMAND zip -r ${ARCHIVE_BASE_NAME}-nodoc-${PROJECT_VERSION}.zip ${ARCHIVE_NAME}
alpar@1135
   206
  COMMAND cmake -E copy_directory doc/html ${ARCHIVE_NAME}/doc/html
alpar@1135
   207
  COMMAND tar -czf ${ARCHIVE_NAME}.tar.gz ${ARCHIVE_NAME}
alpar@1135
   208
  COMMAND zip -r ${ARCHIVE_NAME}.zip ${ARCHIVE_NAME}
alpar@1135
   209
  COMMAND cmake -E copy_directory doc/html ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
alpar@1135
   210
  COMMAND tar -czf ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.tar.gz ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
alpar@1135
   211
  COMMAND zip -r ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}.zip ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
alpar@1135
   212
  COMMAND cmake -E remove_directory ${ARCHIVE_NAME}
alpar@1135
   213
  COMMAND cmake -E remove_directory ${ARCHIVE_BASE_NAME}-doc-${PROJECT_VERSION}
alpar@1135
   214
  DEPENDS html
alpar@1135
   215
  WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
alpar@1135
   216
alpar@1135
   217
# CPACK config (Basically for NSIS)
alpar@1033
   218
IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
ladanyi@726
   219
  SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
ladanyi@726
   220
  SET(CPACK_PACKAGE_VENDOR "EGRES")
ladanyi@726
   221
  SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
ladanyi@726
   222
    "LEMON - Library for Efficient Modeling and Optimization in Networks")
ladanyi@726
   223
  SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
alpar@225
   224
ladanyi@726
   225
  SET(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
alpar@225
   226
ladanyi@726
   227
  SET(CPACK_PACKAGE_INSTALL_DIRECTORY
ladanyi@726
   228
    "${PROJECT_NAME} ${PROJECT_VERSION}")
ladanyi@726
   229
  SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
ladanyi@726
   230
    "${PROJECT_NAME} ${PROJECT_VERSION}")
alpar@225
   231
ladanyi@726
   232
  SET(CPACK_COMPONENTS_ALL headers library html_documentation bin)
alpar@225
   233
ladanyi@726
   234
  SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ headers")
ladanyi@726
   235
  SET(CPACK_COMPONENT_LIBRARY_DISPLAY_NAME "Dynamic-link library")
ladanyi@726
   236
  SET(CPACK_COMPONENT_BIN_DISPLAY_NAME "Command line utilities")
ladanyi@726
   237
  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DISPLAY_NAME "HTML documentation")
alpar@225
   238
ladanyi@726
   239
  SET(CPACK_COMPONENT_HEADERS_DESCRIPTION
ladanyi@726
   240
    "C++ header files")
ladanyi@726
   241
  SET(CPACK_COMPONENT_LIBRARY_DESCRIPTION
ladanyi@726
   242
    "DLL and import library")
ladanyi@726
   243
  SET(CPACK_COMPONENT_BIN_DESCRIPTION
ladanyi@726
   244
    "Command line utilities")
ladanyi@726
   245
  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_DESCRIPTION
ladanyi@726
   246
    "Doxygen generated documentation")
alpar@225
   247
ladanyi@726
   248
  SET(CPACK_COMPONENT_HEADERS_DEPENDS library)
alpar@225
   249
ladanyi@726
   250
  SET(CPACK_COMPONENT_HEADERS_GROUP "Development")
ladanyi@726
   251
  SET(CPACK_COMPONENT_LIBRARY_GROUP "Development")
ladanyi@726
   252
  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_GROUP "Documentation")
alpar@225
   253
ladanyi@726
   254
  SET(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION
ladanyi@726
   255
    "Components needed to develop software using LEMON")
ladanyi@726
   256
  SET(CPACK_COMPONENT_GROUP_DOCUMENTATION_DESCRIPTION
ladanyi@726
   257
    "Documentation of LEMON")
alpar@225
   258
ladanyi@726
   259
  SET(CPACK_ALL_INSTALL_TYPES Full Developer)
alpar@225
   260
ladanyi@726
   261
  SET(CPACK_COMPONENT_HEADERS_INSTALL_TYPES Developer Full)
ladanyi@726
   262
  SET(CPACK_COMPONENT_LIBRARY_INSTALL_TYPES Developer Full)
ladanyi@726
   263
  SET(CPACK_COMPONENT_HTML_DOCUMENTATION_INSTALL_TYPES Full)
alpar@225
   264
ladanyi@726
   265
  SET(CPACK_GENERATOR "NSIS")
ladanyi@726
   266
  SET(CPACK_NSIS_MUI_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis/lemon.ico")
ladanyi@726
   267
  SET(CPACK_NSIS_MUI_UNIICON "${PROJECT_SOURCE_DIR}/cmake/nsis/uninstall.ico")
ladanyi@726
   268
  #SET(CPACK_PACKAGE_ICON "${PROJECT_SOURCE_DIR}/cmake/nsis\\\\installer.bmp")
ladanyi@726
   269
  SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\lemon.ico")
ladanyi@726
   270
  SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}")
ladanyi@726
   271
  SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\lemon.cs.elte.hu")
ladanyi@726
   272
  SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\lemon.cs.elte.hu")
ladanyi@726
   273
  SET(CPACK_NSIS_CONTACT "lemon-user@lemon.cs.elte.hu")
ladanyi@726
   274
  SET(CPACK_NSIS_CREATE_ICONS_EXTRA "
ladanyi@726
   275
    CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Documentation.lnk\\\" \\\"$INSTDIR\\\\share\\\\doc\\\\index.html\\\"
ladanyi@726
   276
    ")
ladanyi@726
   277
  SET(CPACK_NSIS_DELETE_ICONS_EXTRA "
ladanyi@726
   278
    !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP
ladanyi@726
   279
    Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\Documentation.lnk\\\"
ladanyi@726
   280
    ")
alpar@225
   281
ladanyi@726
   282
  INCLUDE(CPack)
ladanyi@726
   283
ENDIF()