Skip to content

Commit

Permalink
🔨 Add code-coverage target
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwizeshift committed May 22, 2022
1 parent d2aabc7 commit 3c2fdf0
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,37 @@ if (MSL_ENABLE_UNIT_TESTS)
add_subdirectory("test")
endif ()

##############################################################################
# Coverage
##############################################################################

find_program(GCOVR_COMMAND NAMES "gcovr")

if (NOT GCOVR_COMMAND)
message(WARNING "'gcovr' executable not found! Unable to add coverage target")
endif ()

set(coverage_dir "${CMAKE_BINARY_DIR}/coverage-report")

add_custom_target(${PROJECT_NAME}.coverage
COMMENT "Generating code-coverage report"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMAND "${CMAKE_COMMAND}" "-E" "make_directory" "${coverage_dir}"
COMMAND "${GCOVR_COMMAND}" "${PROJECT_BINARY_DIR}"
"--coveralls" "${coverage_dir}/coveralls.json"
"--json" "${coverage_dir}/coverage.json"
"--html-details" "${coverage_dir}/index.html"
"--exclude" "test/.*"
"--exclude" "/usr/.*"
"--exclude" "${CMAKE_BINARY_DIR}/.*"
"--exclude-unreachable-branches"
BYPRODUCTS
"${coverage_dir}/coveralls.json"
"${coverage_dir}/coverage.json"
"${coverage_dir}/index.html"
VERBATIM
)

##############################################################################
# Installation
##############################################################################
Expand Down Expand Up @@ -242,3 +273,8 @@ install(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "${MSL_CMAKE_CONFIG_DESTINATION}"
)

install(
DIRECTORY "${coverage_dir}"
TYPE DOC
)

0 comments on commit 3c2fdf0

Please sign in to comment.