You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.7 KiB

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