Skip to content

PCH: Clang: Update PCH usage flags to include original header

Sergey Larin requested to merge cerg2010cerg2010/cmake:prec-include into master

Add an additional include flag to PCH usage command line to fix programs that rely on compile_commands.json file. Pass it to the preprocessor directly to avoid compiler driver to change it to '-include-pch'.

When preprocessor is requested to preprocess a file, it tries to get the original filename from '.pch' and uses that file for preprocessing. CMake generates a '.pch' file from the '.hxx' file by passing an empty '.cxx' source file to the compiler as a compilation unit and the header file with the '-include' flag. After that, compiler puts compilation unit filename in the '.pch' as the original filename.

However, CMake build system uses empty file as the source file and passes the header file using '-include-pch' flag. As a result, Clang uses the wrong file for preprocessing and produces the corrupted preprocessed file.

Fixes: #20355 (closed)
Backport: release
Topic-rename: pch-create-via-include

Edited by Brad King

Merge request reports