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

Replace old code coverage with code-coverage.cmake #125

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions cmake/tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake)

# enables sanitizers support using the the `USE_SANITIZER` flag available values are: Address,
# Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined'
if(USE_SANITIZER OR USE_STATIC_ANALYZER)
CPMAddPackage("gh:StableCoder/cmake-scripts#1f822d1fc87c8d7720c074cde8a278b44963c354")
if(USE_SANITIZER OR USE_STATIC_ANALYZER OR CODE_COVERAGE)
CPMAddPackage("gh:StableCoder/cmake-scripts#1d4bcb41000e7a6a0e6ee1350d91f84f03c14320")

include(${cmake-scripts_SOURCE_DIR}/code-coverage.cmake)

if(USE_SANITIZER)
include(${cmake-scripts_SOURCE_DIR}/sanitizers.cmake)
Expand Down
13 changes: 11 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ project(GreeterTests LANGUAGES CXX)
option(ENABLE_TEST_COVERAGE "Enable test coverage" OFF)
option(TEST_INSTALLED_VERSION "Test the version found by find_package" OFF)

set(CODE_COVERAGE ${ENABLE_TEST_COVERAGE})

# --- Import tools ----

include(../cmake/tools.cmake)
Expand Down Expand Up @@ -54,6 +56,13 @@ doctest_discover_tests(GreeterTests)
# ---- code coverage ----

if(ENABLE_TEST_COVERAGE)
target_compile_options(Greeter PUBLIC -O0 -g -fprofile-arcs -ftest-coverage)
target_link_options(Greeter PUBLIC -fprofile-arcs -ftest-coverage)
if(DEFINED ENV{CPM_SOURCE_CACHE})
set(CCOV_EXCLUDES $ENV{CPM_SOURCE_CACHE}/.* $ENV{CPM_SOURCE_CACHE}/*)
endif()
set(CCOV_EXCLUDES ${CMAKE_BINARY_DIR}/.* ${CMAKE_BINARY_DIR}/*)

add_code_coverage_all_targets(EXCLUDE ${CCOV_EXCLUDES})

target_code_coverage(Greeter EXCLUDE ${CCOV_EXCLUDES})
target_code_coverage(GreeterTests AUTO EXCLUDE ${CCOV_EXCLUDES})
endif()