@@ -85,12 +85,7 @@ find_program(LLVM_PROFDATA_PATH llvm-profdata)
85
85
find_program (LCOV_PATH lcov )
86
86
find_program (GENHTML_PATH genhtml )
87
87
# Hide behind the 'advanced' mode flag for GUI/ccmake
88
- mark_as_advanced (
89
- FORCE
90
- LLVM_COV_PATH
91
- LLVM_PROFDATA_PATH
92
- LCOV_PATH
93
- GENHTML_PATH )
88
+ mark_as_advanced (FORCE LLVM_COV_PATH LLVM_PROFDATA_PATH LCOV_PATH GENHTML_PATH )
94
89
95
90
# Variables
96
91
set (CMAKE_COVERAGE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /ccov )
@@ -117,10 +112,7 @@ if(CODE_COVERAGE AND NOT CODE_COVERAGE_ADDED)
117
112
# Version number checking for 'EXCLUDE' compatibility
118
113
execute_process (COMMAND ${LLVM_COV_PATH} --version
119
114
OUTPUT_VARIABLE LLVM_COV_VERSION_CALL_OUTPUT )
120
- string (
121
- REGEX MATCH
122
- "[0-9]+\\ .[0-9]+\\ .[0-9]+"
123
- LLVM_COV_VERSION
115
+ string (REGEX MATCH "[0-9]+\\ .[0-9]+\\ .[0-9]+" LLVM_COV_VERSION
124
116
${LLVM_COV_VERSION_CALL_OUTPUT} )
125
117
126
118
if (LLVM_COV_VERSION VERSION_LESS "7.0.0" )
@@ -144,17 +136,14 @@ if(CODE_COVERAGE AND NOT CODE_COVERAGE_ADDED)
144
136
COMMAND ;
145
137
COMMENT "libs ready for coverage report." )
146
138
147
- elseif (CMAKE_C_COMPILER_ID MATCHES "GNU"
148
- OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
139
+ elseif (CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES
140
+ "GNU" )
149
141
# Messages
150
142
message (STATUS "Building with lcov Code Coverage Tools" )
151
143
152
144
if (CMAKE_BUILD_TYPE )
153
145
string (TOUPPER ${CMAKE_BUILD_TYPE} upper_build_type )
154
- if (NOT
155
- ${upper_build_type}
156
- STREQUAL
157
- "DEBUG" )
146
+ if (NOT ${upper_build_type} STREQUAL "DEBUG" )
158
147
message (
159
148
WARNING
160
149
"Code coverage results with an optimized (non-Debug) build may be misleading"
@@ -215,20 +204,12 @@ endif()
215
204
# ~~~
216
205
function (target_code_coverage TARGET_NAME )
217
206
# Argument parsing
218
- set (options
219
- AUTO
220
- ALL
221
- EXTERNAL
222
- PUBLIC
223
- INTERFACE )
207
+ set (options AUTO ALL EXTERNAL PUBLIC INTERFACE )
224
208
set (single_value_keywords COVERAGE_TARGET_NAME )
225
209
set (multi_value_keywords EXCLUDE OBJECTS ARGS )
226
210
cmake_parse_arguments (
227
- target_code_coverage
228
- "${options} "
229
- "${single_value_keywords} "
230
- "${multi_value_keywords} "
231
- ${ARGN} )
211
+ target_code_coverage "${options} " "${single_value_keywords} "
212
+ "${multi_value_keywords} " ${ARGN} )
232
213
233
214
# Set the visibility of target functions to PUBLIC, INTERFACE or default to
234
215
# PRIVATE.
@@ -250,22 +231,13 @@ function(target_code_coverage TARGET_NAME)
250
231
# Add code coverage instrumentation to the target's linker command
251
232
if (CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang"
252
233
OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang" )
253
- target_compile_options (
254
- ${TARGET_NAME}
255
- ${TARGET_VISIBILITY}
256
- -fprofile-instr-generate
257
- -fcoverage-mapping )
258
- target_link_options (
259
- ${TARGET_NAME}
260
- ${TARGET_VISIBILITY}
261
- -fprofile-instr-generate
262
- -fcoverage-mapping )
263
- elseif (CMAKE_C_COMPILER_ID MATCHES "GNU"
264
- OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
265
- target_compile_options (
266
- ${TARGET_NAME}
267
- ${TARGET_VISIBILITY}
268
- -fprofile-arcs
234
+ target_compile_options (${TARGET_NAME} ${TARGET_VISIBILITY}
235
+ -fprofile-instr-generate -fcoverage-mapping )
236
+ target_link_options (${TARGET_NAME} ${TARGET_VISIBILITY}
237
+ -fprofile-instr-generate -fcoverage-mapping )
238
+ elseif (CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES
239
+ "GNU" )
240
+ target_compile_options (${TARGET_NAME} ${TARGET_VISIBILITY} -fprofile-arcs
269
241
-ftest-coverage )
270
242
target_link_libraries (${TARGET_NAME} ${TARGET_VISIBILITY} gcov )
271
243
endif ()
@@ -386,10 +358,7 @@ function(target_code_coverage TARGET_NAME)
386
358
387
359
# Generate exclusion string for use
388
360
foreach (EXCLUDE_ITEM ${target_code_coverage_EXCLUDE} )
389
- set (EXCLUDE_REGEX
390
- ${EXCLUDE_REGEX}
391
- --remove
392
- ${COVERAGE_INFO}
361
+ set (EXCLUDE_REGEX ${EXCLUDE_REGEX} --remove ${COVERAGE_INFO}
393
362
'${EXCLUDE_ITEM}' )
394
363
endforeach ()
395
364
@@ -496,12 +465,8 @@ endfunction()
496
465
function (add_code_coverage_all_targets )
497
466
# Argument parsing
498
467
set (multi_value_keywords EXCLUDE )
499
- cmake_parse_arguments (
500
- add_code_coverage_all_targets
501
- ""
502
- ""
503
- "${multi_value_keywords} "
504
- ${ARGN} )
468
+ cmake_parse_arguments (add_code_coverage_all_targets "" ""
469
+ "${multi_value_keywords} " ${ARGN} )
505
470
506
471
if (CODE_COVERAGE )
507
472
if (CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang"
@@ -567,10 +532,7 @@ function(add_code_coverage_all_targets)
567
532
# Exclusion regex string creation
568
533
set (EXCLUDE_REGEX )
569
534
foreach (EXCLUDE_ITEM ${add_code_coverage_all_targets_EXCLUDE} )
570
- set (EXCLUDE_REGEX
571
- ${EXCLUDE_REGEX}
572
- --remove
573
- ${COVERAGE_INFO}
535
+ set (EXCLUDE_REGEX ${EXCLUDE_REGEX} --remove ${COVERAGE_INFO}
574
536
'${EXCLUDE_ITEM}' )
575
537
endforeach ()
576
538
0 commit comments