Commit f5b06cda authored by Brad King's avatar Brad King
Browse files

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.
parent a2514f15
......@@ -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";
......@@ -499,6 +500,34 @@ bool cmGlobalNinjaGenerator::HasRule(const std::string &name)
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
......
......@@ -18,6 +18,7 @@
class cmLocalGenerator;
class cmGeneratedFileStream;
class cmGeneratorTarget;
/**
* \class cmGlobalNinjaGenerator
......@@ -235,6 +236,11 @@ protected:
/// @see cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS()
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;
......
......@@ -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.
......
......@@ -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;
......
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment