[Cmake-commits] [cmake-commits] king committed cmLocalVisualStudio6Generator.cxx 1.152 1.153 cmLocalVisualStudio6Generator.h 1.23 1.24

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Jun 16 11:57:20 EDT 2009


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv30233/Source

Modified Files:
	cmLocalVisualStudio6Generator.cxx 
	cmLocalVisualStudio6Generator.h 
Log Message:
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.


Index: cmLocalVisualStudio6Generator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio6Generator.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -C 2 -d -r1.23 -r1.24
*** cmLocalVisualStudio6Generator.h	29 Jan 2008 22:30:34 -0000	1.23
--- cmLocalVisualStudio6Generator.h	16 Jun 2009 15:57:18 -0000	1.24
***************
*** 94,97 ****
--- 94,99 ----
    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, 

Index: cmLocalVisualStudio6Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio6Generator.cxx,v
retrieving revision 1.152
retrieving revision 1.153
diff -C 2 -d -r1.152 -r1.153
*** cmLocalVisualStudio6Generator.cxx	24 Apr 2009 15:18:03 -0000	1.152
--- cmLocalVisualStudio6Generator.cxx	16 Jun 2009 15:57:18 -0000	1.153
***************
*** 35,38 ****
--- 35,90 ----
  }
  
+ //----------------------------------------------------------------------------
+ // 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()
  {
***************
*** 782,876 ****
                                                   const char * /* libName */)
  {
-   std::string customRuleCode = "";
- 
    if (target.GetType() >= cmTarget::UTILITY )
      {
!     return customRuleCode;
      }
  
!   // 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";
!     }
  
!   // 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";
!     }
  
    customRuleCode += "# End Special Build Tool\n";
--- 834,855 ----
                                                   const char * /* libName */)
  {
    if (target.GetType() >= cmTarget::UTILITY )
      {
!     return "";
      }
  
!   std::string customRuleCode = "# Begin Special Build Tool\n";
!   EventWriter event(this, configName, customRuleCode);
  
!   // 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";



More information about the Cmake-commits mailing list