1
if (CMAKE_BUILD_TYPE MATCHES coverage)
2
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
3
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
4
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage")
5
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
7
find_program(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin")
8
if (NOT GCOVR_EXECUTABLE)
9
message(STATUS "Gcovr binary was not found, can not generate XML coverage info.")
11
message(STATUS "Gcovr found, can generate XML coverage info.")
12
add_custom_target (coverage-xml
13
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
14
COMMAND "${GCOVR_EXECUTABLE}" --exclude="test.*" --exclude="obj.*" -x -r "${CMAKE_SOURCE_DIR}"
15
--object-directory=${CMAKE_BINARY_DIR} -o coverage.xml)
18
find_program(LCOV_EXECUTABLE lcov HINTS ${LCOV_ROOT} "${GCOVR_ROOT}/bin")
19
find_program(GENHTML_EXECUTABLE genhtml HINTS ${GENHTML_ROOT})
20
if (NOT LCOV_EXECUTABLE)
21
message(STATUS "Lcov binary was not found, can not generate HTML coverage info.")
23
if(NOT GENHTML_EXECUTABLE)
24
message(STATUS "Genthml binary not found, can not generate HTML coverage info.")
26
message(STATUS "Lcov and genhtml found, can generate HTML coverage info.")
27
add_custom_target (coverage-html
28
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
29
COMMAND "${LCOV_EXECUTABLE}" --directory ${CMAKE_BINARY_DIR} --capture --output-file coverage.info --no-checksum
30
COMMAND "${GENHTML_EXECUTABLE}" --prefix ${CMAKE_BINARY_DIR} --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info