Browse Source

cmSourceFile: add accessors for PCH source files

`cmLocalGenerator::GetObjectFileNameWithoutTarget` used a heuristic to
detect PCH sources. Use the new special source types to detect them
reliably instead.
Ben Boeckel 3 months ago
parent
commit
7aff0d37b5
3 changed files with 13 additions and 1 deletions
  1. 1 1
      Source/cmLocalGenerator.cxx
  2. 10 0
      Source/cmSourceFile.cxx
  3. 2 0
      Source/cmSourceFile.h

+ 1 - 1
Source/cmLocalGenerator.cxx

@@ -4258,7 +4258,7 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
       objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
     }
   }
-  bool const isPchObject = objectName.find("cmake_pch") != std::string::npos;
+  bool const isPchObject = source.IsPchHeader() || source.IsPchSource();
 
   // Short object path policy selected, use as little info as necessary to
   // select an object name

+ 10 - 0
Source/cmSourceFile.cxx

@@ -34,6 +34,16 @@ void cmSourceFile::SetSpecialSourceType(cmSourceFile::SpecialSourceType type)
   this->SpecialSource = type;
 }
 
+bool cmSourceFile::IsPchHeader() const
+{
+  return this->SpecialSource == SpecialSourceType::PchHeader;
+}
+
+bool cmSourceFile::IsPchSource() const
+{
+  return this->SpecialSource == SpecialSourceType::PchSource;
+}
+
 std::string const& cmSourceFile::GetExtension() const
 {
   return this->Extension;

+ 2 - 0
Source/cmSourceFile.h

@@ -67,6 +67,8 @@ public:
     QtAutogenSource,
   };
   void SetSpecialSourceType(SpecialSourceType type);
+  bool IsPchHeader() const;
+  bool IsPchSource() const;
 
   //! Set/Get a property of this source file
   void SetProperty(std::string const& prop, cmValue value);