Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ccov target dependencies tree #37

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 60 additions & 35 deletions code-coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ function(target_code_coverage TARGET_NAME)
${LLVM_PROFDATA_PATH} merge -sparse
${target_code_coverage_COVERAGE_TARGET_NAME}.profraw -o
${target_code_coverage_COVERAGE_TARGET_NAME}.profdata
DEPENDS ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME})
DEPENDS)

# Ignore regex only works on LLVM >= 7
if(LLVM_COV_VERSION VERSION_GREATER_EQUAL "7.0.0")
Expand Down Expand Up @@ -364,9 +364,9 @@ function(target_code_coverage TARGET_NAME)
${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/${target_code_coverage_COVERAGE_TARGET_NAME}.json
DEPENDS ccov-processing-${target_code_coverage_COVERAGE_TARGET_NAME})

# Generates HTML output of the coverage information for perusal
# Only generates HTML output of the coverage information for perusal
add_custom_target(
ccov-${target_code_coverage_COVERAGE_TARGET_NAME}
ccov-html-${target_code_coverage_COVERAGE_TARGET_NAME}
COMMAND
${LLVM_COV_PATH} show $<TARGET_FILE:${TARGET_NAME}> ${SO_OBJECTS}
-instr-profile=${target_code_coverage_COVERAGE_TARGET_NAME}.profdata
Expand All @@ -375,6 +375,15 @@ function(target_code_coverage TARGET_NAME)
-format="html" ${EXCLUDE_REGEX}
DEPENDS ccov-processing-${target_code_coverage_COVERAGE_TARGET_NAME})

# Generates HTML output of the coverage information for perusal
add_custom_target(
ccov-${target_code_coverage_COVERAGE_TARGET_NAME}
COMMAND
DEPENDS
ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME}
ccov-processing-${target_code_coverage_COVERAGE_TARGET_NAME}
ccov-html-${target_code_coverage_COVERAGE_TARGET_NAME})

elseif(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES
"GNU")
set(COVERAGE_INFO
Expand Down Expand Up @@ -407,38 +416,42 @@ function(target_code_coverage TARGET_NAME)
# Capture coverage data
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
add_custom_target(
ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME}
ccov-clean-${target_code_coverage_COVERAGE_TARGET_NAME}
COMMAND ${CMAKE_COMMAND} -E remove -f ${COVERAGE_INFO}
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters
COMMAND $<TARGET_FILE:${TARGET_NAME}> ${target_code_coverage_ARGS}
COMMAND
${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --base-directory
${CMAKE_SOURCE_DIR} --capture ${EXTERNAL_OPTION} --output-file
${COVERAGE_INFO}
COMMAND ${EXCLUDE_COMMAND}
DEPENDS ccov-preprocessing ${TARGET_NAME})
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters)
else()
add_custom_target(
ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME}
ccov-clean-${target_code_coverage_COVERAGE_TARGET_NAME}
COMMAND ${CMAKE_COMMAND} -E rm -f ${COVERAGE_INFO}
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters
COMMAND $<TARGET_FILE:${TARGET_NAME}> ${target_code_coverage_ARGS}
COMMAND
${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --base-directory
${CMAKE_SOURCE_DIR} --capture ${EXTERNAL_OPTION} --output-file
${COVERAGE_INFO}
COMMAND ${EXCLUDE_COMMAND}
DEPENDS ccov-preprocessing ${TARGET_NAME})
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters)
endif()

# Generates HTML output of the coverage information for perusal
add_custom_target(
ccov-${target_code_coverage_COVERAGE_TARGET_NAME}
ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME}
COMMAND
${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --base-directory
${CMAKE_SOURCE_DIR} --capture ${EXTERNAL_OPTION} --output-file
${COVERAGE_INFO}
COMMAND ${EXCLUDE_COMMAND}
DEPENDS)

# Only generates HTML output of the coverage information for perusal
add_custom_target(
ccov-html-${target_code_coverage_COVERAGE_TARGET_NAME}
COMMAND
${GENHTML_PATH} -o
${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/${target_code_coverage_COVERAGE_TARGET_NAME}
${COVERAGE_INFO}
DEPENDS ccov-capture-${target_code_coverage_COVERAGE_TARGET_NAME})

# Generates HTML output of the coverage information for perusal
add_custom_target(
ccov-${target_code_coverage_COVERAGE_TARGET_NAME}
COMMAND
DEPENDS
ccov-clean-${target_code_coverage_COVERAGE_TARGET_NAME}
ccov-run-${target_code_coverage_COVERAGE_TARGET_NAME}
ccov-html-${target_code_coverage_COVERAGE_TARGET_NAME})
endif()

add_custom_command(
Expand All @@ -456,6 +469,11 @@ function(target_code_coverage TARGET_NAME)
endif()
add_dependencies(ccov ccov-${target_code_coverage_COVERAGE_TARGET_NAME})

if(NOT TARGET ccov-html)
add_custom_target(ccov-html)
endif()
add_dependencies(ccov-html ccov-html-${target_code_coverage_COVERAGE_TARGET_NAME})

Comment on lines +472 to +476
Copy link
Owner

@StableCoder StableCoder May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ccov-html/ccov-html-$TARGET_NAME is only available for GCC with this change. But because it's here, it's being added for both GCC and Clang. Can this be shifted down into the if(GNU) section just underneath?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed that, will fix it.

if(NOT CMAKE_C_COMPILER_ID MATCHES "GNU" AND NOT CMAKE_CXX_COMPILER_ID
MATCHES "GNU")
if(NOT TARGET ccov-report)
Expand Down Expand Up @@ -629,29 +647,36 @@ function(add_code_coverage_all_targets)
# Capture coverage data
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
add_custom_target(
ccov-all-capture
ccov-all-clean
COMMAND ${CMAKE_COMMAND} -E remove -f ${COVERAGE_INFO}
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --capture
--output-file ${COVERAGE_INFO}
COMMAND ${EXCLUDE_COMMAND}
DEPENDS ccov-preprocessing ccov-all-processing)
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters)
else()
add_custom_target(
ccov-all-capture
ccov-all-clean
COMMAND ${CMAKE_COMMAND} -E rm -f ${COVERAGE_INFO}
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --capture
--output-file ${COVERAGE_INFO}
COMMAND ${EXCLUDE_COMMAND}
DEPENDS ccov-preprocessing ccov-all-processing)
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters)
endif()

# Generates HTML output of all targets for perusal
add_custom_target(
ccov-all
ccov-all-capture
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --capture
--output-file ${COVERAGE_INFO}
COMMAND ${EXCLUDE_COMMAND}
DEPENDS)

# Only generates HTML output of all targets for perusal
add_custom_target(
ccov-all-html
COMMAND ${GENHTML_PATH} -o ${CMAKE_COVERAGE_OUTPUT_DIRECTORY}/all-merged
${COVERAGE_INFO} -p ${CMAKE_SOURCE_DIR}
DEPENDS ccov-all-capture)

# Generates HTML output of all targets for perusal
add_custom_target(
ccov-all
COMMAND
DEPENDS ccov-preprocessing ccov-all-processing ccov-all-capture ccov-all-html)

endif()

add_custom_command(
Expand Down