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 # This call activates testing and generates the DartConfiguration.tcl
20 set(EIGEN_TEST_BUILD_FLAGS "" CACHE STRING "Options passed to the build command of unit tests")
22 # Overwrite default DartConfiguration.tcl such that ctest can build our unit tests.
23 # Recall that our unit tests are not in the "all" target, so we have to explicitely ask ctest to build our custom 'buildtests' target.
24 # At this stage, we can also add custom flags to the build tool through the user defined EIGEN_TEST_BUILD_FLAGS variable.
25 file(READ "${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl" EIGEN_DART_CONFIG_FILE)
26 # try to grab the default flags
27 string(REGEX MATCH "MakeCommand:.*-- (.*)\nDefaultCTestConfigurationType" EIGEN_DUMMY ${EIGEN_DART_CONFIG_FILE})
29 string(REGEX MATCH "MakeCommand:.*[^c]make (.*)\nDefaultCTestConfigurationType" EIGEN_DUMMY ${EIGEN_DART_CONFIG_FILE})
31 string(REGEX REPLACE "MakeCommand:.*DefaultCTestConfigurationType" "MakeCommand: ${CMAKE_COMMAND} --build . --target buildtests --config \"\${CTEST_CONFIGURATION_TYPE}\" -- ${CMAKE_MATCH_1} ${EIGEN_TEST_BUILD_FLAGS}\nDefaultCTestConfigurationType"
32 EIGEN_DART_CONFIG_FILE2 ${EIGEN_DART_CONFIG_FILE})
33 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl" ${EIGEN_DART_CONFIG_FILE2})
35 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in ${CMAKE_BINARY_DIR}/CTestCustom.cmake)
37 # some documentation of this function would be nice
40 # configure Eigen related testing options
41 option(EIGEN_NO_ASSERTION_CHECKING "Disable checking of assertions using exceptions" OFF)
42 option(EIGEN_DEBUG_ASSERTS "Enable advanced debuging of assertions" OFF)
44 if(CMAKE_COMPILER_IS_GNUCXX)
45 option(EIGEN_COVERAGE_TESTING "Enable/disable gcov" OFF)
46 if(EIGEN_COVERAGE_TESTING)
47 set(COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage")
48 set(CTEST_CUSTOM_COVERAGE_EXCLUDE "/test/")
49 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS}")
50 endif(EIGEN_COVERAGE_TESTING)
53 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS")
54 endif(CMAKE_COMPILER_IS_GNUCXX)
57 check_cxx_compiler_flag("-std=c++11" EIGEN_COMPILER_SUPPORT_CXX11)
59 if(EIGEN_TEST_CXX11 AND EIGEN_COMPILER_SUPPORT_CXX11)
60 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")