Home | History | Annotate | Download | only in cmake
      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 
     14 # check whether /bin/bash exists
     15 find_file(EIGEN_BIN_BASH_EXISTS "/bin/bash" PATHS "/" NO_DEFAULT_PATH)
     16 
     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})
     21 # and set a fake one
     22 set(CMAKE_MAKE_PROGRAM "@EIGEN_MAKECOMMAND_PLACEHOLDER@")
     23 
     24 # This call activates testing and generates the DartConfiguration.tcl
     25 include(CTest)
     26 
     27 set(EIGEN_TEST_BUILD_FLAGS " " CACHE STRING "Options passed to the build command of unit tests")
     28 
     29 # overwrite default DartConfiguration.tcl
     30 # The worarounds are different for each version of the MSVC IDE
     31 if(MSVC_IDE)
     32   if(CMAKE_MAKE_PROGRAM_SAVE MATCHES "devenv") # devenv
     33     set(EIGEN_MAKECOMMAND_PLACEHOLDER "${CMAKE_MAKE_PROGRAM_SAVE} Eigen.sln /build \"Release\" /project buildtests ${EIGEN_TEST_BUILD_FLAGS} \n# ")    
     34   else() # msbuild
     35     set(EIGEN_MAKECOMMAND_PLACEHOLDER "${CMAKE_MAKE_PROGRAM_SAVE} buildtests.vcxproj /p:Configuration=\${CTEST_CONFIGURATION_TYPE}  ${EIGEN_TEST_BUILD_FLAGS}\n# ")
     36   endif()
     37 else()
     38   # for make and nmake
     39   set(EIGEN_MAKECOMMAND_PLACEHOLDER "${CMAKE_MAKE_PROGRAM_SAVE} buildtests ${EIGEN_TEST_BUILD_FLAGS}")
     40 endif()
     41 
     42 # copy ctest properties, which currently
     43 # o raise the warning levels
     44 configure_file(${CMAKE_CURRENT_BINARY_DIR}/DartConfiguration.tcl ${CMAKE_BINARY_DIR}/DartConfiguration.tcl)
     45 
     46 # restore default CMAKE_MAKE_PROGRAM
     47 set(CMAKE_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM_SAVE})
     48 # un-set temporary variables so that it is like they never existed. 
     49 # CMake 2.6.3 introduces the more logical unset() syntax for this.
     50 set(CMAKE_MAKE_PROGRAM_SAVE) 
     51 set(EIGEN_MAKECOMMAND_PLACEHOLDER)
     52 
     53 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in ${CMAKE_BINARY_DIR}/CTestCustom.cmake)
     54 
     55 # some documentation of this function would be nice
     56 ei_init_testing()
     57 
     58 # configure Eigen related testing options
     59 option(EIGEN_NO_ASSERTION_CHECKING "Disable checking of assertions using exceptions" OFF)
     60 option(EIGEN_DEBUG_ASSERTS "Enable advanced debuging of assertions" OFF)
     61 
     62 if(CMAKE_COMPILER_IS_GNUCXX)
     63   option(EIGEN_COVERAGE_TESTING "Enable/disable gcov" OFF)
     64   if(EIGEN_COVERAGE_TESTING)
     65     set(COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage")
     66     set(CTEST_CUSTOM_COVERAGE_EXCLUDE "/test/")
     67   else(EIGEN_COVERAGE_TESTING)
     68     set(COVERAGE_FLAGS "")
     69   endif(EIGEN_COVERAGE_TESTING)
     70   if(EIGEN_TEST_C++0x)
     71     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
     72   endif(EIGEN_TEST_C++0x)
     73   if(CMAKE_SYSTEM_NAME MATCHES Linux)
     74     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS} -g2")
     75     set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COVERAGE_FLAGS} -O2 -g2")
     76     set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COVERAGE_FLAGS} -fno-inline-functions")
     77     set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_FLAGS} -O0 -g3")
     78   endif(CMAKE_SYSTEM_NAME MATCHES Linux)
     79 elseif(MSVC)
     80   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS")
     81 endif(CMAKE_COMPILER_IS_GNUCXX)
     82