cmGeneratorTarget: Add API for target-relative commands.

This commit is contained in:
Stephen Kelly 2015-10-23 00:42:58 +02:00
parent d288b216af
commit 3f8aa62bfb
13 changed files with 71 additions and 49 deletions

View File

@ -833,6 +833,24 @@ const char* cmGeneratorTarget::GetLocation(const std::string& config) const
return location.c_str(); return location.c_str();
} }
std::vector<cmCustomCommand> const&
cmGeneratorTarget::GetPreBuildCommands() const
{
return this->Target->GetPreBuildCommands();
}
std::vector<cmCustomCommand> const&
cmGeneratorTarget::GetPreLinkCommands() const
{
return this->Target->GetPreLinkCommands();
}
std::vector<cmCustomCommand> const&
cmGeneratorTarget::GetPostBuildCommands() const
{
return this->Target->GetPostBuildCommands();
}
bool cmGeneratorTarget::IsImported() const bool cmGeneratorTarget::IsImported() const
{ {
return this->Target->IsImported(); return this->Target->IsImported();
@ -2267,11 +2285,11 @@ cmTargetTraceDependencies
// Queue pre-build, pre-link, and post-build rule dependencies. // Queue pre-build, pre-link, and post-build rule dependencies.
this->CheckCustomCommands( this->CheckCustomCommands(
this->GeneratorTarget->Target->GetPreBuildCommands()); this->GeneratorTarget->GetPreBuildCommands());
this->CheckCustomCommands( this->CheckCustomCommands(
this->GeneratorTarget->Target->GetPreLinkCommands()); this->GeneratorTarget->GetPreLinkCommands());
this->CheckCustomCommands( this->CheckCustomCommands(
this->GeneratorTarget->Target->GetPostBuildCommands()); this->GeneratorTarget->GetPostBuildCommands());
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -33,6 +33,10 @@ public:
bool IsImported() const; bool IsImported() const;
const char *GetLocation(const std::string& config) const; const char *GetLocation(const std::string& config) const;
std::vector<cmCustomCommand> const &GetPreBuildCommands() const;
std::vector<cmCustomCommand> const &GetPreLinkCommands() const;
std::vector<cmCustomCommand> const &GetPostBuildCommands() const;
#define DECLARE_TARGET_POLICY(POLICY) \ #define DECLARE_TARGET_POLICY(POLICY) \
cmPolicies::PolicyStatus GetPolicyStatus ## POLICY () const \ cmPolicies::PolicyStatus GetPolicyStatus ## POLICY () const \
{ return this->PolicyMap.Get(cmPolicies::POLICY); } { return this->PolicyMap.Get(cmPolicies::POLICY); }

View File

@ -392,10 +392,10 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries()
void cmGhsMultiTargetGenerator::WriteCustomCommands() void cmGhsMultiTargetGenerator::WriteCustomCommands()
{ {
WriteCustomCommandsHelper( WriteCustomCommandsHelper(
this->GeneratorTarget->Target->GetPreBuildCommands(), this->GeneratorTarget->GetPreBuildCommands(),
cmTarget::PRE_BUILD); cmTarget::PRE_BUILD);
WriteCustomCommandsHelper( WriteCustomCommandsHelper(
this->GeneratorTarget->Target->GetPostBuildCommands(), this->GeneratorTarget->GetPostBuildCommands(),
cmTarget::POST_BUILD); cmTarget::POST_BUILD);
} }

View File

@ -1469,11 +1469,11 @@ void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases,
cmGeneratorTarget* gtgt) cmGeneratorTarget* gtgt)
{ {
std::vector<cmCustomCommand> const & prebuild std::vector<cmCustomCommand> const & prebuild
= gtgt->Target->GetPreBuildCommands(); = gtgt->GetPreBuildCommands();
std::vector<cmCustomCommand> const & prelink std::vector<cmCustomCommand> const & prelink
= gtgt->Target->GetPreLinkCommands(); = gtgt->GetPreLinkCommands();
std::vector<cmCustomCommand> postbuild std::vector<cmCustomCommand> postbuild
= gtgt->Target->GetPostBuildCommands(); = gtgt->GetPostBuildCommands();
if(gtgt->GetType() == cmState::SHARED_LIBRARY && if(gtgt->GetType() == cmState::SHARED_LIBRARY &&
!gtgt->IsFrameworkOnApple()) !gtgt->IsFrameworkOnApple())

View File

@ -1787,15 +1787,15 @@ void cmLocalUnixMakefileGenerator3
// Global targets store their rules in pre- and post-build commands. // Global targets store their rules in pre- and post-build commands.
this->AppendCustomDepends(depends, this->AppendCustomDepends(depends,
gt->Target->GetPreBuildCommands()); gt->GetPreBuildCommands());
this->AppendCustomDepends(depends, this->AppendCustomDepends(depends,
gt->Target->GetPostBuildCommands()); gt->GetPostBuildCommands());
this->AppendCustomCommands(commands, this->AppendCustomCommands(commands,
gt->Target->GetPreBuildCommands(), gt->GetPreBuildCommands(),
gt, gt,
cmLocalGenerator::START_OUTPUT); cmLocalGenerator::START_OUTPUT);
this->AppendCustomCommands(commands, this->AppendCustomCommands(commands,
gt->Target->GetPostBuildCommands(), gt->GetPostBuildCommands(),
gt, gt,
cmLocalGenerator::START_OUTPUT); cmLocalGenerator::START_OUTPUT);
std::string targetName = gt->GetName(); std::string targetName = gt->GetName();

View File

@ -266,21 +266,21 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
// depend only on the previous rule. // depend only on the previous rule.
if ((target->GetType() == cmState::UTILITY || if ((target->GetType() == cmState::UTILITY ||
target->GetType() == cmState::GLOBAL_TARGET) && target->GetType() == cmState::GLOBAL_TARGET) &&
(!target->Target->GetPreBuildCommands().empty() || (!target->GetPreBuildCommands().empty() ||
!target->Target->GetPostBuildCommands().empty())) !target->GetPostBuildCommands().empty()))
{ {
// Accumulate the dependencies of all the commands. // Accumulate the dependencies of all the commands.
std::vector<std::string> depends; std::vector<std::string> depends;
for (std::vector<cmCustomCommand>::const_iterator cr = for (std::vector<cmCustomCommand>::const_iterator cr =
target->Target->GetPreBuildCommands().begin(); target->GetPreBuildCommands().begin();
cr != target->Target->GetPreBuildCommands().end(); ++cr) cr != target->GetPreBuildCommands().end(); ++cr)
{ {
depends.insert(depends.end(), depends.insert(depends.end(),
cr->GetDepends().begin(), cr->GetDepends().end()); cr->GetDepends().begin(), cr->GetDepends().end());
} }
for (std::vector<cmCustomCommand>::const_iterator cr = for (std::vector<cmCustomCommand>::const_iterator cr =
target->Target->GetPostBuildCommands().begin(); target->GetPostBuildCommands().begin();
cr != target->Target->GetPostBuildCommands().end(); ++cr) cr != target->GetPostBuildCommands().end(); ++cr)
{ {
depends.insert(depends.end(), depends.insert(depends.end(),
cr->GetDepends().begin(), cr->GetDepends().end()); cr->GetDepends().begin(), cr->GetDepends().end());
@ -289,14 +289,14 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
// Add the pre- and post-build commands in order. // Add the pre- and post-build commands in order.
int count = 1; int count = 1;
for (std::vector<cmCustomCommand>::const_iterator cr = for (std::vector<cmCustomCommand>::const_iterator cr =
target->Target->GetPreBuildCommands().begin(); target->GetPreBuildCommands().begin();
cr != target->Target->GetPreBuildCommands().end(); ++cr) cr != target->GetPreBuildCommands().end(); ++cr)
{ {
this->AddUtilityCommandHack(target, count++, depends, *cr); this->AddUtilityCommandHack(target, count++, depends, *cr);
} }
for (std::vector<cmCustomCommand>::const_iterator cr = for (std::vector<cmCustomCommand>::const_iterator cr =
target->Target->GetPostBuildCommands().begin(); target->GetPostBuildCommands().begin();
cr != target->Target->GetPostBuildCommands().end(); ++cr) cr != target->GetPostBuildCommands().end(); ++cr)
{ {
this->AddUtilityCommandHack(target, count++, depends, *cr); this->AddUtilityCommandHack(target, count++, depends, *cr);
} }
@ -838,8 +838,8 @@ cmLocalVisualStudio6Generator::CreateTargetRules(cmGeneratorTarget *target,
// Write the pre-build and pre-link together (VS6 does not support both). // Write the pre-build and pre-link together (VS6 does not support both).
event.Start("PreLink"); event.Start("PreLink");
event.Write(target->Target->GetPreBuildCommands()); event.Write(target->GetPreBuildCommands());
event.Write(target->Target->GetPreLinkCommands()); event.Write(target->GetPreLinkCommands());
cmsys::auto_ptr<cmCustomCommand> pcc( cmsys::auto_ptr<cmCustomCommand> pcc(
this->MaybeCreateImplibDir(target, configName, false)); this->MaybeCreateImplibDir(target, configName, false));
if(pcc.get()) if(pcc.get())
@ -855,7 +855,7 @@ cmLocalVisualStudio6Generator::CreateTargetRules(cmGeneratorTarget *target,
// Write the post-build rules. // Write the post-build rules.
event.Start("PostBuild"); event.Start("PostBuild");
event.Write(target->Target->GetPostBuildCommands()); event.Write(target->GetPostBuildCommands());
event.Finish(); event.Finish();
customRuleCode += "# End Special Build Tool\n"; customRuleCode += "# End Special Build Tool\n";

View File

@ -2021,7 +2021,7 @@ void cmLocalVisualStudio7Generator
const char* tool = const char* tool =
this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool"; this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
event.Start(tool); event.Start(tool);
event.Write(target->Target->GetPreBuildCommands()); event.Write(target->GetPreBuildCommands());
event.Finish(); event.Finish();
// Add pre-link event. // Add pre-link event.
@ -2035,7 +2035,7 @@ void cmLocalVisualStudio7Generator
{ {
addedPrelink = true; addedPrelink = true;
std::vector<cmCustomCommand> commands = std::vector<cmCustomCommand> commands =
target->Target->GetPreLinkCommands(); target->GetPreLinkCommands();
cmGlobalVisualStudioGenerator* gg cmGlobalVisualStudioGenerator* gg
= static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator); = static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
gg->AddSymbolExportCommand( gg->AddSymbolExportCommand(
@ -2045,7 +2045,7 @@ void cmLocalVisualStudio7Generator
} }
if (!addedPrelink) if (!addedPrelink)
{ {
event.Write(target->Target->GetPreLinkCommands()); event.Write(target->GetPreLinkCommands());
} }
cmsys::auto_ptr<cmCustomCommand> pcc( cmsys::auto_ptr<cmCustomCommand> pcc(
this->MaybeCreateImplibDir(target, this->MaybeCreateImplibDir(target,
@ -2059,7 +2059,7 @@ void cmLocalVisualStudio7Generator
// Add post-build event. // Add post-build event.
tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool"; tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
event.Start(tool); event.Start(tool);
event.Write(target->Target->GetPostBuildCommands()); event.Write(target->GetPostBuildCommands());
event.Finish(); event.Finish();
} }

View File

@ -279,11 +279,11 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
{ {
this->LocalGenerator this->LocalGenerator
->AppendCustomCommands(commands, ->AppendCustomCommands(commands,
this->GeneratorTarget->Target->GetPreBuildCommands(), this->GeneratorTarget->GetPreBuildCommands(),
this->GeneratorTarget); this->GeneratorTarget);
this->LocalGenerator this->LocalGenerator
->AppendCustomCommands(commands, ->AppendCustomCommands(commands,
this->GeneratorTarget->Target->GetPreLinkCommands(), this->GeneratorTarget->GetPreLinkCommands(),
this->GeneratorTarget); this->GeneratorTarget);
} }
@ -450,7 +450,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
{ {
this->LocalGenerator-> this->LocalGenerator->
AppendCustomCommands(commands, AppendCustomCommands(commands,
this->GeneratorTarget->Target->GetPostBuildCommands(), this->GeneratorTarget->GetPostBuildCommands(),
this->GeneratorTarget); this->GeneratorTarget);
} }

View File

@ -114,7 +114,7 @@ void cmMakefileLibraryTargetGenerator::WriteObjectLibraryRules()
// Add post-build rules. // Add post-build rules.
this->LocalGenerator-> this->LocalGenerator->
AppendCustomCommands(commands, AppendCustomCommands(commands,
this->GeneratorTarget->Target->GetPostBuildCommands(), this->GeneratorTarget->GetPostBuildCommands(),
this->GeneratorTarget); this->GeneratorTarget);
// Depend on the object files. // Depend on the object files.
@ -458,11 +458,11 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
{ {
this->LocalGenerator this->LocalGenerator
->AppendCustomCommands(commands, ->AppendCustomCommands(commands,
this->GeneratorTarget->Target->GetPreBuildCommands(), this->GeneratorTarget->GetPreBuildCommands(),
this->GeneratorTarget); this->GeneratorTarget);
this->LocalGenerator this->LocalGenerator
->AppendCustomCommands(commands, ->AppendCustomCommands(commands,
this->GeneratorTarget->Target->GetPreLinkCommands(), this->GeneratorTarget->GetPreLinkCommands(),
this->GeneratorTarget); this->GeneratorTarget);
} }
@ -814,7 +814,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
{ {
this->LocalGenerator-> this->LocalGenerator->
AppendCustomCommands(commands, AppendCustomCommands(commands,
this->GeneratorTarget->Target->GetPostBuildCommands(), this->GeneratorTarget->GetPostBuildCommands(),
this->GeneratorTarget); this->GeneratorTarget);
} }

View File

@ -67,20 +67,20 @@ void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
// Utility targets store their rules in pre- and post-build commands. // Utility targets store their rules in pre- and post-build commands.
this->LocalGenerator->AppendCustomDepends this->LocalGenerator->AppendCustomDepends
(depends, this->GeneratorTarget->Target->GetPreBuildCommands()); (depends, this->GeneratorTarget->GetPreBuildCommands());
this->LocalGenerator->AppendCustomDepends this->LocalGenerator->AppendCustomDepends
(depends, this->GeneratorTarget->Target->GetPostBuildCommands()); (depends, this->GeneratorTarget->GetPostBuildCommands());
this->LocalGenerator->AppendCustomCommands this->LocalGenerator->AppendCustomCommands
(commands, this->GeneratorTarget->Target->GetPreBuildCommands(), (commands, this->GeneratorTarget->GetPreBuildCommands(),
this->GeneratorTarget); this->GeneratorTarget);
// Depend on all custom command outputs for sources // Depend on all custom command outputs for sources
this->DriveCustomCommands(depends); this->DriveCustomCommands(depends);
this->LocalGenerator->AppendCustomCommands this->LocalGenerator->AppendCustomCommands
(commands, this->GeneratorTarget->Target->GetPostBuildCommands(), (commands, this->GeneratorTarget->GetPostBuildCommands(),
this->GeneratorTarget); this->GeneratorTarget);
// Add dependencies on targets that must be built first. // Add dependencies on targets that must be built first.

View File

@ -598,9 +598,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
} }
const std::vector<cmCustomCommand> *cmdLists[3] = { const std::vector<cmCustomCommand> *cmdLists[3] = {
&gt.Target->GetPreBuildCommands(), &gt.GetPreBuildCommands(),
&gt.Target->GetPreLinkCommands(), &gt.GetPreLinkCommands(),
&gt.Target->GetPostBuildCommands() &gt.GetPostBuildCommands()
}; };
std::vector<std::string> preLinkCmdLines, postBuildCmdLines; std::vector<std::string> preLinkCmdLines, postBuildCmdLines;

View File

@ -33,8 +33,8 @@ void cmNinjaUtilityTargetGenerator::Generate()
cmNinjaDeps deps, outputs, util_outputs(1, utilCommandName); cmNinjaDeps deps, outputs, util_outputs(1, utilCommandName);
const std::vector<cmCustomCommand> *cmdLists[2] = { const std::vector<cmCustomCommand> *cmdLists[2] = {
&this->GetGeneratorTarget()->Target->GetPreBuildCommands(), &this->GetGeneratorTarget()->GetPreBuildCommands(),
&this->GetGeneratorTarget()->Target->GetPostBuildCommands() &this->GetGeneratorTarget()->GetPostBuildCommands()
}; };
bool uses_terminal = false; bool uses_terminal = false;

View File

@ -2814,7 +2814,7 @@ cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
{ {
addedPrelink = true; addedPrelink = true;
std::vector<cmCustomCommand> commands = std::vector<cmCustomCommand> commands =
this->GeneratorTarget->Target->GetPreLinkCommands(); this->GeneratorTarget->GetPreLinkCommands();
this->GlobalGenerator->AddSymbolExportCommand( this->GlobalGenerator->AddSymbolExportCommand(
this->GeneratorTarget, commands, configName); this->GeneratorTarget, commands, configName);
this->WriteEvent("PreLinkEvent", commands, configName); this->WriteEvent("PreLinkEvent", commands, configName);
@ -2823,12 +2823,12 @@ cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
if (!addedPrelink) if (!addedPrelink)
{ {
this->WriteEvent("PreLinkEvent", this->WriteEvent("PreLinkEvent",
this->GeneratorTarget->Target->GetPreLinkCommands(), configName); this->GeneratorTarget->GetPreLinkCommands(), configName);
} }
this->WriteEvent("PreBuildEvent", this->WriteEvent("PreBuildEvent",
this->GeneratorTarget->Target->GetPreBuildCommands(), configName); this->GeneratorTarget->GetPreBuildCommands(), configName);
this->WriteEvent("PostBuildEvent", this->WriteEvent("PostBuildEvent",
this->GeneratorTarget->Target->GetPostBuildCommands(), configName); this->GeneratorTarget->GetPostBuildCommands(), configName);
} }
void cmVisualStudio10TargetGenerator::WriteEvent( void cmVisualStudio10TargetGenerator::WriteEvent(