From 7e9b9fe918cde6d0769ade833b2086c1d89c45ff Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Wed, 26 Feb 2020 15:16:30 +0100 Subject: PCH: Copy the timestamp from an absolute header file If `target_precompile_headers` contains a file from the project, then CMake will set the timestamp for `cmake_pch.h|xx` from that file. This helps with ccache and precompile headers. Fixes: #19923 --- Source/cmGeneratorTarget.cxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 4dfc33d..ad8c19e 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -25,6 +25,7 @@ #include "cmCustomCommand.h" #include "cmCustomCommandGenerator.h" #include "cmCustomCommandLines.h" +#include "cmFileTimes.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorExpression.h" #include "cmGeneratorExpressionContext.h" @@ -3424,6 +3425,7 @@ std::string cmGeneratorTarget::GetPchHeader(const std::string& config, auto pchPrologue = this->Makefile->GetDefinition("CMAKE_PCH_PROLOGUE"); auto pchEpilogue = this->Makefile->GetDefinition("CMAKE_PCH_EPILOGUE"); + std::string firstHeaderOnDisk; { cmGeneratedFileStream file( filename_tmp, false, @@ -3447,6 +3449,11 @@ std::string cmGeneratorTarget::GetPchHeader(const std::string& config, } else { file << "#include \"" << header_bt.Value << "\"\n"; } + + if (cmSystemTools::FileExists(header_bt.Value) && + firstHeaderOnDisk.empty()) { + firstHeaderOnDisk = header_bt.Value; + } } if (language == "CXX") { file << "#endif // __cplusplus\n"; @@ -3458,6 +3465,11 @@ std::string cmGeneratorTarget::GetPchHeader(const std::string& config, file << pchEpilogue << "\n"; } } + + if (!firstHeaderOnDisk.empty()) { + cmFileTimes::Copy(firstHeaderOnDisk, filename_tmp); + } + cmSystemTools::MoveFileIfDifferent(filename_tmp, filename); } } @@ -3516,6 +3528,7 @@ std::string cmGeneratorTarget::GetPchSource(const std::string& config, cmGeneratedFileStream file(filename_tmp); file << "/* generated by CMake */\n"; } + cmFileTimes::Copy(pchHeader, filename_tmp); cmSystemTools::MoveFileIfDifferent(filename_tmp, filename); } } -- cgit v0.12