Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
27e57c2
feat: enabled coverage flags
benthevining Mar 11, 2026
bd281fe
feat: coverage flags
benthevining Mar 11, 2026
1764874
fix: coverage flags
benthevining Mar 11, 2026
d8b6ecb
fix: coverage flags
benthevining Mar 11, 2026
ef04347
fix: coverage flags
benthevining Mar 11, 2026
3f80b21
fix: coverage flags
benthevining Mar 11, 2026
67a7697
fix: using alternate Clang install method
benthevining Mar 11, 2026
0814727
fix: using alternate Clang install method
benthevining Mar 11, 2026
d3b09f9
fix: not installing higher Clang version
benthevining Mar 11, 2026
0111b44
chore: enabling color diagnostics
benthevining Mar 11, 2026
6f0e56b
fix: coverage flags
benthevining Mar 11, 2026
dec5213
fix: coverage flags
benthevining Mar 11, 2026
91b8409
fix: coverage flags
benthevining Mar 11, 2026
0828966
fix: alternate Clang install method
benthevining Mar 11, 2026
7da55b2
fix: pinned GHA to commit hash [skip ci]
benthevining Mar 11, 2026
270d93b
Merge branch 'main' into coverage
benthevining Mar 11, 2026
348e4e0
fix: pinning Github actions to commit SHAs
benthevining Mar 12, 2026
a8d4c15
Merge branch 'main' into coverage
benthevining Mar 12, 2026
435923a
chore: excluding tests/ directory from coverage results
benthevining Mar 13, 2026
78dd317
fix: disabled coverage for UBSAN configuration
benthevining Mar 13, 2026
30750ec
fix(coverage): using generator expression with link_libraries() to on…
benthevining Mar 13, 2026
93dc7e5
fix(coverage): disabling flags when needed
benthevining Mar 13, 2026
300745f
feat: script & custom target for cleaning old coverage output
benthevining Mar 13, 2026
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
7 changes: 4 additions & 3 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@
sudo apt-get update
sudo apt-get install -y libc++-dev libc++abi-dev

# TODO: ensure install of runtime libraries for sanitizers, set LD_LIBRARY_PATH
# TODO: ensure install of runtime libraries for sanitizers, set LD_LIBRARY_PATH
- name: Ensure Clang version
if: runner.os == 'Linux' && matrix.preset == 'clang'
uses: egor-tensin/setup-clang@471a6f8ef1d449dba8e1a51780e7f943572a3f99 # v2.1
uses: aminya/setup-cpp@v1.8.0
with:
version: 21
llvm: 21
clang: 21

- name: Ensure CMake 4.0
uses: lukka/get-cmake@f176ccd3f28bda569c43aae4894f06b2435a3375 # v4.2.3
Expand Down
13 changes: 12 additions & 1 deletion config/cmake/All.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#
# ======================================================================================

include_guard (GLOBAL)

include ("${CMAKE_CURRENT_LIST_DIR}/Sanitizers.cmake")
# include ("${CMAKE_CURRENT_LIST_DIR}/Coverage.cmake")
include ("${CMAKE_CURRENT_LIST_DIR}/Coverage.cmake")
include ("${CMAKE_CURRENT_LIST_DIR}/Warnings.cmake")

# General settings
Expand All @@ -34,3 +36,12 @@ list (JOIN debug_configs "," debug_configs)

set (CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:${debug_configs}>:Debug>" CACHE STRING "")
endblock ()

# Enhance error reporting and compiler messages
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options (-fcolor-diagnostics)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_compile_options (-fdiagnostics-color=always)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND MSVC_VERSION GREATER 1900)
add_compile_options (/diagnostics:column)
endif ()
164 changes: 14 additions & 150 deletions config/cmake/Coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,163 +10,27 @@
#
# ======================================================================================

#[=======================================================================[.rst:
Coverage.cmake
----------------------

Including this module enables support for code coverage reports.

This module sets ``CTEST_COVERAGE_COMMAND`` to ``gcov``'s location, if it can be found.

Variables
^^^^^^^^^^

.. variable:: GCOV_PROGRAM

Path to the ``gcov`` executable.

.. variable:: GENINFO_PROGRAM

Path to the ``geninfo`` executable.

.. variable:: GENHTML_PROGRAM

Path to the ``genhtml`` executable.

Targets
^^^^^^^^^

Each target will only exist if all required tools could be found.

.. target:: coverage-clean

Executes a script to remove all previously generated coverage files from the build tree.
This can be useful if you get test output containing errors mentioning failure to merge
previous coverage output, etc.

.. target:: coverage-report

Builds a coverage report from coverage files found in the build tree. Requires that gcov,
geninfo, and genhtml could all be found.

.. target:: open-coverage

First builds ``coverage-report``, then opens the generated HTML in your default browser.

#]=======================================================================]
# Including this module globally enables coverage flags.

include_guard (GLOBAL)

include (FeatureSummary)

# set up compiler flags to generate coverage output

get_cmake_property (debug_configs DEBUG_CONFIGURATIONS)

if (NOT debug_configs)
set (debug_configs Debug)
endif ()

list (JOIN debug_configs "," debug_configs)

set (config_debug "$<CONFIG:${debug_configs}>")

if (MSVC)
add_compile_options ("$<${config_debug}:/fsanitize-coverage=edge>")
return ()
endif ()

add_compile_options ("$<${config_debug}:--coverage>")
add_link_options ("$<${config_debug}:--coverage>")

if (APPLE)
add_compile_options ("$<${config_debug}:-fprofile-arcs>")
add_link_options ("$<${config_debug}:-fprofile-arcs>")
endif ()

if (CMAKE_C_COMPILER_ID MATCHES "Clang")
add_compile_options (
"$<${config_debug}:-ftest-coverage;-fprofile-instr-generate;-fcoverage-mapping>"
)
endif ()

# add custom target to clean old coverage output

set (COVERAGE_OUTPUT_DIR "${CMAKE_BINARY_DIR}/coverage/$<CONFIG>")
set (COVERAGE_INFO_FILE "${COVERAGE_OUTPUT_DIR}/coverage.info")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
get_cmake_property (debug_configs DEBUG_CONFIGURATIONS)

add_custom_target (
coverage-clean
COMMAND
"${CMAKE_COMMAND}" -D "COVERAGE_OUTPUT_DIR=${COVERAGE_OUTPUT_DIR}" -D
"CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}" -D "CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}" -P
"${CMAKE_CURRENT_LIST_DIR}/detail/DeleteOldCoverageOutput.cmake"
COMMENT "[coverage] - Cleaning old coverage output files..."
VERBATIM
)
if (NOT debug_configs)
set (debug_configs Debug)
endif ()

# set up coverage reports
list (JOIN debug_configs "," debug_configs)

find_program (GCOV_PROGRAM gcov DOC "gcov executable")
find_program (GENINFO_PROGRAM geninfo DOC "geninfo executable")
find_program (GENHTML_PROGRAM genhtml DOC "genhtml executable")
set (config_debug "$<CONFIG:${debug_configs}>")

mark_as_advanced (GCOV_PROGRAM GENINFO_PROGRAM GENHTML_PROGRAM)
add_compile_options ("$<${config_debug}:-g;-O0;--coverage>")
add_link_options ("$<${config_debug}:--coverage>")

add_feature_info (
CoverageReports "GENINFO_PROGRAM AND GENHTML_PROGRAM"
"Custom targets to generate/open coverage report (requires geninfo & genhtml)"
)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
link_libraries (gcov)
endif ()

if (NOT (GENINFO_PROGRAM AND GENHTML_PROGRAM))
return ()
message (STATUS "Coverage enabled")
endif ()

include (FetchContent)

add_custom_command (
OUTPUT "${COVERAGE_INFO_FILE}"
COMMAND
"${GENINFO_PROGRAM}" "${CMAKE_SOURCE_DIR}" --exclude "${FETCHCONTENT_BASE_DIR}" --gcov-tool
"${GCOV_PROGRAM}" --branch-coverage --no-external --follow --forget-test-names
--demangle-cpp --keep-going --rc derive_function_end_line=0 -o "${COVERAGE_INFO_FILE}"
--ignore-errors empty,inconsistent,format,unsupported,category,range,source,unused
COMMENT "[coverage] - Running geninfo on .gcda coverage output files..."
VERBATIM
)

set (index_html "${COVERAGE_OUTPUT_DIR}/index.html")

add_custom_command (
OUTPUT "${index_html}"
COMMAND
"${GENHTML_PROGRAM}" "${COVERAGE_INFO_FILE}" --header-title
"${CMAKE_PROJECT_NAME} coverage report" --prefix "${CMAKE_SOURCE_DIR}" --precision 1
--filter "brace,blank,range,function" --show-zero-columns --suppress-aliases
--simplified-colors --elide-path-mismatch --sort --dark-mode --synthesize-missing
--show-navigation --legend --function-coverage --branch-coverage --demangle-cpp
--forget-test-names --keep-going -o "${COVERAGE_OUTPUT_DIR}" --ignore-errors
empty,inconsistent,format,unsupported,category,range,source
COMMAND "${CMAKE_COMMAND}" -E echo
"Coverage report generated. Open ${index_html} in your browser."
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
DEPENDS "${COVERAGE_INFO_FILE}"
COMMENT "[coverage] - Running genhtml to create coverage report..."
VERBATIM
)

add_custom_target (coverage-report DEPENDS "${index_html}")

set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${COVERAGE_OUTPUT_DIR}")

if (WIN32)
set (open_cmd start)
else ()
set (open_cmd open)
endif ()

add_custom_target (open-coverage COMMAND "${open_cmd}" "${index_html}")

add_dependencies (open-coverage coverage-report)

set_target_properties (coverage-report coverage-clean open-coverage PROPERTIES FOLDER coverage)
4 changes: 2 additions & 2 deletions config/cmake/Warnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Including this module enables some default warnings at directory scope.

include_guard (DIRECTORY)
include_guard (GLOBAL)

if (MSVC)
add_compile_options (
Expand All @@ -35,7 +35,7 @@ if (MSVC)
return ()
endif ()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options (
-pedantic
-pedantic-errors
Expand Down
24 changes: 0 additions & 24 deletions config/cmake/detail/DeleteOldCoverageOutput.cmake

This file was deleted.

Loading