1include(EigenTesting) 2include(CheckCXXSourceCompiles) 3 4# configure the "site" and "buildname" 5ei_set_sitename() 6 7# retrieve and store the build string 8ei_set_build_string() 9 10add_custom_target(buildtests) 11add_custom_target(check COMMAND "ctest") 12add_dependencies(check buildtests) 13 14# check whether /bin/bash exists 15find_file(EIGEN_BIN_BASH_EXISTS "/bin/bash" PATHS "/" NO_DEFAULT_PATH) 16 17# This call activates testing and generates the DartConfiguration.tcl 18include(CTest) 19 20set(EIGEN_TEST_BUILD_FLAGS "" CACHE STRING "Options passed to the build command of unit tests") 21 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. 25file(READ "${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl" EIGEN_DART_CONFIG_FILE) 26# try to grab the default flags 27string(REGEX MATCH "MakeCommand:.*-- (.*)\nDefaultCTestConfigurationType" EIGEN_DUMMY ${EIGEN_DART_CONFIG_FILE}) 28if(NOT CMAKE_MATCH_1) 29string(REGEX MATCH "MakeCommand:.*[^c]make (.*)\nDefaultCTestConfigurationType" EIGEN_DUMMY ${EIGEN_DART_CONFIG_FILE}) 30endif() 31string(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}) 33file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl" ${EIGEN_DART_CONFIG_FILE2}) 34 35configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in ${CMAKE_BINARY_DIR}/CTestCustom.cmake) 36 37# some documentation of this function would be nice 38ei_init_testing() 39 40# configure Eigen related testing options 41option(EIGEN_NO_ASSERTION_CHECKING "Disable checking of assertions using exceptions" OFF) 42option(EIGEN_DEBUG_ASSERTS "Enable advanced debuging of assertions" OFF) 43 44if(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 else(EIGEN_COVERAGE_TESTING) 50 set(COVERAGE_FLAGS "") 51 endif(EIGEN_COVERAGE_TESTING) 52 if(EIGEN_TEST_C++0x) 53 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x") 54 endif(EIGEN_TEST_C++0x) 55 if(CMAKE_SYSTEM_NAME MATCHES Linux) 56 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS} -g2") 57 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COVERAGE_FLAGS} -O2 -g2") 58 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COVERAGE_FLAGS} -fno-inline-functions") 59 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_FLAGS} -O0 -g3") 60 endif(CMAKE_SYSTEM_NAME MATCHES Linux) 61elseif(MSVC) 62 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS") 63endif(CMAKE_COMPILER_IS_GNUCXX) 64