Skip to content

Commit 6a0b12a

Browse files
committed
Make the enabling coverage not cached but explicit, force coverage to debug mode to make sure instrumentation is not optimized away and we get accurate coverage.
1 parent 6ebaec3 commit 6a0b12a

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

cmake/idi/functions/idi_code_coverage.cmake

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,20 @@
2424

2525
include_guard(GLOBAL)
2626

27-
option(CODE_COVERAGE "Build targets with code coverage instrumentation. (Requires GCC or Clang)" OFF)
27+
# CODE_COVERAGE is intentionally NOT cached so it must be explicitly passed
28+
# each time: cmake .. -DCODE_COVERAGE=ON
29+
if(NOT DEFINED CODE_COVERAGE)
30+
set(CODE_COVERAGE OFF)
31+
endif()
32+
33+
# Force Debug build type for accurate coverage results
34+
if(CODE_COVERAGE)
35+
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
36+
message(STATUS "[Coverage] CODE_COVERAGE is ON — forcing CMAKE_BUILD_TYPE to Debug (was: '${CMAKE_BUILD_TYPE}')")
37+
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type forced to Debug for coverage" FORCE)
38+
endif()
39+
message(STATUS "[Coverage] *** CODE COVERAGE BUILD ENABLED — Debug mode, no optimizations (-O0 -g) ***")
40+
endif()
2841

2942
# --- Internal global properties for tracking coverage state ---
3043

0 commit comments

Comments
 (0)