Skip to content

Commit ed79fb9

Browse files
rlalikStableCoder
authored andcommitted
Add plain option for target coverage
1 parent 8034d91 commit ed79fb9

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

code-coverage.cmake

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ endif()
208208
# Optional:
209209
# PUBLIC - Sets the visibility for added compile options to targets to PUBLIC instead of the default of PRIVATE.
210210
# INTERFACE - Sets the visibility for added compile options to targets to INTERFACE instead of the default of PRIVATE.
211+
# PLAIN - Do not set any target visibility (backward compatibility with old cmake projects)
211212
# AUTO - Adds the target to the 'ccov' target so that it can be run in a batch with others easily. Effective on executable targets.
212213
# ALL - Adds the target to the 'ccov-all' and 'ccov-all-report' targets, which merge several executable targets coverage data to a single report. Effective on executable targets.
213214
# EXTERNAL - For GCC's lcov, allows the profiling of 'external' files from the processing directory
@@ -218,7 +219,7 @@ endif()
218219
# ~~~
219220
function(target_code_coverage TARGET_NAME)
220221
# Argument parsing
221-
set(options AUTO ALL EXTERNAL PUBLIC INTERFACE)
222+
set(options AUTO ALL EXTERNAL PUBLIC INTERFACE PLAIN)
222223
set(single_value_keywords COVERAGE_TARGET_NAME)
223224
set(multi_value_keywords EXCLUDE OBJECTS ARGS)
224225
cmake_parse_arguments(
@@ -229,10 +230,16 @@ function(target_code_coverage TARGET_NAME)
229230
# PRIVATE.
230231
if(target_code_coverage_PUBLIC)
231232
set(TARGET_VISIBILITY PUBLIC)
233+
set(TARGET_LINK_VISIBILITY PUBLIC)
232234
elseif(target_code_coverage_INTERFACE)
233235
set(TARGET_VISIBILITY INTERFACE)
236+
set(TARGET_LINK_VISIBILITY INTERFACE)
237+
elseif(target_code_coverage_PLAIN)
238+
set(TARGET_VISIBILITY PUBLIC)
239+
set(TARGET_LINK_VISIBILITY)
234240
else()
235241
set(TARGET_VISIBILITY PRIVATE)
242+
set(TARGET_LINK_VISIBILITY PRIVATE)
236243
endif()
237244

238245
if(NOT target_code_coverage_COVERAGE_TARGET_NAME)
@@ -253,7 +260,7 @@ function(target_code_coverage TARGET_NAME)
253260
"GNU")
254261
target_compile_options(${TARGET_NAME} ${TARGET_VISIBILITY} -fprofile-arcs
255262
-ftest-coverage)
256-
target_link_libraries(${TARGET_NAME} ${TARGET_VISIBILITY} gcov)
263+
target_link_libraries(${TARGET_NAME} ${TARGET_LINK_VISIBILITY} gcov)
257264
endif()
258265

259266
# Targets

0 commit comments

Comments
 (0)