Makefiles: PCH not properly regenerated after input header file receives new mtime
I am using cmake to compile a complex program (https://github.com/deeptho/neumodvb.git) on linux (fedora 34, 35 and 36). This involves using cmake to generate Makefiles. The compiler is clang. Most of the code is c++
As of cmake version 3.20, and up to the most recent git version I checked out from this repository just now, precompiled headers are not properly generated after changing one of the input include files, for example neumodvb/src/neumodb/cursors.h
Recompiling with "cd build; make" fails with a message like
fatal error: file '/home/xxx/neumodvb/src/neumodb/cursors.h' has been modified since the precompiled header '/home/xxx/neumodvb/build/src/neumodb/schema/CMakeFiles/schema.dir/cmake_pch.hxx.gch' was built: mtime changed (was 1652140672, now 1652140794)
note: please rebuild precompiled header '/home/xxx/neumodvb/build/src/neumodb/schema/CMakeFiles/schema.dir/cmake_pch.hxx.gch'
1 error generated.
make[2]: *** [src/neumodb/schema/CMakeFiles/schema.dir/build.make:109: src/neumodb/schema/CMakeFiles/schema.dir/cmake_pch.hxx.gch] Error 1
make[1]: *** [CMakeFiles/Makefile2:1164: src/neumodb/schema/CMakeFiles/schema.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
Using git bisect, I have narrowed the problem down to the following commit:
2c71d051facad13b0a42a57066be2489d5fff6ea is the first bad commit
commit 2c71d051facad13b0a42a57066be2489d5fff6ea
Author: Marc Chevrier <marc.chevrier@gmail.com>
Date: Sun Oct 18 16:11:27 2020 +0200
Makefiles Generators: use compiler for dependencies generation
Each source compilation generates a dependencies file. These dependencies
files are consolidated in one file per target. This consolidation is done
as part of command 'cmake -E cmake_depends` launched before evaluation of
makefile dependency graph.
The consolidation uses the same approach as `CMake` dependencies management.
Fixes: #21321