[Cmake-commits] [cmake-commits] king committed cmLocalVisualStudio7Generator.cxx 1.238 1.239 cmLocalVisualStudio7Generator.h 1.51 1.52

cmake-commits at cmake.org cmake-commits at cmake.org
Fri Jun 12 15:28:50 EDT 2009


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

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


Index: cmLocalVisualStudio7Generator.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio7Generator.cxx,v
retrieving revision 1.238
retrieving revision 1.239
diff -C 2 -d -r1.238 -r1.239
*** cmLocalVisualStudio7Generator.cxx	28 Mar 2009 17:02:29 -0000	1.238
--- cmLocalVisualStudio7Generator.cxx	12 Jun 2009 19:28:48 -0000	1.239
***************
*** 550,553 ****
--- 550,611 ----
  };
  
+ //----------------------------------------------------------------------------
+ // 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,
***************
*** 1629,1754 ****
      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";
  }
  
--- 1687,1710 ----
      return;
      }
!   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();
  }
  

Index: cmLocalVisualStudio7Generator.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmLocalVisualStudio7Generator.h,v
retrieving revision 1.51
retrieving revision 1.52
diff -C 2 -d -r1.51 -r1.52
*** cmLocalVisualStudio7Generator.h	30 Apr 2008 17:26:03 -0000	1.51
--- cmLocalVisualStudio7Generator.h	12 Jun 2009 19:28:48 -0000	1.52
***************
*** 124,127 ****
--- 124,130 ----
    friend class cmLocalVisualStudio7GeneratorInternals;
  
+   class EventWriter;
+   friend class EventWriter;
+ 
    cmVS7FlagTable const* ExtraFlagTable;
    std::string ModuleDefinitionFile;



More information about the Cmake-commits mailing list