-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Description
Problem
cmake/CodeCoverage.cmake in add_code_coverage_to_target unconditionally links gcov for both C and CXX targets:
target_link_libraries(
${name}
${scope}
$<$<LINK_LANGUAGE:CXX>:${COVERAGE_CXX_LINKER_FLAGS}
gcov>
$<$<LINK_LANGUAGE:C>:${COVERAGE_C_LINKER_FLAGS}
gcov>)On macOS with Apple Clang, libgcov doesn't exist — Clang handles coverage instrumentation via --coverage without needing a separate library. This causes link failures when trying to build with -Dcoverage=ON on macOS.
Fix
Only link gcov when using GCC:
target_link_libraries(
${name}
${scope}
$<$<LINK_LANGUAGE:CXX>:${COVERAGE_CXX_LINKER_FLAGS}>
$<$<LINK_LANGUAGE:C>:${COVERAGE_C_LINKER_FLAGS}>)
# GCC requires explicit libgcov linkage; Clang/Apple Clang handle it via --coverage
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(${name} ${scope} gcov)
endif ()Also note the original generator expressions are malformed — gcov> is inside the $<$<LINK_LANGUAGE:...>:...> expression, meaning it's only linked conditionally on language, but the closing > placement makes it part of the expression value rather than a separate library argument.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels