mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-07 22:30:13 -06:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user