Ninja: Port to cmGeneratorTarget.

This commit is contained in:
Stephen Kelly 2015-10-18 23:13:50 +02:00
parent 4c41e74da5
commit 80de856bb5
8 changed files with 62 additions and 60 deletions

View File

@ -886,7 +886,7 @@ void cmGlobalNinjaGenerator::WriteDisclaimer(std::ostream& os)
<< cmVersion::GetMinorVersion() << "\n\n";
}
void cmGlobalNinjaGenerator::AddDependencyToAll(cmTarget* target)
void cmGlobalNinjaGenerator::AddDependencyToAll(cmGeneratorTarget* target)
{
this->AppendTargetOutputs(target, this->AllDependencies);
}
@ -912,18 +912,16 @@ void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies()
void
cmGlobalNinjaGenerator
::AppendTargetOutputs(cmTarget const* target, cmNinjaDeps& outputs)
::AppendTargetOutputs(cmGeneratorTarget const* target, cmNinjaDeps& outputs)
{
std::string configName =
target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
cmGeneratorTarget *gtgt = this->GetGeneratorTarget(target);
target->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
// for frameworks, we want the real name, not smple name
// frameworks always appear versioned, and the build.ninja
// will always attempt to manage symbolic links instead
// of letting cmOSXBundleGenerator do it.
bool realname = gtgt->IsFrameworkOnApple();
bool realname = target->IsFrameworkOnApple();
switch (target->GetType()) {
case cmState::EXECUTABLE:
@ -932,7 +930,7 @@ cmGlobalNinjaGenerator
case cmState::MODULE_LIBRARY:
{
outputs.push_back(this->ConvertToNinjaPath(
gtgt->GetFullPath(configName, false, realname)));
target->GetFullPath(configName, false, realname)));
break;
}
case cmState::OBJECT_LIBRARY:
@ -962,16 +960,15 @@ cmGlobalNinjaGenerator
void
cmGlobalNinjaGenerator
::AppendTargetDepends(cmTarget const* target, cmNinjaDeps& outputs)
::AppendTargetDepends(cmGeneratorTarget const* target, cmNinjaDeps& outputs)
{
if (target->GetType() == cmState::GLOBAL_TARGET) {
// Global targets only depend on other utilities, which may not appear in
// the TargetDepends set (e.g. "all").
std::set<std::string> const& utils = target->GetUtilities();
std::set<std::string> const& utils = target->Target->GetUtilities();
std::copy(utils.begin(), utils.end(), std::back_inserter(outputs));
} else {
cmGeneratorTarget* gt = this->GetGeneratorTarget(target);
cmTargetDependSet const& targetDeps = this->GetTargetDirectDepends(gt);
cmTargetDependSet const& targetDeps = this->GetTargetDirectDepends(target);
for (cmTargetDependSet::const_iterator i = targetDeps.begin();
i != targetDeps.end(); ++i)
{
@ -979,13 +976,13 @@ cmGlobalNinjaGenerator
{
continue;
}
this->AppendTargetOutputs((*i)->Target, outputs);
this->AppendTargetOutputs(*i, outputs);
}
}
}
void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias,
cmTarget* target) {
cmGeneratorTarget* target) {
cmNinjaDeps outputs;
this->AppendTargetOutputs(target, outputs);
// Mark the target's outputs as ambiguous to ensure that no other target uses

View File

@ -285,9 +285,11 @@ public:
ASD.insert(deps.begin(), deps.end());
}
void AppendTargetOutputs(cmTarget const* target, cmNinjaDeps& outputs);
void AppendTargetDepends(cmTarget const* target, cmNinjaDeps& outputs);
void AddDependencyToAll(cmTarget* target);
void AppendTargetOutputs(cmGeneratorTarget const* target,
cmNinjaDeps& outputs);
void AppendTargetDepends(cmGeneratorTarget const* target,
cmNinjaDeps& outputs);
void AddDependencyToAll(cmGeneratorTarget* target);
void AddDependencyToAll(const std::string& input);
const std::vector<cmLocalGenerator*>& GetLocalGenerators() const {
@ -299,7 +301,7 @@ public:
int GetRuleCmdLength(const std::string& name) {
return RuleCmdLength[name]; }
void AddTargetAlias(const std::string& alias, cmTarget* target);
void AddTargetAlias(const std::string& alias, cmGeneratorTarget* target);
virtual void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
@ -388,7 +390,7 @@ private:
/// The mapping from source file to assumed dependencies.
std::map<std::string, std::set<std::string> > AssumedSourceDependencies;
typedef std::map<std::string, cmTarget*> TargetAliasMap;
typedef std::map<std::string, cmGeneratorTarget*> TargetAliasMap;
TargetAliasMap TargetAliases;
};

View File

@ -89,7 +89,7 @@ void cmLocalNinjaGenerator::Generate()
if (!this->GetGlobalNinjaGenerator()->IsExcluded(
this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0],
*t))
this->GetGlobalNinjaGenerator()->AddDependencyToAll((*t)->Target);
this->GetGlobalNinjaGenerator()->AddDependencyToAll(*t);
delete tg;
}
}
@ -285,14 +285,14 @@ void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
void
cmLocalNinjaGenerator
::AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs)
::AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs)
{
this->GetGlobalNinjaGenerator()->AppendTargetOutputs(target, outputs);
}
void
cmLocalNinjaGenerator
::AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs)
::AppendTargetDepends(cmGeneratorTarget* target, cmNinjaDeps& outputs)
{
this->GetGlobalNinjaGenerator()->AppendTargetDepends(target, outputs);
}
@ -441,7 +441,7 @@ cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
}
void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc,
cmTarget* target)
cmGeneratorTarget* target)
{
this->CustomCommandTargets[cc].insert(target);
}
@ -459,7 +459,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements()
//
// FIXME: This won't work in certain obscure scenarios involving indirect
// dependencies.
std::set<cmTarget*>::iterator j = i->second.begin();
std::set<cmGeneratorTarget*>::iterator j = i->second.begin();
assert(j != i->second.end());
std::vector<std::string> ccTargetDeps;
this->AppendTargetDepends(*j, ccTargetDeps);

View File

@ -58,10 +58,11 @@ public:
std::string BuildCommandLine(const std::vector<std::string> &cmdLines);
void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);
void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs);
void AppendTargetDepends(cmGeneratorTarget* target, cmNinjaDeps& outputs);
void AddCustomCommandTarget(cmCustomCommand const* cc, cmTarget* target);
void AddCustomCommandTarget(cmCustomCommand const* cc,
cmGeneratorTarget* target);
void AppendCustomCommandLines(cmCustomCommandGenerator const& ccg,
std::vector<std::string> &cmdLines);
void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg,
@ -102,7 +103,7 @@ private:
std::string HomeRelativeOutputPath;
typedef std::map<cmCustomCommand const*, std::set<cmTarget*> >
typedef std::map<cmCustomCommand const*, std::set<cmGeneratorTarget*> >
CustomCommandTargetMap;
CustomCommandTargetMap CustomCommandTargets;
};

View File

@ -399,7 +399,6 @@ static int calculateCommandLineLengthLimit(int linkRuleLength)
void cmNinjaNormalTargetGenerator::WriteLinkStatement()
{
cmTarget& target = *this->GetTarget();
cmGeneratorTarget& gt = *this->GetGeneratorTarget();
const std::string cfgName = this->GetConfigName();
std::string targetOutput = ConvertToNinjaPath(
@ -443,7 +442,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
// Write comments.
cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
const cmState::TargetType targetType = target.GetType();
const cmState::TargetType targetType = gt.GetType();
this->GetBuildFileStream()
<< "# Link build statements for "
<< cmState::GetTargetTypeName(targetType)
@ -490,13 +489,13 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
&genTarget,
useWatcomQuote);
if(this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")
&& target.GetType() == cmState::SHARED_LIBRARY)
&& gt.GetType() == cmState::SHARED_LIBRARY)
{
if(target.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
if(gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
{
std::string name_of_def_file
= gt.GetSupportDirectory();
name_of_def_file += "/" + target.GetName();
name_of_def_file += "/" + gt.GetName();
name_of_def_file += ".def ";
vars["LINK_FLAGS"] += " /DEF:";
vars["LINK_FLAGS"] += this->GetLocalGenerator()
@ -505,7 +504,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
}
}
this->addPoolNinjaVariable("JOB_POOL_LINK", &target, vars);
this->addPoolNinjaVariable("JOB_POOL_LINK", &gt, vars);
this->AddModuleDefinitionFlag(vars["LINK_FLAGS"]);
vars["LINK_FLAGS"] = cmGlobalNinjaGenerator
@ -599,9 +598,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
}
const std::vector<cmCustomCommand> *cmdLists[3] = {
&target.GetPreBuildCommands(),
&target.GetPreLinkCommands(),
&target.GetPostBuildCommands()
&gt.Target->GetPreBuildCommands(),
&gt.Target->GetPreLinkCommands(),
&gt.Target->GetPostBuildCommands()
};
std::vector<std::string> preLinkCmdLines, postBuildCmdLines;
@ -626,17 +625,17 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
}
// maybe create .def file from list of objects
if (target.GetType() == cmState::SHARED_LIBRARY &&
if (gt.GetType() == cmState::SHARED_LIBRARY &&
this->GetMakefile()->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS"))
{
if(target.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
if(gt.GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"))
{
std::string cmakeCommand =
this->GetLocalGenerator()->ConvertToOutputFormat(
cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
std::string name_of_def_file
= gt.GetSupportDirectory();
name_of_def_file += "/" + target.GetName();
name_of_def_file += "/" + gt.GetName();
name_of_def_file += ".def";
std::string cmd = cmakeCommand;
cmd += " -E __create_def ";
@ -699,11 +698,11 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
const std::string rspfile =
std::string(cmake::GetCMakeFilesDirectoryPostSlash())
+ target.GetName() + ".rsp";
+ gt.GetName() + ".rsp";
// Gather order-only dependencies.
cmNinjaDeps orderOnlyDeps;
this->GetLocalGenerator()->AppendTargetDepends(this->GetTarget(),
this->GetLocalGenerator()->AppendTargetDepends(this->GetGeneratorTarget(),
orderOnlyDeps);
// Ninja should restat after linking if and only if there are byproducts.
@ -772,8 +771,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
}
// Add aliases for the file name and the target name.
globalGen.AddTargetAlias(this->TargetNameOut, &target);
globalGen.AddTargetAlias(this->GetTargetName(), &target);
globalGen.AddTargetAlias(this->TargetNameOut, &gt);
globalGen.AddTargetAlias(this->GetTargetName(), &gt);
}
//----------------------------------------------------------------------------
@ -781,7 +780,8 @@ void cmNinjaNormalTargetGenerator::WriteObjectLibStatement()
{
// Write a phony output that depends on all object files.
cmNinjaDeps outputs;
this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs);
this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(),
outputs);
cmNinjaDeps depends = this->GetObjects();
this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
"Object library "
@ -791,5 +791,5 @@ void cmNinjaNormalTargetGenerator::WriteObjectLibStatement()
// Add aliases for the target name.
this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
this->GetTarget());
this->GetGeneratorTarget());
}

View File

@ -486,7 +486,8 @@ cmNinjaTargetGenerator
si != customCommands.end(); ++si)
{
cmCustomCommand const* cc = (*si)->GetCustomCommand();
this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget());
this->GetLocalGenerator()->AddCustomCommandTarget(cc,
this->GetGeneratorTarget());
// Record the custom commands for this target. The container is used
// in WriteObjectBuildStatement when called in a loop below.
this->CustomCommands.push_back(cc);
@ -511,7 +512,8 @@ cmNinjaTargetGenerator
}
cmNinjaDeps orderOnlyDeps;
this->GetLocalGenerator()->AppendTargetDepends(this->Target, orderOnlyDeps);
this->GetLocalGenerator()->AppendTargetDepends(this->GeneratorTarget,
orderOnlyDeps);
// Add order-only dependencies on custom command outputs.
for(std::vector<cmCustomCommand const*>::const_iterator
@ -633,7 +635,8 @@ cmNinjaTargetGenerator
ConvertToNinjaPath(objectFileDir),
cmLocalGenerator::SHELL);
this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetTarget(), vars);
this->addPoolNinjaVariable("JOB_POOL_COMPILE",
this->GetGeneratorTarget(), vars);
this->SetMsvcTargetPdbVariable(vars);
@ -782,7 +785,7 @@ cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
void cmNinjaTargetGenerator::addPoolNinjaVariable(
const std::string& pool_property,
cmTarget* target,
cmGeneratorTarget* target,
cmNinjaVars& vars)
{
const char* pool = target->GetProperty(pool_property);

View File

@ -53,9 +53,6 @@ protected:
cmGeneratedFileStream& GetBuildFileStream() const;
cmGeneratedFileStream& GetRulesFileStream() const;
cmTarget* GetTarget() const
{ return this->Target; }
cmGeneratorTarget* GetGeneratorTarget() const
{ return this->GeneratorTarget; }
@ -152,7 +149,7 @@ protected:
std::set<std::string> MacContentFolders;
void addPoolNinjaVariable(const std::string& pool_property,
cmTarget* target,
cmGeneratorTarget* target,
cmNinjaVars& vars);
private:

View File

@ -16,7 +16,6 @@
#include "cmGlobalNinjaGenerator.h"
#include "cmMakefile.h"
#include "cmSourceFile.h"
#include "cmTarget.h"
#include "cmCustomCommandGenerator.h"
cmNinjaUtilityTargetGenerator::cmNinjaUtilityTargetGenerator(
@ -34,8 +33,8 @@ void cmNinjaUtilityTargetGenerator::Generate()
cmNinjaDeps deps, outputs, util_outputs(1, utilCommandName);
const std::vector<cmCustomCommand> *cmdLists[2] = {
&this->GetTarget()->GetPreBuildCommands(),
&this->GetTarget()->GetPostBuildCommands()
&this->GetGeneratorTarget()->Target->GetPreBuildCommands(),
&this->GetGeneratorTarget()->Target->GetPostBuildCommands()
};
bool uses_terminal = false;
@ -66,7 +65,8 @@ void cmNinjaUtilityTargetGenerator::Generate()
{
cmCustomCommandGenerator ccg(*cc, this->GetConfigName(),
this->GetLocalGenerator());
this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget());
this->GetLocalGenerator()->AddCustomCommandTarget(cc,
this->GetGeneratorTarget());
// Depend on all custom command outputs.
const std::vector<std::string>& ccOutputs = ccg.GetOutputs();
@ -78,8 +78,10 @@ void cmNinjaUtilityTargetGenerator::Generate()
}
}
this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs);
this->GetLocalGenerator()->AppendTargetDepends(this->GetTarget(), deps);
this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(),
outputs);
this->GetLocalGenerator()->AppendTargetDepends(this->GetGeneratorTarget(),
deps);
if (commands.empty()) {
this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
@ -140,5 +142,5 @@ void cmNinjaUtilityTargetGenerator::Generate()
}
this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
this->GetTarget());
this->GetGeneratorTarget());
}