Merge CMAKE config improvements (#388, #389, #390)
authorAlpar Juttner <alpar@cs.elte.hu>
Sun, 12 Sep 2010 07:02:51 +0200
changeset 9983ffd46dc8e01
parent 991 fb932bcfd803
parent 997 a725503acfe9
child 1000 de428ebb47ab
Merge CMAKE config improvements (#388, #389, #390)
     1.1 --- a/CMakeLists.txt	Sat Sep 04 23:58:03 2010 +0200
     1.2 +++ b/CMakeLists.txt	Sun Sep 12 07:02:51 2010 +0200
     1.3 @@ -3,12 +3,21 @@
     1.4  SET(PROJECT_NAME "LEMON")
     1.5  PROJECT(${PROJECT_NAME})
     1.6  
     1.7 +INCLUDE(FindPythonInterp)
     1.8 +
     1.9  IF(EXISTS ${PROJECT_SOURCE_DIR}/cmake/version.cmake)
    1.10    INCLUDE(${PROJECT_SOURCE_DIR}/cmake/version.cmake)
    1.11  ELSEIF(DEFINED ENV{LEMON_VERSION})
    1.12    SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.")
    1.13  ELSE()
    1.14    EXECUTE_PROCESS(
    1.15 +    COMMAND ${PYTHON_EXECUTABLE} ./scripts/chg-len.py
    1.16 +    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
    1.17 +    OUTPUT_VARIABLE HG_REVISION_PATH
    1.18 +    ERROR_QUIET
    1.19 +    OUTPUT_STRIP_TRAILING_WHITESPACE
    1.20 +  )
    1.21 +  EXECUTE_PROCESS(
    1.22      COMMAND hg id -i
    1.23      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
    1.24      OUTPUT_VARIABLE HG_REVISION
    1.25 @@ -16,9 +25,15 @@
    1.26      OUTPUT_STRIP_TRAILING_WHITESPACE
    1.27    )
    1.28    IF(HG_REVISION STREQUAL "")
    1.29 -    SET(HG_REVISION "hg-tip")
    1.30 +    SET(HG_REVISION_ID "hg-tip")
    1.31 +  ELSE()
    1.32 +    IF(HG_REVISION_PATH STREQUAL "")
    1.33 +      SET(HG_REVISION_ID ${HG_REVISION})
    1.34 +    ELSE()
    1.35 +      SET(HG_REVISION_ID ${HG_REVISION_PATH}.${HG_REVISION})
    1.36 +    ENDIF()
    1.37    ENDIF()
    1.38 -  SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.")
    1.39 +  SET(LEMON_VERSION ${HG_REVISION_ID} CACHE STRING "LEMON version string.")
    1.40  ENDIF()
    1.41  
    1.42  SET(PROJECT_VERSION ${LEMON_VERSION})
    1.43 @@ -31,13 +46,80 @@
    1.44  FIND_PACKAGE(CPLEX)
    1.45  FIND_PACKAGE(COIN)
    1.46  
    1.47 +IF(DEFINED ENV{LEMON_CXX_WARNING})
    1.48 +  SET(CXX_WARNING $ENV{LEMON_CXX_WARNING})
    1.49 +ELSE()
    1.50 +  IF(CMAKE_COMPILER_IS_GNUCXX)
    1.51 +    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 -ansi -fno-strict-aliasing -Wold-style-cast -Wno-unknown-pragmas")
    1.52 +    SET(CMAKE_CXX_FLAGS_DEBUG CACHE STRING "-ggdb")
    1.53 +    SET(CMAKE_C_FLAGS_DEBUG CACHE STRING "-ggdb")
    1.54 +  ELSEIF(MSVC)
    1.55 +    # This part is unnecessary 'casue the same is set by the lemon/core.h.
    1.56 +    # Still keep it as an example.
    1.57 +    SET(CXX_WARNING "/wd4250 /wd4355 /wd4503 /wd4800 /wd4996")
    1.58 +    # Suppressed warnings:
    1.59 +    # C4250: 'class1' : inherits 'class2::member' via dominance
    1.60 +    # C4355: 'this' : used in base member initializer list
    1.61 +    # C4503: 'function' : decorated name length exceeded, name was truncated
    1.62 +    # C4800: 'type' : forcing value to bool 'true' or 'false'
    1.63 +    #        (performance warning)
    1.64 +    # C4996: 'function': was declared deprecated
    1.65 +  ELSE()
    1.66 +    SET(CXX_WARNING "-Wall -W")
    1.67 +  ENDIF()
    1.68 +ENDIF()
    1.69 +SET(LEMON_CXX_WARNING_FLAGS ${CXX_WARNING} CACHE STRING "LEMON warning flags.")
    1.70 +
    1.71 +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LEMON_CXX_WARNING_FLAGS}")
    1.72 +
    1.73 +SET( CMAKE_CXX_FLAGS_MAINTAINER "-Werror -ggdb" CACHE STRING
    1.74 +    "Flags used by the C++ compiler during maintainer builds."
    1.75 +    FORCE )
    1.76 +SET( CMAKE_C_FLAGS_MAINTAINER "-Werror" CACHE STRING
    1.77 +    "Flags used by the C compiler during maintainer builds."
    1.78 +    FORCE )
    1.79 +SET( CMAKE_EXE_LINKER_FLAGS_MAINTAINER
    1.80 +    "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
    1.81 +    "Flags used for linking binaries during maintainer builds."
    1.82 +    FORCE )
    1.83 +SET( CMAKE_SHARED_LINKER_FLAGS_MAINTAINER
    1.84 +    "-Wl,--warn-unresolved-symbols,--warn-once" CACHE STRING
    1.85 +    "Flags used by the shared libraries linker during maintainer builds."
    1.86 +    FORCE )
    1.87 +MARK_AS_ADVANCED(
    1.88 +    CMAKE_CXX_FLAGS_MAINTAINER
    1.89 +    CMAKE_C_FLAGS_MAINTAINER
    1.90 +    CMAKE_EXE_LINKER_FLAGS_MAINTAINER
    1.91 +    CMAKE_SHARED_LINKER_FLAGS_MAINTAINER )
    1.92 +
    1.93 +IF(CMAKE_CONFIGURATION_TYPES)
    1.94 +  LIST(APPEND CMAKE_CONFIGURATION_TYPES Maintainer)
    1.95 +  LIST(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
    1.96 +  SET(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
    1.97 +      "Add the configurations that we need"
    1.98 +      FORCE)
    1.99 + endif()
   1.100 +
   1.101 +IF(NOT CMAKE_BUILD_TYPE)
   1.102 +  SET(CMAKE_BUILD_TYPE "Release")
   1.103 +ENDIF()
   1.104 +
   1.105 +SET( CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
   1.106 +    "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel Maintainer."
   1.107 +    FORCE )
   1.108 +
   1.109 +
   1.110  INCLUDE(CheckTypeSize)
   1.111  CHECK_TYPE_SIZE("long long" LONG_LONG)
   1.112  SET(LEMON_HAVE_LONG_LONG ${HAVE_LONG_LONG})
   1.113  
   1.114 -INCLUDE(FindPythonInterp)
   1.115 +ENABLE_TESTING()
   1.116  
   1.117 -ENABLE_TESTING()
   1.118 +IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer")
   1.119 +  ADD_CUSTOM_TARGET(check ALL COMMAND ${CMAKE_CTEST_COMMAND})
   1.120 +ELSE()
   1.121 +  ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
   1.122 +ENDIF()
   1.123  
   1.124  ADD_SUBDIRECTORY(lemon)
   1.125  IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
   1.126 @@ -64,7 +146,7 @@
   1.127    )
   1.128  ENDIF()
   1.129  
   1.130 -IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR} AND WIN32)
   1.131 +IF(${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
   1.132    SET(CPACK_PACKAGE_NAME ${PROJECT_NAME})
   1.133    SET(CPACK_PACKAGE_VENDOR "EGRES")
   1.134    SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
     2.1 --- a/test/CMakeLists.txt	Sat Sep 04 23:58:03 2010 +0200
     2.2 +++ b/test/CMakeLists.txt	Sun Sep 12 07:02:51 2010 +0200
     2.3 @@ -117,7 +117,12 @@
     2.4  ENDIF()
     2.5  
     2.6  FOREACH(TEST_NAME ${TESTS})
     2.7 -  ADD_EXECUTABLE(${TEST_NAME} ${TEST_NAME}.cc)
     2.8 +  IF(${CMAKE_BUILD_TYPE} STREQUAL "Maintainer")
     2.9 +    ADD_EXECUTABLE(${TEST_NAME} ${TEST_NAME}.cc)
    2.10 +  ELSE()
    2.11 +    ADD_EXECUTABLE(${TEST_NAME} EXCLUDE_FROM_ALL ${TEST_NAME}.cc)
    2.12 +  ENDIF()
    2.13    TARGET_LINK_LIBRARIES(${TEST_NAME} lemon)
    2.14    ADD_TEST(${TEST_NAME} ${TEST_NAME})
    2.15 +  ADD_DEPENDENCIES(check ${TEST_NAME})
    2.16  ENDFOREACH()