2 include(CheckCXXSourceCompiles)
4 # configure the "site" and "buildname"
7 # retrieve and store the build string
10 add_custom_target(buildtests)
11 add_custom_target(check COMMAND "ctest")
12 add_dependencies(check buildtests)
14 # check whether /bin/bash exists
15 find_file(EIGEN_BIN_BASH_EXISTS "/bin/bash" PATHS "/" NO_DEFAULT_PATH)
17 # CMake/Ctest does not allow us to change the build command,
18 # so we have to workaround by directly editing the generated DartConfiguration.tcl file
19 # save CMAKE_MAKE_PROGRAM
20 set(CMAKE_MAKE_PROGRAM_SAVE ${CMAKE_MAKE_PROGRAM})
22 set(CMAKE_MAKE_PROGRAM "@EIGEN_MAKECOMMAND_PLACEHOLDER@")
24 # This call activates testing and generates the DartConfiguration.tcl
27 set(EIGEN_TEST_BUILD_FLAGS " " CACHE STRING "Options passed to the build command of unit tests")
29 # Overwrite default DartConfiguration.tcl such that ctest can build our unit tests.
30 # Recall that our unit tests are not in the "all" target, so we have to explicitely ask ctest to build our custom 'buildtests' target.
31 # At this stage, we can also add custom flags to the build tool through the user defined EIGEN_TEST_BUILD_FLAGS variable.
32 file(READ "${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl" EIGEN_DART_CONFIG_FILE)
33 # try to grab the default flags
34 string(REGEX MATCH "MakeCommand:.*-- (.*)\nDefaultCTestConfigurationType" EIGEN_DUMMY ${EIGEN_DART_CONFIG_FILE})
36 string(REGEX MATCH "MakeCommand:.*[^c]make (.*)\nDefaultCTestConfigurationType" EIGEN_DUMMY ${EIGEN_DART_CONFIG_FILE})
38 string(REGEX REPLACE "MakeCommand:.*DefaultCTestConfigurationType" "MakeCommand: ${CMAKE_COMMAND} --build . --target buildtests --config \"\${CTEST_CONFIGURATION_TYPE}\" -- ${CMAKE_MATCH_1} ${EIGEN_TEST_BUILD_FLAGS}\nDefaultCTestConfigurationType"
39 EIGEN_DART_CONFIG_FILE2 ${EIGEN_DART_CONFIG_FILE})
40 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl" ${EIGEN_DART_CONFIG_FILE2})
42 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in ${CMAKE_BINARY_DIR}/CTestCustom.cmake)
44 # some documentation of this function would be nice
47 # configure Eigen related testing options
48 option(EIGEN_NO_ASSERTION_CHECKING "Disable checking of assertions using exceptions" OFF)
49 option(EIGEN_DEBUG_ASSERTS "Enable advanced debuging of assertions" OFF)
51 if(CMAKE_COMPILER_IS_GNUCXX)
52 option(EIGEN_COVERAGE_TESTING "Enable/disable gcov" OFF)
53 if(EIGEN_COVERAGE_TESTING)
54 set(COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage")
55 set(CTEST_CUSTOM_COVERAGE_EXCLUDE "/test/")
56 else(EIGEN_COVERAGE_TESTING)
57 set(COVERAGE_FLAGS "")
58 endif(EIGEN_COVERAGE_TESTING)
60 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
61 endif(EIGEN_TEST_C++0x)
62 if(CMAKE_SYSTEM_NAME MATCHES Linux)
63 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS} -g2")
64 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COVERAGE_FLAGS} -O2 -g2")
65 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COVERAGE_FLAGS} -fno-inline-functions")
66 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_FLAGS} -O0 -g3")
67 endif(CMAKE_SYSTEM_NAME MATCHES Linux)
69 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS")
70 endif(CMAKE_COMPILER_IS_GNUCXX)