From 3f373b06b05083d9395250379a2978b5f6085002 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Fri, 9 Jan 2026 13:13:26 +0100 Subject: build: Add build target to generate coverage report This adds a 'make coverage' option to conveniently summarize test coverage. If lcov is installed, it will also automatically generate the HTML summary. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- cmake/compiler.cmake | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'cmake/compiler.cmake') diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake index 4fa0e2ea..6258cca0 100644 --- a/cmake/compiler.cmake +++ b/cmake/compiler.cmake @@ -31,6 +31,18 @@ test_and_set_c_compiler_flag_global(-Wdeclaration-after-statement) test_and_set_c_compiler_flag_global(-Winfinite-recursion) test_and_set_c_compiler_flag_global(-fmax-errors=5) +set(DISABLE_COVERAGE ON CACHE BOOL "Disable code coverage analysis") + +if (NOT DISABLE_COVERAGE) + test_and_set_c_compiler_flag_global(-g) + test_and_set_c_compiler_flag_global(--coverage) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage") + set(ENABLE_COVERAGE ON) +else() + set(ENABLE_COVERAGE OFF) +endif() + if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (Release, Debug, DebugASan, DebugTSan, DebugLSan, DebugUSan, DebugAnalyzer)" FORCE) -- cgit v1.2.3