Code coverage with Clang
Closed this issue · 1 comments
Proposed patch (can be applied with git apply
if GitHub did not break the formatting):
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 69d23c10..efbcb162 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -254,9 +254,9 @@ endfunction(link_to_fti)
# Coverage is only supported by the GCC compilers
# TODO: Maybe support for CLang is also possible
-if(ENABLE_COVERAGE AND "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
+if(ENABLE_COVERAGE)
set(ADD_CFLAGS "${ADD_CFLAGS} --coverage -O0 -g")
- link_to_fti("gcov")
+ link_to_fti("--coverage")
endif()
set_property(TARGET ${fti_targets} PROPERTY POSITION_INDEPENDENT_CODE True)
Clang and GCC support the --coverage
option but Clang ships with its own flavor of the gcov
library. This is not a problem because one may pass --coverage
also at link time. Here is the relevant excerpt from the latest GCC documentation, Instrumentation Options](https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html):
--coverage
This option is used to compile and link code instrumented for coverage analysis. The option is a synonym for -fprofile-arcs -ftest-coverage (when compiling) and -lgcov (when linking). See the documentation for those options for more details.
I briefly ran a test and found .gcno
files in the build directory afterwards but I did not try to run gcov
on these files.
Fixed, thanks.