-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeCoverage.cmake
More file actions
17 lines (16 loc) · 952 Bytes
/
CodeCoverage.cmake
File metadata and controls
17 lines (16 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function(enable_code_coverage project_name)
if(ENABLE_CODE_COVERAGE)
if("${CMAKE_C_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
target_compile_options(${project_name} INTERFACE -fprofile-instr-generate -fcoverage-mapping)
target_link_options(${project_name} INTERFACE -fprofile-instr-generate -fcoverage-mapping)
elseif(CMAKE_COMPILER_IS_GNUCXX)
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
message(WARNING "Code coverage results with an optimized (non-Debug) build may be misleading")
endif()
target_compile_options(${project_name} INTERFACE --coverage -fprofile-arcs -ftest-coverage)
target_link_options(${project_name} INTERFACE -lgcov --coverage)
else()
message(FATAL_ERROR "Code coverage requires Clang or GCC. Aborting.")
endif()
endif()
endfunction()