Skip to content

Commit 25fe881

Browse files
committed
Add code coverage support on Apple llvm toolchain
When on macOS, if using the Apple-provided toolchain from XCode, also use the same toolchain for code-coverage. The use of hybrid toolchains does not go well.
1 parent 321dbc7 commit 25fe881

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Diff for: code-coverage.cmake

+14-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,20 @@ if(CODE_COVERAGE AND NOT CODE_COVERAGE_ADDED)
100100

101101
if(CMAKE_C_COMPILER_ID MATCHES "(Apple)?[Cc]lang"
102102
OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
103-
# Messages
104-
message(STATUS "Building with llvm Code Coverage Tools")
103+
104+
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang" OR CMAKE_CXX_COMPILER_ID
105+
MATCHES "AppleClang")
106+
# When on macOS and using the Apple-provided toolchain, use the
107+
# XCode-provided llvm toolchain via `xcrun`
108+
message(
109+
STATUS
110+
"Building with XCode-provided llvm code coverage tools (via `xcrun`)")
111+
set(LLVM_COV_PATH xcrun llvm-cov)
112+
set(LLVM_PROFDATA_PATH xcrun llvm-profdata)
113+
else()
114+
# Use the regular llvm toolchain
115+
message(STATUS "Building with llvm code coverage tools")
116+
endif()
105117

106118
if(NOT LLVM_COV_PATH)
107119
message(FATAL_ERROR "llvm-cov not found! Aborting.")

0 commit comments

Comments
 (0)