Skip to content

Commit 5cd1b66

Browse files
rlalikStableCoder
authored andcommitted
add_code_coverage() checks for CODE_COVERAGE variable
According to the documentation, any code coverage is enabled only when CODE_COVERAGE is enabled. The add_code_coverage() function was not checking for it. This commit fixes it.
1 parent 75b6dfe commit 5cd1b66

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

code-coverage.cmake

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,16 @@ endfunction()
487487
# any subdirectories. To add coverage instrumentation to only specific targets,
488488
# use `target_code_coverage`.
489489
function(add_code_coverage)
490-
if(CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang"
491-
OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
492-
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
493-
add_link_options(-fprofile-instr-generate -fcoverage-mapping)
494-
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES
490+
if(CODE_COVERAGE)
491+
if(CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang"
492+
OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
493+
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
494+
add_link_options(-fprofile-instr-generate -fcoverage-mapping)
495+
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES
495496
"GNU")
496-
add_compile_options(-fprofile-arcs -ftest-coverage)
497-
link_libraries(gcov)
497+
add_compile_options(-fprofile-arcs -ftest-coverage)
498+
link_libraries(gcov)
499+
endif()
498500
endif()
499501
endfunction()
500502

0 commit comments

Comments
 (0)