summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2012-03-13 13:30:23 (GMT)
committerBrad King <brad.king@kitware.com>2012-03-16 14:18:35 (GMT)
commitf5b06cda0f187929ac68ed64595c22d4e6ec773c (patch)
tree12e37e06684152c28d588f4d29573c25b3ec3280
parenta2514f15fae34abb6f29dddf6f5cfe8b171a8035 (diff)
downloadCMake-f5b06cda0f187929ac68ed64595c22d4e6ec773c.zip
CMake-f5b06cda0f187929ac68ed64595c22d4e6ec773c.tar.gz
CMake-f5b06cda0f187929ac68ed64595c22d4e6ec773c.tar.bz2
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.
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx29
-rw-r--r--Source/cmGlobalNinjaGenerator.h6
-rw-r--r--Source/cmLocalNinjaGenerator.cxx31
-rw-r--r--Source/cmLocalNinjaGenerator.h3
-rw-r--r--Source/cmNinjaTargetGenerator.cxx5
5 files changed, 39 insertions, 35 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 7c1529b..03c8be9 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -14,6 +14,7 @@
#include "cmLocalNinjaGenerator.h"
#include "cmMakefile.h"
#include "cmGeneratedFileStream.h"
+#include "cmGeneratorTarget.h"
#include "cmVersion.h"
const char* cmGlobalNinjaGenerator::NINJA_BUILD_FILE = "build.ninja";
@@ -500,6 +501,34 @@ bool cmGlobalNinjaGenerator::HasRule(const std::string &name)
}
//----------------------------------------------------------------------------
+// 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
void cmGlobalNinjaGenerator::OpenBuildFileStream()
diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h
index 39df826..3217581 100644
--- a/Source/cmGlobalNinjaGenerator.h
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -18,6 +18,7 @@
class cmLocalGenerator;
class cmGeneratedFileStream;
+class cmGeneratorTarget;
/**
* \class cmGlobalNinjaGenerator
@@ -236,6 +237,11 @@ protected:
virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() { return true; }
private:
+
+ /// @see cmGlobalGenerator::ComputeTargetObjects
+ virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const;
+
+private:
// In order to access the AddDependencyToAll() functions and co.
friend class cmLocalNinjaGenerator;
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index 78072b5..425b219 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -117,37 +117,6 @@ cmGlobalNinjaGenerator* cmLocalNinjaGenerator::GetGlobalNinjaGenerator()
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.
diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h
index 28b431d..ea44b2f 100644
--- a/Source/cmLocalNinjaGenerator.h
+++ b/Source/cmLocalNinjaGenerator.h
@@ -59,9 +59,6 @@ public:
const char* GetConfigName() const
{ return this->ConfigName.c_str(); }
- std::string GetObjectFileName(const cmTarget& target,
- const cmSourceFile& source);
-
/// @return whether we are processing the top CMakeLists.txt file.
bool isRootMakefile() const;
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 23662d9..cc67434 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -256,7 +256,10 @@ cmNinjaTargetGenerator
std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
if(!path.empty())
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;
}