BUG: Fixed ordering of multiple commands in a custom target when implemented as custom commands. Also added support to execute pre-build rules first to be consistent with makefile generator.

This commit is contained in:
Brad King 2005-04-26 11:08:18 -04:00
parent 2b05a503e4
commit 15c7d45ecd
2 changed files with 76 additions and 26 deletions

View File

@ -217,35 +217,48 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
this->AddDSPBuildRule(); this->AddDSPBuildRule();
} }
// for utility targets need custom command since post build doesn't // For utility targets need custom command since pre- and post-
// do anything (Visual Studio 7 seems to do this correctly without // build does not do anything in Visual Studio 6. In order for the
// the hack) // rules to run in the correct order as custom commands, we need
if (target.GetType() == cmTarget::UTILITY && // special care for dependencies. The first rule must depend on all
target.GetPostBuildCommands().size()) // the dependencies of all the rules. The later rules must each
// depend only on the previous rule.
if (target.GetType() == cmTarget::UTILITY &&
(!target.GetPreBuildCommands().empty() ||
!target.GetPostBuildCommands().empty()))
{ {
int count = 1; // Accumulate the dependencies of all the commands.
for (std::vector<cmCustomCommand>::const_iterator cr = std::vector<std::string> depends;
target.GetPostBuildCommands().begin(); for (std::vector<cmCustomCommand>::const_iterator cr =
target.GetPreBuildCommands().begin();
cr != target.GetPreBuildCommands().end(); ++cr)
{
depends.insert(depends.end(),
cr->GetDepends().begin(), cr->GetDepends().end());
}
for (std::vector<cmCustomCommand>::const_iterator cr =
target.GetPostBuildCommands().begin();
cr != target.GetPostBuildCommands().end(); ++cr) cr != target.GetPostBuildCommands().end(); ++cr)
{ {
char *output = new char [ depends.insert(depends.end(),
strlen(m_Makefile->GetStartOutputDirectory()) + cr->GetDepends().begin(), cr->GetDepends().end());
strlen(libName) + 30]; }
sprintf(output,"%s/%s_force_%i",
m_Makefile->GetStartOutputDirectory(), // Add the pre- and post-build commands in order.
libName, count); int count = 1;
const char* no_main_dependency = 0; for (std::vector<cmCustomCommand>::const_iterator cr =
const char* no_comment = 0; target.GetPreBuildCommands().begin();
m_Makefile->AddCustomCommandToOutput(output, cr != target.GetPreBuildCommands().end(); ++cr)
cr->GetDepends(), {
no_main_dependency, this->AddUtilityCommandHack(target, count++, depends,
cr->GetCommandLines(), cr->GetCommandLines());
no_comment); }
cmSourceFile* outsf = for (std::vector<cmCustomCommand>::const_iterator cr =
m_Makefile->GetSourceFileWithOutput(output); target.GetPostBuildCommands().begin();
target.GetSourceFiles().push_back(outsf); cr != target.GetPostBuildCommands().end(); ++cr)
count++; {
delete [] output; this->AddUtilityCommandHack(target, count++, depends,
cr->GetCommandLines());
} }
} }
@ -409,6 +422,40 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
} }
void
cmLocalVisualStudio6Generator
::AddUtilityCommandHack(cmTarget& target, int count,
std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines)
{
// Create a fake output that forces the rule to run.
char* output = new char[(strlen(m_Makefile->GetStartOutputDirectory()) +
strlen(target.GetName()) + 30)];
sprintf(output,"%s/%s_force_%i", m_Makefile->GetStartOutputDirectory(),
target.GetName(), count);
// Add the rule with the given dependencies and commands.
const char* no_main_dependency = 0;
const char* no_comment = 0;
m_Makefile->AddCustomCommandToOutput(output,
depends,
no_main_dependency,
commandLines,
no_comment);
// Replace the dependencies with the output of this rule so that the
// next rule added will run after this one.
depends.clear();
depends.push_back(output);
// Add a source file representing this output to the project.
cmSourceFile* outsf = m_Makefile->GetSourceFileWithOutput(output);
target.GetSourceFiles().push_back(outsf);
// Free the fake output name.
delete [] output;
}
void cmLocalVisualStudio6Generator::WriteCustomRule(std::ostream& fout, void cmLocalVisualStudio6Generator::WriteCustomRule(std::ostream& fout,
const char* source, const char* source,
const char* command, const char* command,

View File

@ -87,6 +87,9 @@ private:
const std::vector<std::string>& depends, const std::vector<std::string>& depends,
const char* output, const char* output,
const char* flags); const char* flags);
void AddUtilityCommandHack(cmTarget& target, int count,
std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines);
std::string CreateTargetRules(const cmTarget &target, std::string CreateTargetRules(const cmTarget &target,
const char *libName); const char *libName);