Today I've built clang-tidy from sources, I've built it using clang++. After it has been built I've created a symlink to the executable like this:
ln -s /path/to/build/bin/clang-tidy /usr/local/bin/clang-tidy
Then I've tried to use clang-tidy with cmake on simple project (single .cpp file containing printing helloworld code). This is how my cmake file looks like:
project(Test)
cmake_minimum_required(VERSION 3.12.0 FATAL_ERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_CXX_STANDARD 17)
set(CXX_STANDARD_REQUIRED)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_CLANG_TIDY
clang-tidy;
-checks=*;)
add_executable(Test
helloworld.cpp)
I read somewhere that clang-tidy with cmake only works with Unix Makefiles & Ninja generators (or possibly some else). I usually use xcode generator, but I'm little familiar with those 2 so i didn't really care about others. I've tried to generate and build project with both Unix Makefiles and Ninja, but with both I get this error:
/Users/xxxxxxx/Dev/VSCodePlayground/helloworld.cpp:2:10: error: 'string' file not found [clang-diagnostic-error]
I found some info, that this is probably caused because clang can't find libc++/stdlib headers. So I've tried suggested compilation with -v
argument (which succeeded without errors) and got this output on include dirs:
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
If I understand the issue is that clang-tidy doesn't know the location of headers of libc++ while clang does, am I right? But how should I resolve this and what caused this problem?