Browse Source

Precompile Headers: Add precompile header file to source list

The precompile header file will be added to the list of files,
and be part of the newly "Precompile Header File" source group.

Also make sure the sources have the header as dependency.
Cristian Adam 6 years ago
parent
commit
9d2ac86f45
3 changed files with 13 additions and 1 deletions
  1. 10 1
      Source/cmLocalGenerator.cxx
  2. 1 0
      Source/cmMakefile.cxx
  3. 2 0
      Source/cmSourceFile.h

+ 10 - 1
Source/cmLocalGenerator.cxx

@@ -2375,6 +2375,14 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target,
       pch_sf->SetProperty("PCH_EXTENSION", pchExtension.c_str());
     }
 
+    // Add pchHeader to source files, which will
+    // be grouped as "Precompile Header File"
+    auto pchHeader_sf = this->Makefile->GetOrCreateSource(
+      pchHeader, false, cmSourceFileLocationKind::Known);
+    std::string err;
+    pchHeader_sf->ResolveFullPath(&err);
+    target->AddSource(pchHeader);
+
     for (auto& str : { std::ref(useOptionList), std::ref(createOptionList) }) {
       cmSystemTools::ReplaceString(str, "<PCH_HEADER>", pchHeader);
       cmSystemTools::ReplaceString(str, "<PCH_FILE>", pchFile);
@@ -2399,7 +2407,8 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target,
     }
 
     if (!this->GetGlobalGenerator()->IsXcode()) {
-      sf->SetProperty("OBJECT_DEPENDS", pchFile.c_str());
+      sf->AppendProperty("OBJECT_DEPENDS", pchFile.c_str());
+      sf->AppendProperty("OBJECT_DEPENDS", pchHeader.c_str());
       sf->SetProperty("COMPILE_OPTIONS", useOptionList.c_str());
     }
   }

+ 1 - 0
Source/cmMakefile.cxx

@@ -104,6 +104,7 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
   this->AddSourceGroup("", "^.*$");
   this->AddSourceGroup("Source Files", CM_SOURCE_REGEX);
   this->AddSourceGroup("Header Files", CM_HEADER_REGEX);
+  this->AddSourceGroup("Precompile Header File", CM_PCH_REGEX);
   this->AddSourceGroup("CMake Rules", "\\.rule$");
   this->AddSourceGroup("Resources", CM_RESOURCE_REGEX);
   this->AddSourceGroup("Object Files", "\\.(lo|o|obj)$");

+ 2 - 0
Source/cmSourceFile.h

@@ -135,6 +135,8 @@ private:
   "hpj"                                                                       \
   "|bat)$"
 
+#define CM_PCH_REGEX "cmake_pch\\.(h|hxx)$"
+
 #define CM_RESOURCE_REGEX "\\.(pdf|plist|png|jpeg|jpg|storyboard|xcassets)$"
 
 #endif