diff options
author | Cristian Adam <cristian.adam@gmail.com> | 2020-02-26 14:16:30 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-02-26 15:05:47 (GMT) |
commit | 7e9b9fe918cde6d0769ade833b2086c1d89c45ff (patch) | |
tree | 26de3051794ca9c623694b61fa9dfaba4cb481cd /Source/cmGeneratorTarget.cxx | |
parent | 125f0451a9061c60036c5f92d104ee9fb3111a98 (diff) | |
download | CMake-7e9b9fe918cde6d0769ade833b2086c1d89c45ff.zip CMake-7e9b9fe918cde6d0769ade833b2086c1d89c45ff.tar.gz CMake-7e9b9fe918cde6d0769ade833b2086c1d89c45ff.tar.bz2 |
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
Diffstat (limited to 'Source/cmGeneratorTarget.cxx')
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 13 |
1 files changed, 13 insertions, 0 deletions
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); } } |