diff options
author | Brad King <brad.king@kitware.com> | 2009-06-16 15:57:18 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-06-16 15:57:18 (GMT) |
commit | 5129c23cba388a1aecc754bd4c1cb179ba4735d3 (patch) | |
tree | 2e69a877bf983d7cd794a27a6de062ecca18b2fe | |
parent | 66189b0b7970d9270845a2d2ee725a7c357cc0ac (diff) | |
download | CMake-5129c23cba388a1aecc754bd4c1cb179ba4735d3.zip CMake-5129c23cba388a1aecc754bd4c1cb179ba4735d3.tar.gz CMake-5129c23cba388a1aecc754bd4c1cb179ba4735d3.tar.bz2 |
ENH: Refactor VS 6 build event generation
In cmLocalVisualStudio6Generator 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.
-rw-r--r-- | Source/cmLocalVisualStudio6Generator.cxx | 151 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio6Generator.h | 2 |
2 files changed, 67 insertions, 86 deletions
diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index 9373e31..4cf9f6c 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -34,6 +34,58 @@ cmLocalVisualStudio6Generator::~cmLocalVisualStudio6Generator() { } +//---------------------------------------------------------------------------- +// Helper class to write build events. +class cmLocalVisualStudio6Generator::EventWriter +{ +public: + EventWriter(cmLocalVisualStudio6Generator* lg, + const char* config, std::string& code): + LG(lg), Config(config), Code(code), First(true) {} + void Start(const char* event) + { + this->First = true; + this->Event = event; + } + void Finish() + { + this->Code += (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) + { + this->Code += this->Event + "_Cmds="; + this->First = false; + } + else + { + this->Code += "\\\n\t"; + } + this->Code += + this->LG->ConstructScript(cc.GetCommandLines(), + cc.GetWorkingDirectory(), + this->Config, + cc.GetEscapeOldStyle(), + cc.GetEscapeAllowMakeVars(), + "\\\n\t"); + } +private: + cmLocalVisualStudio6Generator* LG; + const char* Config; + std::string& Code; + bool First; + std::string Event; +}; + void cmLocalVisualStudio6Generator::AddHelperCommands() { std::set<cmStdString> lang; @@ -781,97 +833,24 @@ cmLocalVisualStudio6Generator::CreateTargetRules(cmTarget &target, const char* configName, const char * /* libName */) { - std::string customRuleCode = ""; - if (target.GetType() >= cmTarget::UTILITY ) { - return customRuleCode; + return ""; } - // are there any rules? - if (target.GetPreBuildCommands().size() + - target.GetPreLinkCommands().size() + - target.GetPostBuildCommands().size() == 0) - { - return customRuleCode; - } - - customRuleCode = "# Begin Special Build Tool\n"; - - // Write the pre-build and pre-link together (VS6 does not support - // both). Make sure no continuation character is put on the last - // line. - int prelink_total = (static_cast<int>(target.GetPreBuildCommands().size())+ - static_cast<int>(target.GetPreLinkCommands().size())); - int prelink_count = 0; - if(prelink_total > 0) - { - // header stuff - customRuleCode += "PreLink_Cmds="; - } - for (std::vector<cmCustomCommand>::const_iterator cr = - target.GetPreBuildCommands().begin(); - cr != target.GetPreBuildCommands().end(); ++cr) - { - if(prelink_count++ > 0) - { - customRuleCode += "\\\n\t"; - } - customRuleCode += this->ConstructScript(cr->GetCommandLines(), - cr->GetWorkingDirectory(), - configName, - cr->GetEscapeOldStyle(), - cr->GetEscapeAllowMakeVars(), - "\\\n\t"); - } - for (std::vector<cmCustomCommand>::const_iterator cr = - target.GetPreLinkCommands().begin(); - cr != target.GetPreLinkCommands().end(); ++cr) - { - if(prelink_count++ > 0) - { - customRuleCode += "\\\n\t"; - } - customRuleCode += this->ConstructScript(cr->GetCommandLines(), - cr->GetWorkingDirectory(), - configName, - cr->GetEscapeOldStyle(), - cr->GetEscapeAllowMakeVars(), - "\\\n\t"); - } - if(prelink_total > 0) - { - customRuleCode += "\n"; - } + std::string customRuleCode = "# Begin Special Build Tool\n"; + EventWriter event(this, configName, customRuleCode); - // Write the post-build rules. Make sure no continuation character - // is put on the last line. - int postbuild_total = - static_cast<int>(target.GetPostBuildCommands().size()); - int postbuild_count = 0; - if(postbuild_total > 0) - { - customRuleCode += "PostBuild_Cmds="; - } - for (std::vector<cmCustomCommand>::const_iterator cr = - target.GetPostBuildCommands().begin(); - cr != target.GetPostBuildCommands().end(); ++cr) - { - if(postbuild_count++ > 0) - { - customRuleCode += "\\\n\t"; - } - customRuleCode += this->ConstructScript(cr->GetCommandLines(), - cr->GetWorkingDirectory(), - configName, - cr->GetEscapeOldStyle(), - cr->GetEscapeAllowMakeVars(), - "\\\n\t"); - } - if(postbuild_total > 0) - { - customRuleCode += "\n"; - } + // Write the pre-build and pre-link together (VS6 does not support both). + event.Start("PreLink"); + event.Write(target.GetPreBuildCommands()); + event.Write(target.GetPreLinkCommands()); + event.Finish(); + + // Write the post-build rules. + event.Start("PostBuild"); + event.Write(target.GetPostBuildCommands()); + event.Finish(); customRuleCode += "# End Special Build Tool\n"; return customRuleCode; diff --git a/Source/cmLocalVisualStudio6Generator.h b/Source/cmLocalVisualStudio6Generator.h index 22415db..8a46444 100644 --- a/Source/cmLocalVisualStudio6Generator.h +++ b/Source/cmLocalVisualStudio6Generator.h @@ -93,6 +93,8 @@ private: const cmCustomCommand& origCommand); void WriteGroup(const cmSourceGroup *sg, cmTarget& target, std::ostream &fout, const char *libName); + class EventWriter; + friend class EventWriter; std::string CreateTargetRules(cmTarget &target, const char* configName, const char *libName); |