Skip to content

Commit 6f854b7

Browse files
committed
Added passing args to coverage executable calls
Allowing for appending arguments to calls to executables with attatched coverage information for custom use.
1 parent 7f4d07b commit 6f854b7

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

code-coverage.cmake

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,16 @@ endif()
192192
# AUTO - Adds the target to the 'ccov' target so that it can be run in a batch with others easily. Effective on executable targets.
193193
# 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.
194194
# EXTERNAL - For GCC's lcov, allows the profiling of 'external' files from the processing directory
195-
# COVERAGE_TARGET_NAME - Changes the outgoing target name so instead of `ccov-${TARGET_NAME}` it becomes `ccov-${COVERAGE_TARGET_NAME}`.
195+
# COVERAGE_TARGET_NAME - For executables ONLY, changes the outgoing target name so instead of `ccov-${TARGET_NAME}` it becomes `ccov-${COVERAGE_TARGET_NAME}`.
196196
# EXCLUDE <REGEX_PATTERNS> - Excludes files of the patterns provided from coverage. **These do not copy to the 'all' targets.**
197197
# OBJECTS <TARGETS> - For executables ONLY, if the provided targets are shared libraries, adds coverage information to the output
198+
# ARGS <ARGUMENTS> - For executables ONLY, append sthe given arguments to the associated ccov-* executable call
198199
# ~~~
199200
function(target_code_coverage TARGET_NAME)
200201
# Argument parsing
201202
set(options AUTO ALL EXTERNAL)
202203
set(single_value_keywords COVERAGE_TARGET_NAME)
203-
set(multi_value_keywords EXCLUDE OBJECTS)
204+
set(multi_value_keywords EXCLUDE OBJECTS ARGS)
204205
cmake_parse_arguments(target_code_coverage "${options}" "${single_value_keywords}"
205206
"${multi_value_keywords}" ${ARGN})
206207

@@ -209,6 +210,8 @@ function(target_code_coverage TARGET_NAME)
209210
set(target_code_coverage_COVERAGE_TARGET_NAME ${TARGET_NAME})
210211
endif()
211212

213+
message(STATUS "For the target ${target_code_coverage_COVERAGE_TARGET_NAME}, these are the arguments given to use: ${target_code_coverage_ARGS}")
214+
212215
if(CODE_COVERAGE)
213216

214217
# Add code coverage instrumentation to the target's linker command
@@ -275,7 +278,7 @@ function(target_code_coverage TARGET_NAME)
275278
add_custom_target(
276279
ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME}
277280
COMMAND LLVM_PROFILE_FILE=${target_code_coverage_COVERAGE_TARGET_NAME}.profraw
278-
$<TARGET_FILE:${TARGET_NAME}>
281+
$<TARGET_FILE:${TARGET_NAME}> ${target_code_coverage_ARGS}
279282
COMMAND echo "-object=$<TARGET_FILE:${TARGET_NAME}>" >>
280283
${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/binaries.list
281284
COMMAND echo "${CMAKE_CURRENT_BINARY_DIR}/${target_code_coverage_COVERAGE_TARGET_NAME}.profraw " >>
@@ -331,7 +334,7 @@ function(target_code_coverage TARGET_NAME)
331334
# Run the executable, generating coverage information
332335
add_custom_target(
333336
ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME}
334-
COMMAND $<TARGET_FILE:${TARGET_NAME}>
337+
COMMAND $<TARGET_FILE:${TARGET_NAME}> ${target_code_coverage_ARGS}
335338
DEPENDS ccov-preprocessing ${TARGET_NAME})
336339

337340
# Generate exclusion string for use
@@ -356,7 +359,7 @@ function(target_code_coverage TARGET_NAME)
356359
ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME}
357360
COMMAND ${CMAKE_COMMAND} -E remove ${COVERAGE_INFO}
358361
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters
359-
COMMAND $<TARGET_FILE:${TARGET_NAME}>
362+
COMMAND $<TARGET_FILE:${TARGET_NAME}> ${target_code_coverage_ARGS}
360363
COMMAND
361364
${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --base-directory
362365
${CMAKE_SOURCE_DIR} --capture ${EXTERNAL_OPTION} --output-file

0 commit comments

Comments
 (0)