summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2005-04-26 15:08:18 (GMT)
committerBrad King <brad.king@kitware.com>2005-04-26 15:08:18 (GMT)
commit15c7d45ecd787b74eb4a4dc5cafe69bd92351938 (patch)
treeb0425d5816d30613799105d75fc2dca1dc88ae8c
parent2b05a503e4e9a3eacabb2154c8c5319ce776c39d (diff)
downloadCMake-15c7d45ecd787b74eb4a4dc5cafe69bd92351938.zip
CMake-15c7d45ecd787b74eb4a4dc5cafe69bd92351938.tar.gz
CMake-15c7d45ecd787b74eb4a4dc5cafe69bd92351938.tar.bz2
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.
-rw-r--r--Source/cmLocalVisualStudio6Generator.cxx97
-rw-r--r--Source/cmLocalVisualStudio6Generator.h3
2 files changed, 75 insertions, 25 deletions
diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx
index 5c73194..ae19cc7 100644
--- a/Source/cmLocalVisualStudio6Generator.cxx
+++ b/Source/cmLocalVisualStudio6Generator.cxx
@@ -217,35 +217,48 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
this->AddDSPBuildRule();
}
- // for utility targets need custom command since post build doesn't
- // do anything (Visual Studio 7 seems to do this correctly without
- // the hack)
- if (target.GetType() == cmTarget::UTILITY &&
- target.GetPostBuildCommands().size())
+ // For utility targets need custom command since pre- and post-
+ // build does not do anything in Visual Studio 6. In order for the
+ // rules to run in the correct order as custom commands, we need
+ // special care for dependencies. The first rule must depend on all
+ // 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()))
{
+ // Accumulate the dependencies of all the commands.
+ std::vector<std::string> depends;
+ 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)
+ {
+ depends.insert(depends.end(),
+ cr->GetDepends().begin(), cr->GetDepends().end());
+ }
+
+ // Add the pre- and post-build commands in order.
int count = 1;
- for (std::vector<cmCustomCommand>::const_iterator cr =
- target.GetPostBuildCommands().begin();
+ for (std::vector<cmCustomCommand>::const_iterator cr =
+ target.GetPreBuildCommands().begin();
+ cr != target.GetPreBuildCommands().end(); ++cr)
+ {
+ this->AddUtilityCommandHack(target, count++, depends,
+ cr->GetCommandLines());
+ }
+ for (std::vector<cmCustomCommand>::const_iterator cr =
+ target.GetPostBuildCommands().begin();
cr != target.GetPostBuildCommands().end(); ++cr)
{
- char *output = new char [
- strlen(m_Makefile->GetStartOutputDirectory()) +
- strlen(libName) + 30];
- sprintf(output,"%s/%s_force_%i",
- m_Makefile->GetStartOutputDirectory(),
- libName, count);
- const char* no_main_dependency = 0;
- const char* no_comment = 0;
- m_Makefile->AddCustomCommandToOutput(output,
- cr->GetDepends(),
- no_main_dependency,
- cr->GetCommandLines(),
- no_comment);
- cmSourceFile* outsf =
- m_Makefile->GetSourceFileWithOutput(output);
- target.GetSourceFiles().push_back(outsf);
- 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,
const char* source,
const char* command,
diff --git a/Source/cmLocalVisualStudio6Generator.h b/Source/cmLocalVisualStudio6Generator.h
index 6e3d459..c96deb0 100644
--- a/Source/cmLocalVisualStudio6Generator.h
+++ b/Source/cmLocalVisualStudio6Generator.h
@@ -87,6 +87,9 @@ private:
const std::vector<std::string>& depends,
const char* output,
const char* flags);
+ void AddUtilityCommandHack(cmTarget& target, int count,
+ std::vector<std::string>& depends,
+ const cmCustomCommandLines& commandLines);
std::string CreateTargetRules(const cmTarget &target,
const char *libName);