Explorar o código

Factor out custom command .rule file path generation

Add cmGlobalGenerator::GenerateRuleFile to compute a generator-specific
rule file location.  This will allow specific generators to override the
location of .rule files without changing the behavior of other
generators.
Brad King %!s(int64=13) %!d(string=hai) anos
pai
achega
369e3464be
Modificáronse 3 ficheiros con 22 adicións e 10 borrados
  1. 15 0
      Source/cmGlobalGenerator.cxx
  2. 3 0
      Source/cmGlobalGenerator.h
  3. 4 10
      Source/cmMakefile.cxx

+ 15 - 0
Source/cmGlobalGenerator.cxx

@@ -2091,6 +2091,21 @@ cmTarget cmGlobalGenerator::CreateGlobalTarget(
   return target;
   return target;
 }
 }
 
 
+//----------------------------------------------------------------------------
+std::string
+cmGlobalGenerator::GenerateRuleFile(std::string const& output) const
+{
+  std::string ruleFile = output;
+  ruleFile += ".rule";
+  const char* dir = this->GetCMakeCFGIntDir();
+  if(dir && dir[0] == '$')
+    {
+    cmSystemTools::ReplaceString(ruleFile, dir,
+                                 cmake::GetCMakeFilesDirectory());
+    }
+  return ruleFile;
+}
+
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 void cmGlobalGenerator::AppendDirectoryForConfig(const char*, const char*,
 void cmGlobalGenerator::AppendDirectoryForConfig(const char*, const char*,
                                                  const char*, std::string&)
                                                  const char*, std::string&)

+ 3 - 0
Source/cmGlobalGenerator.h

@@ -277,6 +277,9 @@ public:
       i.e. "Can I build Debug and Release in the same tree?" */
       i.e. "Can I build Debug and Release in the same tree?" */
   virtual bool IsMultiConfig() { return false; }
   virtual bool IsMultiConfig() { return false; }
 
 
+  /** Generate an <output>.rule file path for a given command output.  */
+  virtual std::string GenerateRuleFile(std::string const& output) const;
+
 protected:
 protected:
   typedef std::vector<cmLocalGenerator*> GeneratorVector;
   typedef std::vector<cmLocalGenerator*> GeneratorVector;
   // for a project collect all its targets by following depend
   // for a project collect all its targets by following depend

+ 4 - 10
Source/cmMakefile.cxx

@@ -948,17 +948,11 @@ cmMakefile::AddCustomCommandToOutput(const std::vector<std::string>& outputs,
   // Generate a rule file if the main dependency is not available.
   // Generate a rule file if the main dependency is not available.
   if(!file)
   if(!file)
     {
     {
+    cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
+
     // Construct a rule file associated with the first output produced.
     // Construct a rule file associated with the first output produced.
-    std::string outName = outputs[0];
-    outName += ".rule";
-    const char* dir =
-      this->LocalGenerator->GetGlobalGenerator()->
-      GetCMakeCFGIntDir();
-    if(dir && dir[0] == '$')
-      {
-      cmSystemTools::ReplaceString(outName, dir,
-                                   cmake::GetCMakeFilesDirectory());
-      }
+    std::string outName = gg->GenerateRuleFile(outputs[0]);
+
     // Check if the rule file already exists.
     // Check if the rule file already exists.
     file = this->GetSource(outName.c_str());
     file = this->GetSource(outName.c_str());
     if(file && file->GetCustomCommand() && !replace)
     if(file && file->GetCustomCommand() && !replace)