-
Notifications
You must be signed in to change notification settings - Fork 47
/
coverage.cmake
61 lines (56 loc) · 1.29 KB
/
coverage.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#
# Copyright 2022 CNRS
#
# Author: Guilhem Saurel
#
# .rst: .. ifmode:: internal
#
# .. variable:: ENABLE_COVERAGE
#
# When this is ON, coverage compiler flags are enabled. Disabled for MSVC.
if(NOT MSVC)
option(ENABLE_COVERAGE "Enable C++ and Python code coverage" OFF)
else()
set(ENABLE_COVERAGE OFF)
endif()
# .rst: .. ifmode:: internal
#
# .. command:: enable_coverage
#
# Deprecated and useless.
function(enable_coverage target)
message(
WARNING
"the 'enable_coverage' CMake function is deprecated and does nothing."
)
endfunction()
if(ENABLE_COVERAGE)
set(
CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -O0 -g --coverage"
CACHE STRING
"coverage flags"
)
find_program(
KCOV
kcov
DOC "kcov is required for use with -DENABLE_COVERAGE=ON"
REQUIRED
)
set(KCOV_DIR "${CMAKE_BINARY_DIR}/kcov")
file(MAKE_DIRECTORY ${KCOV_DIR})
endif()
macro(_SETUP_COVERAGE_FINALIZE)
if(NOT TARGET coverage)
add_custom_target(
coverage
COMMENT "Generating HTML report for code coverage"
)
add_custom_target(
${PROJECT_NAME}-coverage
COMMAND ${KCOV} --merge ${CMAKE_BINARY_DIR}/coverage ${KCOV_DIR}/*
COMMENT "Generating HTML report for code coverage"
)
add_dependencies(coverage ${PROJECT_NAME}-coverage)
endif()
endmacro()