@@ -471,14 +471,6 @@ function(target_code_coverage TARGET_NAME)
471
471
"${CMAKE_COVERAGE_DATA_DIRECTORY} /${target_code_coverage_COVERAGE_TARGET_NAME} .info"
472
472
)
473
473
474
- # Run the executable, generating coverage information
475
- add_custom_target (
476
- ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME}
477
- COMMAND
478
- ${CMAKE_CROSSCOMPILING_EMULATOR} ${target_code_coverage_PRE_ARGS}
479
- $<TARGET_FILE:${TARGET_NAME} > ${target_code_coverage_ARGS}
480
- DEPENDS ${TARGET_NAME} )
481
-
482
474
# Generate exclusion string for use
483
475
foreach (EXCLUDE_ITEM ${target_code_coverage_EXCLUDE} )
484
476
set (EXCLUDE_REGEX ${EXCLUDE_REGEX} --remove ${COVERAGE_INFO}
@@ -509,14 +501,32 @@ function(target_code_coverage TARGET_NAME)
509
501
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters)
510
502
endif ()
511
503
504
+ # Run the executable, generating coverage information
505
+ add_custom_command (
506
+ OUTPUT ${target_code_coverage_COVERAGE_TARGET_NAME} .ccov-run
507
+ COMMAND
508
+ ${CMAKE_CROSSCOMPILING_EMULATOR} ${target_code_coverage_PRE_ARGS}
509
+ $<TARGET_FILE:${TARGET_NAME} > ${target_code_coverage_ARGS}
510
+ COMMAND # add a dummy file to use as a dependency to indicate the target
511
+ # has been run and data collected
512
+ ${CMAKE_COMMAND} -E touch
513
+ ${target_code_coverage_COVERAGE_TARGET_NAME} .ccov-run
514
+ DEPENDS ${TARGET_NAME} )
512
515
add_custom_target (
513
- ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME}
516
+ ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME}
517
+ DEPENDS ${target_code_coverage_COVERAGE_TARGET_NAME} .ccov-run)
518
+
519
+ add_custom_command (
520
+ OUTPUT ${COVERAGE_INFO}
514
521
COMMAND
515
522
${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --base-directory
516
523
${CMAKE_SOURCE_DIR} --capture ${EXTERNAL_OPTION} --output -file
517
524
${COVERAGE_INFO}
518
525
COMMAND ${EXCLUDE_COMMAND}
519
- DEPENDS )
526
+ DEPENDS ${target_code_coverage_COVERAGE_TARGET_NAME} .ccov-run)
527
+ add_custom_target (
528
+ ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME}
529
+ DEPENDS ${COVERAGE_INFO} )
520
530
521
531
# Only generates HTML output of the coverage information for perusal
522
532
add_custom_target (
@@ -528,15 +538,12 @@ function(target_code_coverage TARGET_NAME)
528
538
COMMAND
529
539
${CMAKE_COMMAND} -E echo
530
540
"Open ${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /${target_code_coverage_COVERAGE_TARGET_NAME} /index.html in your browser to view the coverage report."
531
- DEPENDS ccov-capture- ${target_code_coverage_COVERAGE_TARGET_NAME } )
541
+ DEPENDS ${COVERAGE_INFO } )
532
542
533
543
# Generates HTML output of the coverage information for perusal
534
544
add_custom_target (
535
545
ccov-${target_code_coverage_COVERAGE_TARGET_NAME}
536
- COMMAND
537
- DEPENDS ccov-clean-${target_code_coverage_COVERAGE_TARGET_NAME}
538
- ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME}
539
- ccov-html-${target_code_coverage_COVERAGE_TARGET_NAME} )
546
+ DEPENDS ccov-html-${target_code_coverage_COVERAGE_TARGET_NAME} )
540
547
endif ()
541
548
542
549
# AUTO
@@ -737,8 +744,7 @@ function(add_code_coverage_all_targets)
737
744
"GNU" )
738
745
set (COVERAGE_INFO "${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /ccov-all.info" )
739
746
740
- # Nothing required for gcov
741
- add_custom_target (ccov-all -processing COMMAND ;)
747
+ add_custom_target (ccov-all -run)
742
748
743
749
# Exclusion regex string creation
744
750
set (EXCLUDE_REGEX)
@@ -769,12 +775,13 @@ function(add_code_coverage_all_targets)
769
775
DEPENDS ccov-all -processing)
770
776
endif ()
771
777
772
- add_custom_target (
773
- ccov- all -capture
774
- COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --capture
775
- --output -file ${COVERAGE_INFO}
778
+ add_custom_command (
779
+ OUTPUT ${COVERAGE_INFO}
780
+ COMMAND ${LCOV_PATH} --ignore -errors unused --directory
781
+ ${CMAKE_BINARY_DIR} --capture --output -file ${COVERAGE_INFO}
776
782
COMMAND ${EXCLUDE_COMMAND}
777
- DEPENDS )
783
+ DEPENDS ccov-all -run)
784
+ add_custom_target (ccov-all -capture DEPENDS ${COVERAGE_INFO} )
778
785
779
786
# Only generates HTML output of all targets for perusal
780
787
add_custom_target (
@@ -784,13 +791,13 @@ function(add_code_coverage_all_targets)
784
791
COMMAND
785
792
${CMAKE_COMMAND} -E echo
786
793
"Open ${CMAKE_COVERAGE_OUTPUT_DIRECTORY} /all-merged/index.html in your browser to view the coverage report."
787
- DEPENDS ccov- all -capture )
794
+ DEPENDS ${COVERAGE_INFO} )
788
795
789
796
# Generates HTML output of all targets for perusal
790
797
add_custom_target (
791
798
ccov-all
792
799
COMMAND
793
- DEPENDS ccov-all -processing ccov- all -capture ccov- all - html)
800
+ DEPENDS ccov-all -html)
794
801
795
802
endif ()
796
803
endfunction ()
0 commit comments