From c8bd3e541524d42e5b9860f3622e3ecf02aa808d Mon Sep 17 00:00:00 2001 From: Martin Killenberg <martin.killenberg@desy.de> Date: Thu, 3 Nov 2016 09:53:39 +0100 Subject: [PATCH] added script to enable coverage report --- cmake/enable_code_coverage_report.cmake | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 cmake/enable_code_coverage_report.cmake diff --git a/cmake/enable_code_coverage_report.cmake b/cmake/enable_code_coverage_report.cmake new file mode 100644 index 0000000..44c270d --- /dev/null +++ b/cmake/enable_code_coverage_report.cmake @@ -0,0 +1,40 @@ +####################################################################################################################### +# enable_code_coverage_report.cmake +# +# Enable possibility to generate a code coverage report when compiling in 'Debug' mode. +# Configure with the option -DCMAKE_BUILD_TYPE=Debug. +# It require working tests which can be called with 'make test'. The coverage is created +# over these tests. +# +# You need lcov installed to use the 'make coverage' command. +# +# This script appends to the variable CMAKE_CXX_FLAGS_DEBUG, +# and adds the target 'coverage', only available in 'Debug' mode. +# +####################################################################################################################### + +####################################################################################################################### +# +# 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. +# +####################################################################################################################### + +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 --coverage") + +#The make coverage command is only available in debug mode +IF(CMAKE_BUILD_TYPE STREQUAL "Debug") + configure_file(cmake/make_coverage.sh.in + ${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 + ) +ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") + -- GitLab