Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 1 | include(EigenTesting) |
| 2 | include(CheckCXXSourceCompiles) |
| 3 | |
| 4 | # configure the "site" and "buildname" |
| 5 | ei_set_sitename() |
| 6 | |
| 7 | # retrieve and store the build string |
| 8 | ei_set_build_string() |
| 9 | |
| 10 | add_custom_target(buildtests) |
| 11 | add_custom_target(check COMMAND "ctest") |
| 12 | add_dependencies(check buildtests) |
| 13 | |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame^] | 14 | # check whether /bin/bash exists (disabled as not used anymore) |
| 15 | # find_file(EIGEN_BIN_BASH_EXISTS "/bin/bash" PATHS "/" NO_DEFAULT_PATH) |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 16 | |
| 17 | # This call activates testing and generates the DartConfiguration.tcl |
| 18 | include(CTest) |
| 19 | |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame^] | 20 | set(EIGEN_TEST_BUILD_FLAGS "" CACHE STRING "Options passed to the build command of unit tests") |
| 21 | set(EIGEN_DASHBOARD_BUILD_TARGET "buildtests" CACHE STRING "Target to be built in dashboard mode, default is buildtests") |
| 22 | set(EIGEN_CTEST_ERROR_EXCEPTION "" CACHE STRING "Regular expression for build error messages to be filtered out") |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 23 | |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame^] | 24 | # Overwrite default DartConfiguration.tcl such that ctest can build our unit tests. |
| 25 | # Recall that our unit tests are not in the "all" target, so we have to explicitely ask ctest to build our custom 'buildtests' target. |
| 26 | # At this stage, we can also add custom flags to the build tool through the user defined EIGEN_TEST_BUILD_FLAGS variable. |
| 27 | file(READ "${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl" EIGEN_DART_CONFIG_FILE) |
| 28 | # try to grab the default flags |
| 29 | string(REGEX MATCH "MakeCommand:.*-- (.*)\nDefaultCTestConfigurationType" EIGEN_DUMMY ${EIGEN_DART_CONFIG_FILE}) |
| 30 | if(NOT CMAKE_MATCH_1) |
| 31 | string(REGEX MATCH "MakeCommand:.*[^c]make (.*)\nDefaultCTestConfigurationType" EIGEN_DUMMY ${EIGEN_DART_CONFIG_FILE}) |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 32 | endif() |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame^] | 33 | string(REGEX REPLACE "MakeCommand:.*DefaultCTestConfigurationType" "MakeCommand: ${CMAKE_COMMAND} --build . --target ${EIGEN_DASHBOARD_BUILD_TARGET} --config \"\${CTEST_CONFIGURATION_TYPE}\" -- ${CMAKE_MATCH_1} ${EIGEN_TEST_BUILD_FLAGS}\nDefaultCTestConfigurationType" |
| 34 | EIGEN_DART_CONFIG_FILE2 ${EIGEN_DART_CONFIG_FILE}) |
| 35 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl" ${EIGEN_DART_CONFIG_FILE2}) |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 36 | |
| 37 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in ${CMAKE_BINARY_DIR}/CTestCustom.cmake) |
| 38 | |
| 39 | # some documentation of this function would be nice |
| 40 | ei_init_testing() |
| 41 | |
| 42 | # configure Eigen related testing options |
| 43 | option(EIGEN_NO_ASSERTION_CHECKING "Disable checking of assertions using exceptions" OFF) |
| 44 | option(EIGEN_DEBUG_ASSERTS "Enable advanced debuging of assertions" OFF) |
| 45 | |
| 46 | if(CMAKE_COMPILER_IS_GNUCXX) |
| 47 | option(EIGEN_COVERAGE_TESTING "Enable/disable gcov" OFF) |
| 48 | if(EIGEN_COVERAGE_TESTING) |
| 49 | set(COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage") |
| 50 | set(CTEST_CUSTOM_COVERAGE_EXCLUDE "/test/") |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame^] | 51 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS}") |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 52 | endif(EIGEN_COVERAGE_TESTING) |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame^] | 53 | |
Brian Silverman | 72890c2 | 2015-09-19 14:37:37 -0400 | [diff] [blame] | 54 | elseif(MSVC) |
| 55 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS") |
| 56 | endif(CMAKE_COMPILER_IS_GNUCXX) |
Austin Schuh | 189376f | 2018-12-20 22:11:15 +1100 | [diff] [blame^] | 57 | |
| 58 | |