Skip to content

Commit e95b081

Browse files
committed
Refactor ccov target dependencies tree
1 parent ea9e8b7 commit e95b081

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

code-coverage.cmake

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ function(target_code_coverage TARGET_NAME)
430430
# Capture coverage data
431431
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
432432
add_custom_target(
433-
ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME}
433+
ccov-clean-${target_code_coverage_COVERAGE_TARGET_NAME}
434434
COMMAND ${CMAKE_COMMAND} -E remove -f ${COVERAGE_INFO}
435435
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters
436436
COMMAND
@@ -444,7 +444,7 @@ function(target_code_coverage TARGET_NAME)
444444
DEPENDS ${TARGET_NAME})
445445
else()
446446
add_custom_target(
447-
ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME}
447+
ccov-clean-${target_code_coverage_COVERAGE_TARGET_NAME}
448448
COMMAND ${CMAKE_COMMAND} -E rm -f ${COVERAGE_INFO}
449449
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters
450450
COMMAND
@@ -458,14 +458,32 @@ function(target_code_coverage TARGET_NAME)
458458
DEPENDS ${TARGET_NAME})
459459
endif()
460460

461-
# Generates HTML output of the coverage information for perusal
462461
add_custom_target(
463-
ccov-${target_code_coverage_COVERAGE_TARGET_NAME}
462+
ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME}
463+
COMMAND
464+
${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --base-directory
465+
${CMAKE_SOURCE_DIR} --capture ${EXTERNAL_OPTION} --output-file
466+
${COVERAGE_INFO}
467+
COMMAND ${EXCLUDE_COMMAND}
468+
DEPENDS)
469+
470+
# Only generates HTML output of the coverage information for perusal
471+
add_custom_target(
472+
ccov-html-${target_code_coverage_COVERAGE_TARGET_NAME}
464473
COMMAND
465474
${GENHTML_PATH} -o
466475
${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/${target_code_coverage_COVERAGE_TARGET_NAME}
467476
${COVERAGE_INFO}
468477
DEPENDS ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME})
478+
479+
# Generates HTML output of the coverage information for perusal
480+
add_custom_target(
481+
ccov-${target_code_coverage_COVERAGE_TARGET_NAME}
482+
COMMAND
483+
DEPENDS
484+
ccov-clean-${target_code_coverage_COVERAGE_TARGET_NAME}
485+
ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME}
486+
ccov-html-${target_code_coverage_COVERAGE_TARGET_NAME})
469487
endif()
470488

471489
add_custom_command(
@@ -483,6 +501,11 @@ function(target_code_coverage TARGET_NAME)
483501
endif()
484502
add_dependencies(ccov ccov-${target_code_coverage_COVERAGE_TARGET_NAME})
485503

504+
if(NOT TARGET ccov-html)
505+
add_custom_target(ccov-html)
506+
endif()
507+
add_dependencies(ccov-html ccov-html-${target_code_coverage_COVERAGE_TARGET_NAME})
508+
486509
if(NOT CMAKE_C_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_CXX_COMPILER_ID
487510
MATCHES "GNU")
488511
if(NOT TARGET ccov-report)
@@ -671,29 +694,42 @@ function(add_code_coverage_all_targets)
671694
# Capture coverage data
672695
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
673696
add_custom_target(
674-
ccov-all-capture
697+
ccov-all-clean
675698
COMMAND ${CMAKE_COMMAND} -E remove -f ${COVERAGE_INFO}
676699
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --capture
677700
--output-file ${COVERAGE_INFO}
678701
COMMAND ${EXCLUDE_COMMAND}
679702
DEPENDS ccov-all-processing)
680703
else()
681704
add_custom_target(
682-
ccov-all-capture
705+
ccov-all-clean
683706
COMMAND ${CMAKE_COMMAND} -E rm -f ${COVERAGE_INFO}
684707
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --capture
685708
--output-file ${COVERAGE_INFO}
686709
COMMAND ${EXCLUDE_COMMAND}
687710
DEPENDS ccov-all-processing)
688711
endif()
689712

690-
# Generates HTML output of all targets for perusal
691713
add_custom_target(
692-
ccov-all
714+
ccov-all-capture
715+
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --capture
716+
--output-file ${COVERAGE_INFO}
717+
COMMAND ${EXCLUDE_COMMAND}
718+
DEPENDS)
719+
720+
# Only generates HTML output of all targets for perusal
721+
add_custom_target(
722+
ccov-all-html
693723
COMMAND ${GENHTML_PATH} -o ${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/all-merged
694724
${COVERAGE_INFO} -p ${CMAKE_SOURCE_DIR}
695725
DEPENDS ccov-all-capture)
696726

727+
# Generates HTML output of all targets for perusal
728+
add_custom_target(
729+
ccov-all
730+
COMMAND
731+
DEPENDS ccov-preprocessing ccov-all-processing ccov-all-clean ccov-all-html)
732+
697733
endif()
698734

699735
add_custom_command(

0 commit comments

Comments
 (0)