Skip to content

Commit 4af5b40

Browse files
committed
Add PRE_ARGS option to target_code_coverage
In addition to the current ARGS multi-value option which appends options to the end of an executable call, PRE_ARGS instead prefixes items to the call, to the end for of: $PRE_ARGS ccov-* $ARGS
1 parent 6873aff commit 4af5b40

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Diff for: code-coverage.cmake

+10-6
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,14 @@ endif()
211211
# COVERAGE_TARGET_NAME - For executables ONLY, changes the outgoing target name so instead of `ccov-${TARGET_NAME}` it becomes `ccov-${COVERAGE_TARGET_NAME}`.
212212
# EXCLUDE <PATTERNS> - Excludes files of the patterns provided from coverage. Note that GCC/lcov excludes by glob pattern, and clang/LLVM excludes via regex! **These do not copy to the 'all' targets.**
213213
# OBJECTS <TARGETS> - For executables ONLY, if the provided targets are shared libraries, adds coverage information to the output
214-
# ARGS <ARGUMENTS> - For executables ONLY, appends the given arguments to the associated ccov-* executable call
214+
# PRE_ARGS <ARGUMENTS> - For executables ONLY, prefixes given arguments to the associated ccov-* executable call ($<PRE_ARGS> ccov-*)
215+
# ARGS <ARGUMENTS> - For executables ONLY, appends the given arguments to the associated ccov-* executable call (ccov-* $<ARGS>)
215216
# ~~~
216217
function(target_code_coverage TARGET_NAME)
217218
# Argument parsing
218219
set(options AUTO ALL EXTERNAL PUBLIC INTERFACE PLAIN)
219220
set(single_value_keywords COVERAGE_TARGET_NAME)
220-
set(multi_value_keywords EXCLUDE OBJECTS ARGS)
221+
set(multi_value_keywords EXCLUDE OBJECTS PRE_ARGS ARGS)
221222
cmake_parse_arguments(
222223
target_code_coverage "${options}" "${single_value_keywords}"
223224
"${multi_value_keywords}" ${ARGN})
@@ -309,7 +310,7 @@ function(target_code_coverage TARGET_NAME)
309310
add_custom_target(
310311
ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME}
311312
COMMAND
312-
${CMAKE_COMMAND} -E env
313+
${CMAKE_COMMAND} -E env ${target_code_coverage_PRE_ARGS}
313314
LLVM_PROFILE_FILE=${target_code_coverage_COVERAGE_TARGET_NAME}.profraw
314315
$<TARGET_FILE:${TARGET_NAME}> ${target_code_coverage_ARGS}
315316
COMMAND
@@ -388,7 +389,8 @@ function(target_code_coverage TARGET_NAME)
388389
# Run the executable, generating coverage information
389390
add_custom_target(
390391
ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME}
391-
COMMAND $<TARGET_FILE:${TARGET_NAME}> ${target_code_coverage_ARGS}
392+
COMMAND ${target_code_coverage_PRE_ARGS} $<TARGET_FILE:${TARGET_NAME}>
393+
${target_code_coverage_ARGS}
392394
DEPENDS ${TARGET_NAME})
393395

394396
# Generate exclusion string for use
@@ -414,7 +416,8 @@ function(target_code_coverage TARGET_NAME)
414416
ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME}
415417
COMMAND ${CMAKE_COMMAND} -E remove -f ${COVERAGE_INFO}
416418
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters
417-
COMMAND $<TARGET_FILE:${TARGET_NAME}> ${target_code_coverage_ARGS}
419+
COMMAND ${target_code_coverage_PRE_ARGS}
420+
$<TARGET_FILE:${TARGET_NAME}> ${target_code_coverage_ARGS}
418421
COMMAND
419422
${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --base-directory
420423
${CMAKE_SOURCE_DIR} --capture ${EXTERNAL_OPTION} --output-file
@@ -426,7 +429,8 @@ function(target_code_coverage TARGET_NAME)
426429
ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME}
427430
COMMAND ${CMAKE_COMMAND} -E rm -f ${COVERAGE_INFO}
428431
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters
429-
COMMAND $<TARGET_FILE:${TARGET_NAME}> ${target_code_coverage_ARGS}
432+
COMMAND ${target_code_coverage_PRE_ARGS}
433+
$<TARGET_FILE:${TARGET_NAME}> ${target_code_coverage_ARGS}
430434
COMMAND
431435
${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --base-directory
432436
${CMAKE_SOURCE_DIR} --capture ${EXTERNAL_OPTION} --output-file

0 commit comments

Comments
 (0)