Commit 5b15810e authored by Jens Georg's avatar Jens Georg
Browse files

Consolidate coverage options

 - Remove Makefile.coverage.in
 - Drop BUILD_COVERAGE_ON_DEBUG for ENABLE_COVERAGE_REPORT (defaults to
    on if included)
 - Add clean-gcda target
parent 32b422c3
#######################################################################################################################
#
# Additional make target for generating a code coverage report.
#
# ATTENTION: This file has bee deprecated in project-template and will no longer be maintained.
# DO NOT MODIFY THIS FILE IN THE PROJECT TEMPLATE!
# Use make_coverage.sh.in instead!
#
#######################################################################################################################
#######################################################################################################################
#
# IMPORTANT NOTE:
#
# DO NOT MODIFY THIS FILE inside a project. Instead update the project-template repository and pull the change from
# there. Make sure to keep the file generic, since it will be used by other projects, too.
#
# If you have modified this file inside a project despite this warning, make sure to cherry-pick all your changes
# into the project-template repository immediately.
#
#######################################################################################################################
coverage:
echo ATTENTION: Using Makefile.coverage.in in your CMake project is deprecated. Please change to make_coverage.sh.in
rm -f `find . -name "*\.gcda"`
make test
lcov --capture --directory . --output-file coverage_all.info
#lcov capture also includes external stuff like glibc, boost etc.
#only extract the reports for this project
lcov --extract coverage_all.info "@CMAKE_SOURCE_DIR@*" -o coverage_incl_build.info
#Some projects install the library and its headers for testing in the build directory
#and compile tests and examples against it. This leads to double
#counting and untested lines in the coverage report. That's why we
#exclude the build directory from the coverage report (needed if the
#build directory is in the source tree).
#Attention: If you make an 'in sorce build' the coverage report will
#be empty!
lcov --remove coverage_incl_build.info "@PROJECT_BINARY_DIR@/*" -o coverage.info
genhtml coverage.info --output-directory coverage_html
echo ATTENTION: Using Makefile.coverage.in in your CMake project is deprecated. Please change to make_coverage.sh.in
......@@ -25,16 +25,24 @@
#
#######################################################################################################################
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 --coverage")
# The make coverage command is only available in debug mode. Also
# factor in that cmake treats CMAKE_BUILD_TYPE string as case
# insensitive.
option(ENABLE_COVERAGE_REPORT "Create coverage target to generate code coverage reports" ON)
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type_uppercase)
IF(build_type_uppercase STREQUAL "DEBUG")
IF(build_type_uppercase STREQUAL "DEBUG" AND ENABLE_COVERAGE_REPORT)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} --coverage")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} --coverage")
configure_file(cmake/make_coverage.sh.in
${PROJECT_BINARY_DIR}/make_coverage.sh @ONLY)
${PROJECT_BINARY_DIR}/make_coverage.sh @ONLY)
add_custom_target(coverage
./make_coverage.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating test coverage documentation" VERBATIM)
./make_coverage.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating test coverage documentation" VERBATIM)
add_custom_target(clean-gcda
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND find -name "*.gcda" -exec rm {} \;
COMMENT "Removing old coverage files" VERBATIM)
ENDIF()
......@@ -23,7 +23,7 @@
#
#######################################################################################################################
rm -f `find . -name "*\.gcda"`
cmake --build . --target clean-gcda
cmake --build . --target test
lcov --capture --directory . --output-file coverage_all.info --ignore-errors gcov
......
......@@ -23,25 +23,17 @@
include(cmake/enable_latest_cxx_support.cmake)
option(BUILD_COVERAGE_ON_DEBUG "Generate coverage information when compiling in debug mode" ON)
if (BUILD_COVERAGE_ON_DEBUG)
set(CTK_COVERAGE_FLAGS "--coverage")
else()
set(CTK_COVERAGE_FLAGS "")
endif()
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;asan;tsan")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${${PROJECT_NAME}_CXX_FLAGS} -Wall -Wextra -Wshadow -pedantic -Wuninitialized")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O3 -g")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 ${CTK_COVERAGE_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
set(CMAKE_CXX_FLAGS_TSAN "${CMAKE_CXX_FLAGS} -g -O1 -fsanitize=thread")
set(CMAKE_CXX_FLAGS_ASAN "${CMAKE_CXX_FLAGS} -g -O0 -fsanitize=address -fsanitize=undefined -fsanitize=leak")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${${PROJECT_NAME}_C_FLAGS} -Wall -Wextra -Wshadow -pedantic -Wuninitialized")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O3 -g")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0 ${CTK_COVERAGE_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0")
set(CMAKE_C_FLAGS_TSAN "${CMAKE_C_FLAGS} -g -O1 -fsanitize=thread")
set(CMAKE_C_FLAGS_ASAN "${CMAKE_C_FLAGS} -g -O0 -fsanitize=address -fsanitize=undefined -fsanitize=leak")
Supports Markdown
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