mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-25 11:52:40 +01:00
cmake: add coverage support
This commit is contained in:
parent
ed4509fffa
commit
a9f8f27b21
@ -2,16 +2,15 @@ cmake_minimum_required(VERSION 3.2.2)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CTEST_SCRIPT_DIRECTORY}/../modules")
|
||||
|
||||
get_filename_component(SRC_DIR "${CTEST_SCRIPT_DIRECTORY}/../.." ABSOLUTE)
|
||||
get_filename_component(BIN_DIR "${SRC_DIR}/build/experimental" ABSOLUTE)
|
||||
get_filename_component(CTEST_SOURCE_DIRECTORY "${CTEST_SCRIPT_DIRECTORY}/../.." ABSOLUTE)
|
||||
get_filename_component(CTEST_BINARY_DIRECTORY "${CTEST_SOURCE_DIRECTORY}/build/experimental" ABSOLUTE)
|
||||
|
||||
set(CTEST_SOURCE_DIRECTORY "${SRC_DIR}")
|
||||
set(CTEST_BINARY_DIRECTORY "${BIN_DIR}")
|
||||
set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
|
||||
ctest_empty_binary_directory("${BIN_DIR}")
|
||||
set(CTEST_COVERAGE_COMMAND "gcov")
|
||||
|
||||
set(CMAKE_BINARY_DIR "${BIN_DIR}")
|
||||
set(CMAKE_CURRENT_BINARY_DIR "${BIN_DIR}")
|
||||
if(EXISTS "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt")
|
||||
ctest_empty_binary_directory("${CTEST_BINARY_DIRECTORY}")
|
||||
endif()
|
||||
|
||||
include(GetGitRevisionDescription)
|
||||
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
|
||||
@ -23,12 +22,12 @@ set(CTEST_BUILD_NAME "experimental_script-${SHORT_COMMIT}")
|
||||
ctest_start("Experimental")
|
||||
ctest_configure(
|
||||
OPTIONS
|
||||
"-DBUILD_VIEWER=1;-DBUILD_TESTS=1"
|
||||
"-DBUILD_VIEWER=1;-DBUILD_TESTS=1;-DTEST_COVERAGE=1;-DRW_VERBOSE_DEBUG_MESSAGES=0"
|
||||
)
|
||||
ctest_build()
|
||||
ctest_test(
|
||||
RETURN_VALUE TEST_RESULT
|
||||
)
|
||||
ctest_test()
|
||||
ctest_coverage()
|
||||
ctest_coverage()
|
||||
ctest_submit(
|
||||
RETURN_VALUE SUBMIT_RESULT
|
||||
)
|
||||
@ -39,5 +38,5 @@ message("Build Name: ${CTEST_BUILD_NAME}")
|
||||
if(NOT SUBMIT_RESULT EQUAL "0")
|
||||
message("Uploading results failed.")
|
||||
message("Execute the next command to submit later.")
|
||||
message("make -C \"CTEST_BINARY_DIRECTORY\" ExperimentalSubmit")
|
||||
message("make -C \"${CTEST_BINARY_DIRECTORY}\" ExperimentalSubmit")
|
||||
endif()
|
||||
|
@ -68,3 +68,25 @@ elseif(FAILED_CHECK_ACTION STREQUAL "BREAKPOINT")
|
||||
else()
|
||||
message(FATAL_ERROR "Illegal FAILED_CHECK_ACTION option. (was '${FAILED_CHECK_ACTION}')")
|
||||
endif()
|
||||
|
||||
if(TEST_COVERAGE)
|
||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
message("Test Coverage enabled. Setting CMAKE_BUILD_TYPE to Debug.")
|
||||
set(CMAKE_BUILD_TYPE "Debug")
|
||||
endif()
|
||||
if(NOT BUILD_TESTS)
|
||||
message("TestCoverage enabled. Enabling BUILD_TESTS.")
|
||||
set(BUILD_TESTS "ON")
|
||||
endif()
|
||||
target_compile_options(rw_interface
|
||||
INTERFACE
|
||||
"-O0"
|
||||
"-fprofile-arcs"
|
||||
"-ftest-coverage"
|
||||
)
|
||||
set_target_properties(rw_interface
|
||||
PROPERTIES
|
||||
INTERFACE_LINK_LIBRARIES
|
||||
gcov
|
||||
)
|
||||
endif()
|
||||
|
@ -15,5 +15,7 @@ set(BIN_DIR "bin" CACHE STRING "Prefix subdirectory to put the binaries in.")
|
||||
set(DOC_DIR "share/doc/openrw" CACHE STRING "Prefix subdirectory to put the documentation in.")
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release" FORCE)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release")
|
||||
endif()
|
||||
|
||||
option(TEST_COVERAGE "Enable coverage analysis (implies CMAKE_BUILD_TYPE=Debug)")
|
||||
|
@ -77,4 +77,6 @@ target_link_libraries(run_tests
|
||||
${Boost_SYSTEM_LIBRARY}
|
||||
)
|
||||
|
||||
add_test(UnitTests run_tests)
|
||||
add_test(NAME UnitTests
|
||||
COMMAND "$<TARGET_FILE:run_tests>"
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user