aminya / project_options

A general-purpose CMake library that provides functions that improve the CMake experience following the best practices.
https://aminya.github.io/project_options/
MIT License
352 stars 52 forks source link

error: PCH file built from a different branch ((clang-1316.0.21.2)) than the compiler () [clang-diagnostic-error] #107

Open ClausKlein opened 2 years ago

ClausKlein commented 2 years ago

task: [test_release] cmake --build ./test/build --config Release
[2/6] Building CXX object CMakeFiles/lib2.dir/Release/src/mylib2/lib.cpp.o
/Users/clausklein/cmake/cmakelib/test/src/mylib2/lib.cpp:22:47: warning: 10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]
  auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1);
                                              ^
Checking /Users/clausklein/cmake/cmakelib/test/src/mylib2/lib.cpp ...
Checking /Users/clausklein/cmake/cmakelib/test/src/mylib2/lib.cpp: FMT_LOCALE=1;CMAKE_INTDIR="Release";NDEBUG=1...
[4/6] Building CXX object CMakeFiles/main.dir/Release/cmake_pch.hxx.pch
Checking /Users/clausklein/cmake/cmakelib/test/build/CMakeFiles/main.dir/cmake_pch.hxx.cxx ...
Checking /Users/clausklein/cmake/cmakelib/test/build/CMakeFiles/main.dir/cmake_pch.hxx.cxx: FMT_LOCALE=1;CMAKE_INTDIR="Release";NDEBUG=1...
[5/6] Building CXX object CMakeFiles/main.dir/Release/src/main/main.cpp.o
FAILED: CMakeFiles/main.dir/Release/src/main/main.cpp.o 
/usr/local/Cellar/cmake/3.22.1/bin/cmake -E __run_co_compile --launcher=/usr/local/bin/ccache --tidy="/usr/local/opt/llvm/bin/clang-tidy;-extra-arg=-Wno-unknown-warning-option;-extra-arg=-std=c++20;--extra-arg-before=--driver-mode=g++" --cppcheck="/usr/local/bin/cppcheck;--template=gcc;--enable=style,performance,warning,portability;--inline-suppr;--suppress=internalAstError;--suppress=unmatchedSuppression;--inconclusive;--std=c++20" --source=/Users/clausklein/cmake/cmakelib/test/src/main/main.cpp -- /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DFMT_LOCALE -DCMAKE_INTDIR=\"Release\" -isystem /Users/clausklein/cmake/cmakelib/test/build/vcpkg_installed/x64-osx/include -isystem /Users/clausklein/cmake/cmakelib/test/build/vcpkg_installed/x64-osx/include/eigen3 -O3 -DNDEBUG -flto=thin -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -fcolor-diagnostics -march=native --coverage -O0 -g -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wconversion -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wformat=2 -Wimplicit-fallthrough -std=c++2a -Winvalid-pch -Xclang -include-pch -Xclang /Users/clausklein/cmake/cmakelib/test/build/CMakeFiles/main.dir/Release/cmake_pch.hxx.pch -Xclang -include -Xclang /Users/clausklein/cmake/cmakelib/test/build/CMakeFiles/main.dir/Release/cmake_pch.hxx -MD -MT CMakeFiles/main.dir/Release/src/main/main.cpp.o -MF CMakeFiles/main.dir/Release/src/main/main.cpp.o.d -o CMakeFiles/main.dir/Release/src/main/main.cpp.o -c /Users/clausklein/cmake/cmakelib/test/src/main/main.cpp
error: PCH file built from a different branch ((clang-1316.0.21.2)) than the compiler () [clang-diagnostic-error]
1 error generated.
Error while processing /Users/clausklein/cmake/cmakelib/test/src/main/main.cpp.
Found compiler error(s).
ninja: build stopped: subcommand failed.
task: Failed to run task "test_install": task: Failed to run task "test_release": exit status 1
bash-3.2$ find . -name '*.pch'
./test/build/CMakeFiles/main.dir/Release/cmake_pch.hxx.pch
bash-3.2$ which gcc
/usr/bin/gcc
bash-3.2$ gcc --version
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: x86_64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
bash-3.2$ 

<!-- POLAR PLEDGE BADGE START -->
## Upvote & Fund

- I am using [Polar.sh](https://polar.sh/aminya) so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.

- Thank you in advance for helping prioritize & fund our backlog.

<a href="https://polar.sh/aminya/project_options/issues/107">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/aminya/project_options/issues/107/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/aminya/project_options/issues/107/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->
ClausKlein commented 2 years ago

The clang-tidy toolchain used has an different version!

bash-3.2$ /usr/local/opt/llvm/bin/clang-tidy -version
Homebrew LLVM version 13.0.0
  Optimized build.
  Default target: x86_64-apple-darwin21.4.0
  Host CPU: skylake
bash-3.2$ 
aminya commented 2 years ago

Is this a clang-tidy bug?

ClausKlein commented 2 years ago

Is this a clang-tidy bug?

I think not. There are often problems with clang-tidy or include-what-you-use when the compiler is g++ or apple-clang++.

I prevented this by disabling PCH option.