@@ -192,16 +192,23 @@ endif()
192
192
# AUTO - Adds the target to the 'ccov' target so that it can be run in a batch with others easily. Effective on executable targets.
193
193
# 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.
194
194
# 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
196
# EXCLUDE <REGEX_PATTERNS> - Excludes files of the patterns provided from coverage. **These do not copy to the 'all' targets.**
196
197
# OBJECTS <TARGETS> - For executables ONLY, if the provided targets are shared libraries, adds coverage information to the output
197
198
# ~~~
198
199
function (target_code_coverage TARGET_NAME)
199
200
# Argument parsing
200
201
set (options AUTO ALL EXTERNAL)
202
+ set (single_value_keywords COVERAGE_TARGET_NAME)
201
203
set (multi_value_keywords EXCLUDE OBJECTS)
202
- cmake_parse_arguments (target_code_coverage "${options} " ""
204
+ cmake_parse_arguments (target_code_coverage "${options} " "${single_value_keywords} "
203
205
"${multi_value_keywords} " ${ARGN} )
204
206
207
+ if (NOT target_code_coverage_COVERAGE_TARGET_NAME)
208
+ # If a specific name was given, use that instead.
209
+ set (target_code_coverage_COVERAGE_TARGET_NAME ${TARGET_NAME} )
210
+ endif ()
211
+
205
212
if (CODE_COVERAGE)
206
213
207
214
# Add code coverage instrumentation to the target's linker command
@@ -231,7 +238,7 @@ function(target_code_coverage TARGET_NAME)
231
238
if (CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang"
232
239
OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang" )
233
240
add_custom_target (
234
- ccov-run-${TARGET_NAME }
241
+ ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME }
235
242
COMMAND echo "-object=$<TARGET_FILE:${TARGET_NAME} >" >>
236
243
${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /binaries.list
237
244
DEPENDS ccov-preprocessing ${TARGET_NAME} )
@@ -243,7 +250,7 @@ function(target_code_coverage TARGET_NAME)
243
250
)
244
251
endif ()
245
252
246
- add_dependencies (ccov-libs ccov-run-${TARGET_NAME } )
253
+ add_dependencies (ccov-libs ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME } )
247
254
endif ()
248
255
endif ()
249
256
@@ -266,21 +273,21 @@ function(target_code_coverage TARGET_NAME)
266
273
267
274
# Run the executable, generating raw profile data
268
275
add_custom_target (
269
- ccov-run-${TARGET_NAME }
270
- COMMAND LLVM_PROFILE_FILE=${TARGET_NAME } .profraw
276
+ ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME }
277
+ COMMAND LLVM_PROFILE_FILE=${target_code_coverage_COVERAGE_TARGET_NAME } .profraw
271
278
$<TARGET_FILE:${TARGET_NAME} >
272
279
COMMAND echo "-object=$<TARGET_FILE:${TARGET_NAME} >" >>
273
280
${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /binaries.list
274
- COMMAND echo "${CMAKE_CURRENT_BINARY_DIR} /${TARGET_NAME } .profraw " >>
281
+ COMMAND echo "${CMAKE_CURRENT_BINARY_DIR} /${target_code_coverage_COVERAGE_TARGET_NAME } .profraw " >>
275
282
${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /profraw.list
276
283
DEPENDS ccov-preprocessing ccov-libs ${TARGET_NAME} )
277
284
278
285
# Merge the generated profile data so llvm-cov can process it
279
286
add_custom_target (
280
- ccov-processing-${TARGET_NAME }
281
- COMMAND ${LLVM_PROFDATA_PATH} merge -sparse ${TARGET_NAME } .profraw -o
282
- ${TARGET_NAME } .profdata
283
- DEPENDS ccov-run-${TARGET_NAME } )
287
+ ccov-processing-${target_code_coverage_COVERAGE_TARGET_NAME }
288
+ COMMAND ${LLVM_PROFDATA_PATH} merge -sparse ${target_code_coverage_COVERAGE_TARGET_NAME } .profraw -o
289
+ ${target_code_coverage_COVERAGE_TARGET_NAME } .profdata
290
+ DEPENDS ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME } )
284
291
285
292
# Ignore regex only works on LLVM >= 7
286
293
if (LLVM_COV_VERSION VERSION_GREATER_EQUAL "7.0.0" )
@@ -292,38 +299,38 @@ function(target_code_coverage TARGET_NAME)
292
299
293
300
# Print out details of the coverage information to the command line
294
301
add_custom_target (
295
- ccov-show-${TARGET_NAME }
302
+ ccov-show-${target_code_coverage_COVERAGE_TARGET_NAME }
296
303
COMMAND
297
304
${LLVM_COV_PATH} show $<TARGET_FILE:${TARGET_NAME} > ${SO_OBJECTS}
298
- -instr-profile=${TARGET_NAME } .profdata -show-line-counts-or -regions
305
+ -instr-profile=${target_code_coverage_COVERAGE_TARGET_NAME } .profdata -show-line-counts-or -regions
299
306
${EXCLUDE_REGEX}
300
- DEPENDS ccov-processing-${TARGET_NAME } )
307
+ DEPENDS ccov-processing-${target_code_coverage_COVERAGE_TARGET_NAME } )
301
308
302
309
# Print out a summary of the coverage information to the command line
303
310
add_custom_target (
304
- ccov-report-${TARGET_NAME }
311
+ ccov-report-${target_code_coverage_COVERAGE_TARGET_NAME }
305
312
COMMAND ${LLVM_COV_PATH} report $<TARGET_FILE:${TARGET_NAME} >
306
- ${SO_OBJECTS} -instr-profile=${TARGET_NAME } .profdata
313
+ ${SO_OBJECTS} -instr-profile=${target_code_coverage_COVERAGE_TARGET_NAME } .profdata
307
314
${EXCLUDE_REGEX}
308
- DEPENDS ccov-processing-${TARGET_NAME } )
315
+ DEPENDS ccov-processing-${target_code_coverage_COVERAGE_TARGET_NAME } )
309
316
310
317
# Generates HTML output of the coverage information for perusal
311
318
add_custom_target (
312
- ccov-${TARGET_NAME }
319
+ ccov-${target_code_coverage_COVERAGE_TARGET_NAME }
313
320
COMMAND
314
321
${LLVM_COV_PATH} show $<TARGET_FILE:${TARGET_NAME} > ${SO_OBJECTS}
315
- -instr-profile=${TARGET_NAME } .profdata -show-line-counts-or -regions
316
- -output -dir=${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /${TARGET_NAME }
322
+ -instr-profile=${target_code_coverage_COVERAGE_TARGET_NAME } .profdata -show-line-counts-or -regions
323
+ -output -dir=${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /${target_code_coverage_COVERAGE_TARGET_NAME }
317
324
-format="html" ${EXCLUDE_REGEX}
318
- DEPENDS ccov-processing-${TARGET_NAME } )
325
+ DEPENDS ccov-processing-${target_code_coverage_COVERAGE_TARGET_NAME } )
319
326
320
327
elseif (CMAKE_COMPILER_IS_GNUCXX)
321
328
set (COVERAGE_INFO
322
- "${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /${TARGET_NAME } .info" )
329
+ "${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /${target_code_coverage_COVERAGE_TARGET_NAME } .info" )
323
330
324
331
# Run the executable, generating coverage information
325
332
add_custom_target (
326
- ccov-run-${TARGET_NAME }
333
+ ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME }
327
334
COMMAND $<TARGET_FILE:${TARGET_NAME} >
328
335
DEPENDS ccov-preprocessing ${TARGET_NAME} )
329
336
@@ -346,7 +353,7 @@ function(target_code_coverage TARGET_NAME)
346
353
347
354
# Capture coverage data
348
355
add_custom_target (
349
- ccov-capture-${TARGET_NAME }
356
+ ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME }
350
357
COMMAND ${CMAKE_COMMAND} -E remove ${COVERAGE_INFO}
351
358
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters
352
359
COMMAND $<TARGET_FILE:${TARGET_NAME} >
@@ -359,33 +366,33 @@ function(target_code_coverage TARGET_NAME)
359
366
360
367
# Generates HTML output of the coverage information for perusal
361
368
add_custom_target (
362
- ccov-${TARGET_NAME }
369
+ ccov-${target_code_coverage_COVERAGE_TARGET_NAME }
363
370
COMMAND ${GENHTML_PATH} -o
364
- ${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /${TARGET_NAME }
371
+ ${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /${target_code_coverage_COVERAGE_TARGET_NAME }
365
372
${COVERAGE_INFO}
366
- DEPENDS ccov-capture-${TARGET_NAME } )
373
+ DEPENDS ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME } )
367
374
endif ()
368
375
369
376
add_custom_command (
370
- TARGET ccov-${TARGET_NAME }
377
+ TARGET ccov-${target_code_coverage_COVERAGE_TARGET_NAME }
371
378
POST_BUILD
372
379
COMMAND ;
373
380
COMMENT
374
- "Open ${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /${TARGET_NAME } /index.html in your browser to view the coverage report."
381
+ "Open ${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /${target_code_coverage_COVERAGE_TARGET_NAME } /index.html in your browser to view the coverage report."
375
382
)
376
383
377
384
# AUTO
378
385
if (target_code_coverage_AUTO)
379
386
if (NOT TARGET ccov)
380
387
add_custom_target (ccov)
381
388
endif ()
382
- add_dependencies (ccov ccov-${TARGET_NAME } )
389
+ add_dependencies (ccov ccov-${target_code_coverage_COVERAGE_TARGET_NAME } )
383
390
384
391
if (NOT CMAKE_COMPILER_IS_GNUCXX)
385
392
if (NOT TARGET ccov-report)
386
393
add_custom_target (ccov-report)
387
394
endif ()
388
- add_dependencies (ccov-report ccov-report-${TARGET_NAME } )
395
+ add_dependencies (ccov-report ccov-report-${target_code_coverage_COVERAGE_TARGET_NAME } )
389
396
endif ()
390
397
endif ()
391
398
@@ -398,7 +405,7 @@ function(target_code_coverage TARGET_NAME)
398
405
)
399
406
endif ()
400
407
401
- add_dependencies (ccov-all -processing ccov-run-${TARGET_NAME } )
408
+ add_dependencies (ccov-all -processing ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME } )
402
409
endif ()
403
410
endif ()
404
411
endif ()
0 commit comments