diff --git a/cmake/default_coverage.cmake b/cmake/default_coverage.cmake index 4f30777..809a4ec 100644 --- a/cmake/default_coverage.cmake +++ b/cmake/default_coverage.cmake @@ -1,3 +1,6 @@ +include_guard(GLOBAL) + +option(COVERAGE "Enable coverage reporting" OFF) add_library(_DefaultCoverage INTERFACE) @@ -19,6 +22,23 @@ if (COVERAGE) $<$: --coverage> ) + set(COVERAGE_BRANCHES "--rc branch_coverage=1") + set(COVERAGE_WARNINGS "--ignore-errors gcov") + set(GENHTML_WARNINGS "") + if(APPLE) + set(COVERAGE_WARNINGS "--ignore-errors gcov --ignore-errors inconsistent --ignore-errors unused --ignore-errors range --ignore-errors empty,empty") + set(GENHTML_WARNINGS "--ignore-errors inconsistent") + endif() + separate_arguments(COVERAGE_BRANCHES) + separate_arguments(COVERAGE_WARNINGS) + separate_arguments(GENHTML_WARNINGS) + add_custom_target(coverage + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/coverage + COMMAND lcov --directory . --capture --output-file ${CMAKE_BINARY_DIR}/coverage/coverage.info ${COVERAGE_WARNINGS} ${COVERAGE_BRANCHES} + COMMAND lcov --remove ${CMAKE_BINARY_DIR}/coverage/coverage.info '/usr/*' '*/tests/*' '*/_deps/*' '${CMAKE_SOURCE_DIR}/external/*' --output-file ${CMAKE_BINARY_DIR}/coverage/coverage.info.cleaned ${COVERAGE_WARNINGS} ${COVERAGE_BRANCHES} + COMMAND genhtml --branch-coverage ${CMAKE_BINARY_DIR}/coverage/coverage.info.cleaned --output-directory ${CMAKE_BINARY_DIR}/coverage ${GENHTML_WARNINGS} ${COVERAGE_BRANCHES} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) endif(COVERAGE) -add_library(default::coverage ALIAS _DefaultCoverage) \ No newline at end of file +add_library(default::coverage ALIAS _DefaultCoverage) diff --git a/cmake/testing.cmake b/cmake/testing.cmake index 49ffae9..c3cea11 100644 --- a/cmake/testing.cmake +++ b/cmake/testing.cmake @@ -15,7 +15,7 @@ FetchContent_MakeAvailable(doctest) add_library(doctest_main STATIC ${PROJECT_SOURCE_DIR}/tests/test_main.cpp) set(TEST_FRAMEWORK doctest::doctest) -set(THIS_PROJECT_LIBS astr) +set(THIS_PROJECT_LIBS astr default::flags) target_link_libraries(doctest_main PUBLIC ${TEST_FRAMEWORK})