Skip to content

Commit 003c241

Browse files
committed
Fix code-coverage Xcode issues
Limition of the Xcode generator related to dependencies of CMake custom commands generating file outputs.
1 parent ff75cf2 commit 003c241

1 file changed

Lines changed: 29 additions & 15 deletions

File tree

code-coverage.cmake

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ function(target_code_coverage TARGET_NAME)
413413
#
414414
# If the option for a hidden target were possible, this would be.
415415
add_custom_target(
416-
ccov-ran-${target_code_coverage_COVERAGE_TARGET_NAME}
416+
ccov-profraw-${target_code_coverage_COVERAGE_TARGET_NAME}
417417
DEPENDS ${target_code_coverage_COVERAGE_TARGET_NAME}.profraw)
418418

419419
# Merge the generated profile data so llvm-cov can process it
@@ -424,7 +424,10 @@ function(target_code_coverage TARGET_NAME)
424424
${target_code_coverage_LLVM_PROFDATA_OPTIONS} -sparse
425425
${target_code_coverage_COVERAGE_TARGET_NAME}.profraw -o
426426
${target_code_coverage_COVERAGE_TARGET_NAME}.profdata
427-
DEPENDS ${target_code_coverage_COVERAGE_TARGET_NAME}.profraw)
427+
DEPENDS ccov-profraw-${target_code_coverage_COVERAGE_TARGET_NAME})
428+
add_custom_target(
429+
ccov-profiledata-${target_code_coverage_COVERAGE_TARGET_NAME}
430+
DEPENDS ${target_code_coverage_COVERAGE_TARGET_NAME}.profdata)
428431

429432
# Ignore regex only works on LLVM >= 7
430433
set(EXCLUDE_REGEX)
@@ -447,7 +450,7 @@ function(target_code_coverage TARGET_NAME)
447450
-instr-profile=${target_code_coverage_COVERAGE_TARGET_NAME}.profdata
448451
-show-line-counts-or-regions ${LINKED_OBJECTS} ${EXCLUDE_REGEX}
449452
${target_code_coverage_LLVM_COV_SHOW_OPTIONS}
450-
DEPENDS ${target_code_coverage_COVERAGE_TARGET_NAME}.profdata)
453+
DEPENDS ccov-profiledata-${target_code_coverage_COVERAGE_TARGET_NAME})
451454

452455
# Print out a summary of the coverage information to the command line
453456
add_custom_target(
@@ -457,7 +460,7 @@ function(target_code_coverage TARGET_NAME)
457460
-instr-profile=${target_code_coverage_COVERAGE_TARGET_NAME}.profdata
458461
${LINKED_OBJECTS} ${EXCLUDE_REGEX}
459462
${target_code_coverage_LLVM_COV_REPORT_OPTIONS}
460-
DEPENDS ${target_code_coverage_COVERAGE_TARGET_NAME}.profdata)
463+
DEPENDS ccov-profiledata-${target_code_coverage_COVERAGE_TARGET_NAME})
461464

462465
# Export coverage information so continuous integration tools (e.g.
463466
# Jenkins) can consume it
@@ -469,7 +472,7 @@ function(target_code_coverage TARGET_NAME)
469472
-format="text" ${LINKED_OBJECTS} ${EXCLUDE_REGEX}
470473
${target_code_coverage_LLVM_COV_EXPORT_OPTIONS} >
471474
${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/${target_code_coverage_COVERAGE_TARGET_NAME}.json
472-
DEPENDS ${target_code_coverage_COVERAGE_TARGET_NAME}.profdata)
475+
DEPENDS ccov-profiledata-${target_code_coverage_COVERAGE_TARGET_NAME})
473476

474477
# Only generates HTML output of the coverage information for perusal
475478
add_custom_target(
@@ -481,7 +484,7 @@ function(target_code_coverage TARGET_NAME)
481484
-output-dir=${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/${target_code_coverage_COVERAGE_TARGET_NAME}
482485
-format="html" ${LINKED_OBJECTS} ${EXCLUDE_REGEX}
483486
${target_code_coverage_LLVM_COV_HTML_OPTIONS}
484-
DEPENDS ${target_code_coverage_COVERAGE_TARGET_NAME}.profdata)
487+
DEPENDS ccov-profiledata-${target_code_coverage_COVERAGE_TARGET_NAME})
485488

486489
# Generates HTML output of the coverage information for perusal
487490
add_custom_target(
@@ -570,7 +573,7 @@ function(target_code_coverage TARGET_NAME)
570573
#
571574
# If the option for a hidden target were possible, this would be.
572575
add_custom_target(
573-
ccov-ran-${target_code_coverage_COVERAGE_TARGET_NAME}
576+
ccov-profiledata-${target_code_coverage_COVERAGE_TARGET_NAME}
574577
DEPENDS ${target_code_coverage_COVERAGE_TARGET_NAME}.ccov-run)
575578

576579
add_custom_command(
@@ -638,8 +641,16 @@ function(target_code_coverage TARGET_NAME)
638641
add_dependencies(ccov-all-run
639642
ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME})
640643

641-
add_dependencies(ccov-all-ran
642-
ccov-ran-${target_code_coverage_COVERAGE_TARGET_NAME})
644+
if(CMAKE_C_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_ID MATCHES
645+
"GNU")
646+
add_dependencies(
647+
ccov-all-ran
648+
ccov-profiledata-${target_code_coverage_COVERAGE_TARGET_NAME})
649+
else()
650+
add_dependencies(
651+
ccov-all-ran
652+
ccov-profraw-${target_code_coverage_COVERAGE_TARGET_NAME})
653+
endif()
643654
endif()
644655
endif()
645656
endfunction()
@@ -762,6 +773,9 @@ function(add_code_coverage_all_targets)
762773
${CMAKE_COVERAGE_DATA_DIRECTORY}/all-profraw.list`
763774
DEPENDS ccov-all-ran)
764775
endif()
776+
add_custom_target(
777+
ccov-all-profiledata
778+
DEPENDS ${CMAKE_COVERAGE_DATA_DIRECTORY}/ccov-all.profdata)
765779

766780
# Regex exclude only available for LLVM >= 7
767781
set(EXCLUDE_REGEX)
@@ -787,7 +801,7 @@ function(add_code_coverage_all_targets)
787801
-instr-profile=${CMAKE_COVERAGE_DATA_DIRECTORY}/ccov-all.profdata
788802
${EXCLUDE_REGEX}
789803
${add_code_coverage_all_targets_LLVM_COV_REPORT_OPTIONS}
790-
DEPENDS ${CMAKE_COVERAGE_DATA_DIRECTORY}/ccov-all.profdata)
804+
DEPENDS ccov-all-profiledata)
791805
else()
792806
add_custom_target(
793807
ccov-all-report
@@ -797,7 +811,7 @@ function(add_code_coverage_all_targets)
797811
-instr-profile=${CMAKE_COVERAGE_DATA_DIRECTORY}/ccov-all.profdata
798812
${EXCLUDE_REGEX}
799813
${add_code_coverage_all_targets_LLVM_COV_REPORT_OPTIONS}
800-
DEPENDS ${CMAKE_COVERAGE_DATA_DIRECTORY}/ccov-all.profdata)
814+
DEPENDS ccov-all-profiledata)
801815
endif()
802816

803817
# Export coverage information so continuous integration tools (e.g. Jenkins)
@@ -813,7 +827,7 @@ function(add_code_coverage_all_targets)
813827
-format="text" ${EXCLUDE_REGEX}
814828
${add_code_coverage_all_targets_LLVM_COV_EXPORT_OPTIONS} >
815829
${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/coverage.json
816-
DEPENDS ${CMAKE_COVERAGE_DATA_DIRECTORY}/ccov-all.profdata)
830+
DEPENDS ccov-all-profiledata)
817831
else()
818832
add_custom_target(
819833
ccov-all-export
@@ -824,7 +838,7 @@ function(add_code_coverage_all_targets)
824838
-format="text" ${EXCLUDE_REGEX}
825839
${add_code_coverage_all_targets_LLVM_COV_EXPORT_OPTIONS} >
826840
${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/coverage.json
827-
DEPENDS ${CMAKE_COVERAGE_DATA_DIRECTORY}/ccov-all.profdata)
841+
DEPENDS ccov-all-profiledata)
828842
endif()
829843

830844
# Generate HTML output of all added targets for perusal
@@ -840,7 +854,7 @@ function(add_code_coverage_all_targets)
840854
-output-dir=${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/all-merged
841855
-format="html" ${EXCLUDE_REGEX}
842856
${add_code_coverage_all_targets_LLVM_COV_HTML_OPTIONS}
843-
DEPENDS ${CMAKE_COVERAGE_DATA_DIRECTORY}/ccov-all.profdata)
857+
DEPENDS ccov-all-profiledata)
844858
else()
845859
add_custom_target(
846860
ccov-all
@@ -852,7 +866,7 @@ function(add_code_coverage_all_targets)
852866
-output-dir=${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/all-merged
853867
-format="html" ${EXCLUDE_REGEX}
854868
${add_code_coverage_all_targets_LLVM_COV_HTML_OPTIONS}
855-
DEPENDS ${CMAKE_COVERAGE_DATA_DIRECTORY}/ccov-all.profdata)
869+
DEPENDS ccov-all-profiledata)
856870
endif()
857871

858872
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES

0 commit comments

Comments
 (0)