Browse Source

Pre-compute object file names before Ninja generation

Implement cmGlobalGenerator::ComputeTargetObjects in the Ninja generator
to pre-compute all the object file names.  Use the results during
generation instead of re-computing it later.
Brad King 13 years ago
parent
commit
f5b06cda0f

+ 29 - 0
Source/cmGlobalNinjaGenerator.cxx

@@ -14,6 +14,7 @@
 #include "cmLocalNinjaGenerator.h"
 #include "cmLocalNinjaGenerator.h"
 #include "cmMakefile.h"
 #include "cmMakefile.h"
 #include "cmGeneratedFileStream.h"
 #include "cmGeneratedFileStream.h"
+#include "cmGeneratorTarget.h"
 #include "cmVersion.h"
 #include "cmVersion.h"
 
 
 const char* cmGlobalNinjaGenerator::NINJA_BUILD_FILE = "build.ninja";
 const char* cmGlobalNinjaGenerator::NINJA_BUILD_FILE = "build.ninja";
@@ -499,6 +500,34 @@ bool cmGlobalNinjaGenerator::HasRule(const std::string &name)
   return (rule != this->Rules.end());
   return (rule != this->Rules.end());
 }
 }
 
 
+//----------------------------------------------------------------------------
+// Private virtual overrides
+
+// TODO: Refactor to combine with cmGlobalUnixMakefileGenerator3 impl.
+void cmGlobalNinjaGenerator::ComputeTargetObjects(cmGeneratorTarget* gt) const
+{
+  cmTarget* target = gt->Target;
+
+  // Compute full path to object file directory for this target.
+  std::string dir_max;
+  dir_max += gt->Makefile->GetCurrentOutputDirectory();
+  dir_max += "/";
+  dir_max += gt->LocalGenerator->GetTargetDirectory(*target);
+  dir_max += "/";
+  gt->ObjectDirectory = dir_max;
+
+  // Compute the name of each object file.
+  for(std::vector<cmSourceFile*>::iterator
+        si = gt->ObjectSources.begin();
+      si != gt->ObjectSources.end(); ++si)
+    {
+    cmSourceFile* sf = *si;
+    std::string objectName = gt->LocalGenerator
+      ->GetObjectFileNameWithoutTarget(*sf, dir_max);
+    gt->Objects[sf] = objectName;
+    }
+}
+
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 // Private methods
 // Private methods
 
 

+ 6 - 0
Source/cmGlobalNinjaGenerator.h

@@ -18,6 +18,7 @@
 
 
 class cmLocalGenerator;
 class cmLocalGenerator;
 class cmGeneratedFileStream;
 class cmGeneratedFileStream;
+class cmGeneratorTarget;
 
 
 /**
 /**
  * \class cmGlobalNinjaGenerator
  * \class cmGlobalNinjaGenerator
@@ -235,6 +236,11 @@ protected:
   /// @see cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS()
   /// @see cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS()
   virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() { return true; }
   virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() { return true; }
 
 
+private:
+
+  /// @see cmGlobalGenerator::ComputeTargetObjects
+  virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const;
+
 private:
 private:
   // In order to access the AddDependencyToAll() functions and co.
   // In order to access the AddDependencyToAll() functions and co.
   friend class cmLocalNinjaGenerator;
   friend class cmLocalNinjaGenerator;

+ 0 - 31
Source/cmLocalNinjaGenerator.cxx

@@ -117,37 +117,6 @@ cmGlobalNinjaGenerator* cmLocalNinjaGenerator::GetGlobalNinjaGenerator()
   return static_cast<cmGlobalNinjaGenerator*>(this->GetGlobalGenerator());
   return static_cast<cmGlobalNinjaGenerator*>(this->GetGlobalGenerator());
 }
 }
 
 
-// TODO: Picked up from cmLocalUnixMakefileGenerator3.  Refactor it.
-std::string
-cmLocalNinjaGenerator
-::GetObjectFileName(const cmTarget& target,
-                    const cmSourceFile& source)
-{
-  // Make sure we never hit this old case.
-  if(source.GetProperty("MACOSX_PACKAGE_LOCATION"))
-    {
-    std::string msg = "MACOSX_PACKAGE_LOCATION set on source file: ";
-    msg += source.GetFullPath();
-    this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR,
-                                      msg.c_str());
-    }
-
-  // Start with the target directory.
-  std::string obj = this->GetTargetDirectory(target);
-  obj += "/";
-
-  // Get the object file name without the target directory.
-  std::string dir_max;
-  dir_max += this->Makefile->GetCurrentOutputDirectory();
-  dir_max += "/";
-  dir_max += obj;
-  std::string objectName =
-    this->GetObjectFileNameWithoutTarget(source, dir_max, 0);
-  // Append the object name to the target directory.
-  obj += objectName;
-  return obj;
-}
-
 //----------------------------------------------------------------------------
 //----------------------------------------------------------------------------
 // Virtual protected methods.
 // Virtual protected methods.
 
 

+ 0 - 3
Source/cmLocalNinjaGenerator.h

@@ -59,9 +59,6 @@ public:
   const char* GetConfigName() const
   const char* GetConfigName() const
   { return this->ConfigName.c_str(); }
   { return this->ConfigName.c_str(); }
 
 
-  std::string GetObjectFileName(const cmTarget& target,
-                                const cmSourceFile& source);
-
   /// @return whether we are processing the top CMakeLists.txt file.
   /// @return whether we are processing the top CMakeLists.txt file.
   bool isRootMakefile() const;
   bool isRootMakefile() const;
 
 

+ 4 - 1
Source/cmNinjaTargetGenerator.cxx

@@ -256,7 +256,10 @@ cmNinjaTargetGenerator
   std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
   std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
   if(!path.empty())
   if(!path.empty())
     path += "/";
     path += "/";
-  path += this->LocalGenerator->GetObjectFileName(*this->Target, *source);
+  std::string const& objectName = this->GeneratorTarget->Objects[source];
+  path += this->LocalGenerator->GetTargetDirectory(*this->Target);
+  path += "/";
+  path += objectName;
   return path;
   return path;
 }
 }