0

The question is about a CMake project that uses Clang as a compiler.

I am building on a Mac, using the Apple Clang that comes with XCode. Since clang-tidy is not included, I installed LLVM from homebrew just for clang-tidy, while still using the native toolchain for everything else.

The problem is when clang-tidy is enabled, it insists on using the header files from LLVM instead of the ones from XCode (which are supposed to be used.

To illustrate the problem here's the (slightly redacted output without clang-tidy:

/opt/homebrew/opt/ccache/libexec/clang++  -I/...redacted.../playground -g -std=c++20 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -mmacosx-version-min=13.2 -O0 -glldb -MD -MT debugbug/CMakeFiles/debugbug.dir/debugbug.cpp.o -MF debugbug/CMakeFiles/debugbug.dir/debugbug.cpp.o.d -o debugbug/CMakeFiles/debugbug.dir/debugbug.cpp.o -c /...redacted.../playground/debugbug/debugbug.cpp
In file included from /...redacted.../playground/debugbug/debugbug.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/map:541:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/__node_handle:63:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/memory:846:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/__memory/allocate_at_least.h:13:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/__memory/allocator_traits.h:298:9: error: no matching function for call to 'construct_at'

When clang-tidy is enabled (from CMakeLists.txt)

if(CLANG_TIDY_ENABLED)
  find_program(CLANG_TIDY_EXECUTABLE NAMES "clang-tidy")
  set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_EXECUTABLE})
endif()

The output shows that a different include path is used:

/opt/homebrew/Cellar/cmake/3.26.0/bin/cmake -E __run_co_compile --tidy="/usr/local/bin/clang-tidy;--extra-arg-before=--driver-mode=g++" --source=/...redacted.../playground/debugbug/debugbug.cpp -- /opt/homebrew/opt/ccache/libexec/clang++  -I/...redacted.../playground -g -std=c++20 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -mmacosx-version-min=13.2 -O0 -glldb -MD -MT debugbug/CMakeFiles/debugbug.dir/debugbug.cpp.o -MF debugbug/CMakeFiles/debugbug.dir/debugbug.cpp.o.d -o debugbug/CMakeFiles/debugbug.dir/debugbug.cpp.o -c /...redacted.../playground/debugbug/debugbug.cpp
/opt/homebrew/Cellar/llvm/15.0.7_1/bin/../include/c++/v1/__memory/allocator_traits.h:298:9: error: no matching function for call to 'construct_at' [clang-diagnostic-error]

Is it possible to make clang-tidy use the same system headers that the compiler uses?

Please keep in mind that this is a shared project, some developers run on Macs, some on Linux, some on WSL, and then there's the CI/CD pipeline that runs on whatever the devops configured; so I can clearly not choose the wine in front of me hardcode the path from my system.

starball
  • 20,030
  • 7
  • 43
  • 238
Alex O
  • 1,429
  • 2
  • 13
  • 20

0 Answers0