소스 검색

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
Cristian Adam 5 년 전
부모
커밋
7e9b9fe918
1개의 변경된 파일13개의 추가작업 그리고 0개의 파일을 삭제
  1. 13 0
      Source/cmGeneratorTarget.cxx

+ 13 - 0
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);
     }
   }