clang-tidy with precompiled headers and cmake does not work

Viewed 286

I have a simple setup where CMake produces the following compile command:

cd /workspaces/cmake-general/tests/project/build/examples/hello-world && /usr/local/bin/cmake -E __run_co_compile 
--iwyu=/usr/local/bin/include-what-you-use 
--tidy="/usr/bin/clang-tidy;-extra-arg=-Wno-unknown-warning-option;-warnings-as-errors=*;--extra-arg-before=--driver-mode=g++" 
--source=/workspaces/cmake-general/tests/project/build/examples/hello-world/CMakeFiles/example-hello-world.dir/cmake_pch.hxx.cxx -- 
/usr/bin/c++  
-I/workspaces/cmake-general/tests/project/examples/hello-world/src 
-I/workspaces/cmake-general/tests/project/build -O3 -DNDEBUG -stdlib=libc++ 
-fcolor-diagnostics -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wconversion 
-Wsign-conversion -Wnull-dereference -Wdouble-promotion 
-Wformat=2 -Werror -std=c++20 -Winvalid-pch -fpch-instantiate-templates 
-Xclang -emit-pch -Xclang -include 
-Xclang /workspaces/cmake-general/tests/project/build/examples/hello-world/CMakeFiles/example-hello-world.dir/cmake_pch.hxx 
-x c++-header -MD -MT examples/hello-world/CMakeFiles/example-hello-world.dir/cmake_pch.hxx.pch -MF 
CMakeFiles/example-hello-world.dir/cmake_pch.hxx.pch.d -o CMakeFiles/example-hello-world.dir/cmake_pch.hxx.pch 
-c /workspaces/cmake-general/tests/project/build/examples/hello-world/CMakeFiles/example-hello-world.dir/cmake_pch.hxx.cxx  

which errors our with not finding

/workspaces/cmake-general/tests/project/build/examples/example-sanitizer/CMakeFiles/example-sanitizer-address.dir/cmake_pch.hxx:5:10: error: 'iostream' file not found [clang-diagnostic-error]
#include <iostream>
         ^
3 errors generated.

When I take --tidy="..." stuff out of the command. It fully compiles, (also if I dont specify PCHs in the CMakeLists.txt) it works. I am not sure what the problem is exactly.

Do PCH and clang-tidy somehow not work? Why are the include directories somehow missing? I am using LLVM-12, clang-12 on Ubuntu. Also adding -I/usr/lib/llvm-12/include/c++/v1 does not help.

0 Answers
Related