Commit dfed068a authored by GUENNEBAUD Gael's avatar GUENNEBAUD Gael

Use ctest for the unit tests

parent 2dbebe56
project(Patate)
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 2.8)
# guard against in-source builds (source: Eigen)
......@@ -21,7 +21,6 @@ if( NOT cmake_build_type_tolower STREQUAL "debug"
message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Release, RelWithDebInfo (case-insensitive).")
endif()
################################################################################
# add a target to generate API documentation with Doxygen #
################################################################################
......@@ -36,10 +35,14 @@ if(DOXYGEN_FOUND)
)
endif(DOXYGEN_FOUND)
################################################################################
# tests and examples #
################################################################################
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
add_subdirectory(examples EXCLUDE_FROM_ALL)
include(cmake/ConfigureTesting.cmake)
add_subdirectory(tests EXCLUDE_FROM_ALL)
## This file should be placed in the root directory of your project.
## Then modify the CMakeLists.txt file in the root directory of your
## project to incorporate the testing dashboard.
## # The following are required to uses Dart and the Cdash dashboard
## ENABLE_TESTING()
## INCLUDE(CTest)
set(CTEST_PROJECT_NAME "Patate")
set(CTEST_NIGHTLY_START_TIME "00:00:00 UTC")
set(CTEST_DROP_METHOD "http")
set(CTEST_DROP_SITE "manao.inria.fr")
set(CTEST_DROP_LOCATION "/CDash/submit.php?project=Patate")
set(CTEST_DROP_SITE_CDASH TRUE)
add_custom_target(buildtests)
add_custom_target(check COMMAND "ctest")
add_dependencies(check buildtests)
# check whether /bin/bash exists
find_file(PATATE_BIN_BASH_EXISTS "/bin/bash" PATHS "/" NO_DEFAULT_PATH)
# CMake/Ctest does not allow us to change the build command,
# so we have to workaround by directly editing the generated DartConfiguration.tcl file
# save CMAKE_MAKE_PROGRAM
set(CMAKE_MAKE_PROGRAM_SAVE ${CMAKE_MAKE_PROGRAM})
# and set a fake one
set(CMAKE_MAKE_PROGRAM "@PATATE_MAKECOMMAND_PLACEHOLDER@")
# This call activates testing and generates the DartConfiguration.tcl
# This adds another build target, which is test for Makefile generators,
# or RUN_TESTS for integrated development environments (like Visual Studio)
include(CTest)
set(PATATE_TEST_BUILD_FLAGS "" CACHE STRING "Options passed to the build command of unit tests")
# overwrite default DartConfiguration.tcl
# The worarounds are different for each version of the MSVC IDE
set(PATATE_TEST_TARGET buildtests)
if(MSVC_IDE)
if(CMAKE_MAKE_PROGRAM_SAVE MATCHES "devenv") # devenv
set(PATATE_BUILD_COMMAND "${CMAKE_MAKE_PROGRAM_SAVE} Patate.sln /build Release /project ${PATATE_TEST_TARGET}")
else() # msbuild
set(PATATE_BUILD_COMMAND "${CMAKE_MAKE_PROGRAM_SAVE} ${PATATE_TEST_TARGET}.vcxproj /p:Configuration=\${CTEST_CONFIGURATION_TYPE}")
endif()
# append the build flags if provided
if(NOT "${PATATE_TEST_BUILD_FLAGS}" MATCHES "^[ \t]*$")
set(PATATE_BUILD_COMMAND "${PATATE_BUILD_COMMAND} ${PATATE_TEST_BUILD_FLAGS}")
endif()
# apply the dartconfig hack ...
set(PATATE_MAKECOMMAND_PLACEHOLDER "${PATATE_BUILD_COMMAND}\n#")
else()
# for make and nmake
set(PATATE_BUILD_COMMAND "${CMAKE_MAKE_PROGRAM_SAVE} ${PATATE_TEST_TARGET} ${PATATE_TEST_BUILD_FLAGS}")
set(PATATE_MAKECOMMAND_PLACEHOLDER "${PATATE_BUILD_COMMAND}")
endif()
configure_file(${CMAKE_BINARY_DIR}/DartConfiguration.tcl ${CMAKE_BINARY_DIR}/DartConfiguration.tcl)
# restore default CMAKE_MAKE_PROGRAM
set(CMAKE_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM_SAVE})
# un-set temporary variables so that it is like they never existed
unset(CMAKE_MAKE_PROGRAM_SAVE)
unset(PATATE_MAKECOMMAND_PLACEHOLDER)
# Configure coverage
if(CMAKE_COMPILER_IS_GNUCXX)
option(PATATE_COVERAGE_TESTING "Enable/disable gcov" ON)
if(PATATE_COVERAGE_TESTING)
set(COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage")
else(PATATE_COVERAGE_TESTING)
set(COVERAGE_FLAGS "")
endif(PATATE_COVERAGE_TESTING)
if(PATATE_TEST_C++0x)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
endif(PATATE_TEST_C++0x)
if(CMAKE_SYSTEM_NAME MATCHES Linux)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS} -g2")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COVERAGE_FLAGS} -O2 -g2")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COVERAGE_FLAGS} -fno-inline-functions")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_FLAGS} -O0 -g3")
endif(CMAKE_SYSTEM_NAME MATCHES Linux)
elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS")
endif(CMAKE_COMPILER_IS_GNUCXX)
......@@ -8,4 +8,6 @@ set(deta_orthogonal_derivatives_SRCS
deta_orthogonal_derivatives.cpp
)
add_executable(deta_orthogonal_derivatives ${deta_orthogonal_derivatives_SRCS})
add_dependencies(tests deta_orthogonal_derivatives)
add_dependencies(buildtests deta_orthogonal_derivatives)
add_test(deta_orthogonal_derivatives deta_orthogonal_derivatives)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment