summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalVisualStudio7Generator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-06-12 19:28:48 (GMT)
committerBrad King <brad.king@kitware.com>2009-06-12 19:28:48 (GMT)
commit4a9dd4aad401c6310b4c546aa5442b7f684e7343 (patch)
treea608d73de128db459d87ab67c498fbd1c933847d /Source/cmLocalVisualStudio7Generator.cxx
parent17daa9398ad419daba6431e9cc5c39624ad48beb (diff)
downloadCMake-4a9dd4aad401c6310b4c546aa5442b7f684e7343.zip
CMake-4a9dd4aad401c6310b4c546aa5442b7f684e7343.tar.gz
CMake-4a9dd4aad401c6310b4c546aa5442b7f684e7343.tar.bz2
ENH: Refactor VS 7,8,9 build event generation
In cmLocalVisualStudio7Generator we generate pre-build, pre-link, and post-build events into project files. This refactors the generation code for the three event types into a private EventWriter class to avoid duplicate code.
Diffstat (limited to 'Source/cmLocalVisualStudio7Generator.cxx')
-rw-r--r--Source/cmLocalVisualStudio7Generator.cxx200
1 files changed, 78 insertions, 122 deletions
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx
index bb061ea..72ae0e6 100644
--- a/Source/cmLocalVisualStudio7Generator.cxx
+++ b/Source/cmLocalVisualStudio7Generator.cxx
@@ -549,6 +549,64 @@ private:
bool& flag_handled);
};
+//----------------------------------------------------------------------------
+// Helper class to write build event <Tool .../> elements.
+class cmLocalVisualStudio7Generator::EventWriter
+{
+public:
+ EventWriter(cmLocalVisualStudio7Generator* lg,
+ const char* config, std::ostream& os):
+ LG(lg), Config(config), Stream(os), First(true) {}
+ void Start(const char* tool)
+ {
+ this->First = true;
+ this->Stream << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
+ }
+ void Finish()
+ {
+ this->Stream << (this->First? "" : "\"") << "/>\n";
+ }
+ void Write(std::vector<cmCustomCommand> const& ccs)
+ {
+ for(std::vector<cmCustomCommand>::const_iterator ci = ccs.begin();
+ ci != ccs.end(); ++ci)
+ {
+ this->Write(*ci);
+ }
+ }
+ void Write(cmCustomCommand const& cc)
+ {
+ if(this->First)
+ {
+ const char* comment = cc.GetComment();
+ if(comment && *comment)
+ {
+ this->Stream << "\nDescription=\""
+ << this->LG->EscapeForXML(comment) << "\"";
+ }
+ this->Stream << "\nCommandLine=\"";
+ this->First = false;
+ }
+ else
+ {
+ this->Stream << this->LG->EscapeForXML("\n");
+ }
+ std::string script =
+ this->LG->ConstructScript(cc.GetCommandLines(),
+ cc.GetWorkingDirectory(),
+ this->Config,
+ cc.GetEscapeOldStyle(),
+ cc.GetEscapeAllowMakeVars());
+ this->Stream << this->LG->EscapeForXML(script.c_str());
+ }
+private:
+ cmLocalVisualStudio7Generator* LG;
+ const char* Config;
+ std::ostream& Stream;
+ bool First;
+};
+
+//----------------------------------------------------------------------------
void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
const char* configName,
const char *libName,
@@ -1628,128 +1686,26 @@ void cmLocalVisualStudio7Generator
{
return;
}
- const char* tool = "VCPreBuildEventTool";
- if(this->FortranProject)
- {
- tool = "VFPreBuildEventTool";
- }
- // add the pre build rules
- fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
- bool init = false;
- for (std::vector<cmCustomCommand>::const_iterator cr =
- target.GetPreBuildCommands().begin();
- cr != target.GetPreBuildCommands().end(); ++cr)
- {
- if(!init)
- {
- const char* comment = cr->GetComment();
- if(comment && *comment)
- {
- fout << "\nDescription=\""
- << this->EscapeForXML(comment) << "\"";
- }
- fout << "\nCommandLine=\"";
- init = true;
- }
- else
- {
- fout << this->EscapeForXML("\n");
- }
- std::string script =
- this->ConstructScript(cr->GetCommandLines(),
- cr->GetWorkingDirectory(),
- configName,
- cr->GetEscapeOldStyle(),
- cr->GetEscapeAllowMakeVars());
- fout << this->EscapeForXML(script.c_str()).c_str();
- }
- if (init)
- {
- fout << "\"";
- }
- fout << "/>\n";
-
- // add the pre Link rules
- tool = "VCPreLinkEventTool";
- if(this->FortranProject)
- {
- tool = "VFPreLinkEventTool";
- }
- fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
- init = false;
- for (std::vector<cmCustomCommand>::const_iterator cr =
- target.GetPreLinkCommands().begin();
- cr != target.GetPreLinkCommands().end(); ++cr)
- {
- if(!init)
- {
- const char* comment = cr->GetComment();
- if(comment && *comment)
- {
- fout << "\nDescription=\""
- << this->EscapeForXML(comment) << "\"";
- }
- fout << "\nCommandLine=\"";
- init = true;
- }
- else
- {
- fout << this->EscapeForXML("\n");
- }
- std::string script =
- this->ConstructScript(cr->GetCommandLines(),
- cr->GetWorkingDirectory(),
- configName,
- cr->GetEscapeOldStyle(),
- cr->GetEscapeAllowMakeVars());
- fout << this->EscapeForXML(script.c_str()).c_str();
- }
- if (init)
- {
- fout << "\"";
- }
- fout << "/>\n";
-
- // add the PostBuild rules
- tool = "VCPostBuildEventTool";
- if(this->FortranProject)
- {
- tool = "VFPostBuildEventTool";
- }
- fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"";
- init = false;
- for (std::vector<cmCustomCommand>::const_iterator cr =
- target.GetPostBuildCommands().begin();
- cr != target.GetPostBuildCommands().end(); ++cr)
- {
- if(!init)
- {
- const char* comment = cr->GetComment();
- if(comment && *comment)
- {
- fout << "\nDescription=\""
- << this->EscapeForXML(comment) << "\"";
- }
- fout << "\nCommandLine=\"";
- init = true;
- }
- else
- {
- fout << this->EscapeForXML("\n");
- }
- std::string script =
- this->ConstructScript(cr->GetCommandLines(),
- cr->GetWorkingDirectory(),
- configName,
- cr->GetEscapeOldStyle(),
- cr->GetEscapeAllowMakeVars());
- fout << this->EscapeForXML(script.c_str()).c_str();
- }
- if (init)
- {
- fout << "\"";
- }
- fout << "/>\n";
+ EventWriter event(this, configName, fout);
+
+ // Add pre-build event.
+ const char* tool =
+ this->FortranProject? "VFPreBuildEventTool":"VCPreBuildEventTool";
+ event.Start(tool);
+ event.Write(target.GetPreBuildCommands());
+ event.Finish();
+
+ // Add pre-link event.
+ tool = this->FortranProject? "VFPreLinkEventTool":"VCPreLinkEventTool";
+ event.Start(tool);
+ event.Write(target.GetPreLinkCommands());
+ event.Finish();
+
+ // Add post-build event.
+ tool = this->FortranProject? "VFPostBuildEventTool":"VCPostBuildEventTool";
+ event.Start(tool);
+ event.Write(target.GetPostBuildCommands());
+ event.Finish();
}
void