Skip to content

Commit a73bb1a

Browse files
rlalikStableCoder
authored andcommitted
Refactor ccov target dependencies tree
1 parent 21af212 commit a73bb1a

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

code-coverage.cmake

Lines changed: 45 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,9 +458,18 @@ 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}
@@ -469,6 +478,15 @@ function(target_code_coverage TARGET_NAME)
469478
${CMAKE_COMMAND} -E echo
470479
"Open ${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/${target_code_coverage_COVERAGE_TARGET_NAME}/index.html in your browser to view the coverage report."
471480
DEPENDS ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME})
481+
482+
# Generates HTML output of the coverage information for perusal
483+
add_custom_target(
484+
ccov-${target_code_coverage_COVERAGE_TARGET_NAME}
485+
COMMAND
486+
DEPENDS
487+
ccov-clean-${target_code_coverage_COVERAGE_TARGET_NAME}
488+
ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME}
489+
ccov-html-${target_code_coverage_COVERAGE_TARGET_NAME})
472490
endif()
473491

474492
# AUTO
@@ -478,6 +496,11 @@ function(target_code_coverage TARGET_NAME)
478496
endif()
479497
add_dependencies(ccov ccov-${target_code_coverage_COVERAGE_TARGET_NAME})
480498

499+
if(NOT TARGET ccov-html)
500+
add_custom_target(ccov-html)
501+
endif()
502+
add_dependencies(ccov-html ccov-html-${target_code_coverage_COVERAGE_TARGET_NAME})
503+
481504
if(NOT CMAKE_C_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_CXX_COMPILER_ID
482505
MATCHES "GNU")
483506
if(NOT TARGET ccov-report)
@@ -666,31 +689,45 @@ function(add_code_coverage_all_targets)
666689
# Capture coverage data
667690
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
668691
add_custom_target(
669-
ccov-all-capture
692+
ccov-all-clean
670693
COMMAND ${CMAKE_COMMAND} -E remove -f ${COVERAGE_INFO}
671694
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --capture
672695
--output-file ${COVERAGE_INFO}
673696
COMMAND ${EXCLUDE_COMMAND}
674697
DEPENDS ccov-all-processing)
675698
else()
676699
add_custom_target(
677-
ccov-all-capture
700+
ccov-all-clean
678701
COMMAND ${CMAKE_COMMAND} -E rm -f ${COVERAGE_INFO}
679702
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --capture
680703
--output-file ${COVERAGE_INFO}
681704
COMMAND ${EXCLUDE_COMMAND}
682705
DEPENDS ccov-all-processing)
683706
endif()
684707

685-
# Generates HTML output of all targets for perusal
686708
add_custom_target(
687-
ccov-all
709+
ccov-all-capture
710+
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --capture
711+
--output-file ${COVERAGE_INFO}
712+
COMMAND ${EXCLUDE_COMMAND}
713+
DEPENDS)
714+
715+
# Only generates HTML output of all targets for perusal
716+
add_custom_target(
717+
ccov-all-html
688718
COMMAND ${GENHTML_PATH} -o ${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/all-merged
689719
${COVERAGE_INFO} -p ${CMAKE_SOURCE_DIR}
690720
COMMAND
691721
${CMAKE_COMMAND} -E echo
692722
"Open ${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/all-merged/index.html in your browser to view the coverage report."
693723
DEPENDS ccov-all-capture)
724+
725+
# Generates HTML output of all targets for perusal
726+
add_custom_target(
727+
ccov-all
728+
COMMAND
729+
DEPENDS ccov-preprocessing ccov-all-processing ccov-all-clean ccov-all-html)
730+
694731
endif()
695732
endif()
696733
endfunction()

0 commit comments

Comments
 (0)