Explorar el Código

cmTarget: Make custom command accessors API const.

Add specific mutators instead of providing non-const refs.
Stephen Kelly hace 12 años
padre
commit
50d152035d

+ 1 - 1
Source/cmGlobalGenerator.cxx

@@ -2407,7 +2407,7 @@ cmTarget cmGlobalGenerator::CreateGlobalTarget(
   // Store the custom command in the target.
   cmCustomCommand cc(0, no_outputs, no_depends, *commandLines, 0,
                      workingDirectory);
-  target.GetPostBuildCommands().push_back(cc);
+  target.AddPostBuildCommand(cc);
   target.SetProperty("EchoString", message);
   std::vector<std::string>::iterator dit;
   for ( dit = depends.begin(); dit != depends.end(); ++ dit )

+ 3 - 3
Source/cmMakefile.cxx

@@ -903,13 +903,13 @@ cmMakefile::AddCustomCommandToTarget(const char* target,
     switch(type)
       {
       case cmTarget::PRE_BUILD:
-        ti->second.GetPreBuildCommands().push_back(cc);
+        ti->second.AddPreBuildCommand(cc);
         break;
       case cmTarget::PRE_LINK:
-        ti->second.GetPreLinkCommands().push_back(cc);
+        ti->second.AddPreLinkCommand(cc);
         break;
       case cmTarget::POST_BUILD:
-        ti->second.GetPostBuildCommands().push_back(cc);
+        ti->second.AddPostBuildCommand(cc);
         break;
       }
     }

+ 1 - 1
Source/cmNinjaNormalTargetGenerator.cxx

@@ -534,7 +534,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
     std::replace(linkLibraries.begin(), linkLibraries.end(), '\\', '/');
     }
 
-  std::vector<cmCustomCommand> *cmdLists[3] = {
+  const std::vector<cmCustomCommand> *cmdLists[3] = {
     &this->GetTarget()->GetPreBuildCommands(),
     &this->GetTarget()->GetPreLinkCommands(),
     &this->GetTarget()->GetPostBuildCommands()

+ 1 - 1
Source/cmQtAutoGenerators.cxx

@@ -257,7 +257,7 @@ bool cmQtAutoGenerators::InitializeAutogenTarget(cmTarget* target)
                        workingDirectory.c_str());
     cc.SetEscapeOldStyle(false);
     cc.SetEscapeAllowMakeVars(true);
-    target->GetPreBuildCommands().push_back(cc);
+    target->AddPreBuildCommand(cc);
     }
   else
 #endif

+ 9 - 3
Source/cmTarget.h

@@ -114,12 +114,18 @@ public:
   /**
    * Get the list of the custom commands for this target
    */
-  std::vector<cmCustomCommand> &GetPreBuildCommands()
+  std::vector<cmCustomCommand> const &GetPreBuildCommands() const
     {return this->PreBuildCommands;}
-  std::vector<cmCustomCommand> &GetPreLinkCommands()
+  std::vector<cmCustomCommand> const &GetPreLinkCommands() const
     {return this->PreLinkCommands;}
-  std::vector<cmCustomCommand> &GetPostBuildCommands()
+  std::vector<cmCustomCommand> const &GetPostBuildCommands() const
     {return this->PostBuildCommands;}
+  void AddPreBuildCommand(cmCustomCommand const &cmd)
+    {this->PreBuildCommands.push_back(cmd);}
+  void AddPreLinkCommand(cmCustomCommand const &cmd)
+    {this->PreLinkCommands.push_back(cmd);}
+  void AddPostBuildCommand(cmCustomCommand const &cmd)
+    {this->PostBuildCommands.push_back(cmd);}
 
   /**
    * Get the list of the source files used by this target

+ 3 - 3
Source/cmVisualStudio10TargetGenerator.cxx

@@ -1794,7 +1794,7 @@ cmVisualStudio10TargetGenerator::WriteEvents(std::string const& configName)
 
 void cmVisualStudio10TargetGenerator::WriteEvent(
   const char* name,
-  std::vector<cmCustomCommand> & commands,
+  std::vector<cmCustomCommand> const& commands,
   std::string const& configName)
 {
   if(commands.size() == 0)
@@ -1807,10 +1807,10 @@ void cmVisualStudio10TargetGenerator::WriteEvent(
   std::string script;
   const char* pre = "";
   std::string comment;
-  for(std::vector<cmCustomCommand>::iterator i = commands.begin();
+  for(std::vector<cmCustomCommand>::const_iterator i = commands.begin();
       i != commands.end(); ++i)
     {
-    cmCustomCommand& command = *i;
+    const cmCustomCommand& command = *i;
     comment += pre;
     comment += lg->ConstructComment(command);
     script += pre;

+ 2 - 1
Source/cmVisualStudio10TargetGenerator.h

@@ -87,7 +87,8 @@ private:
   void AddLibraries(cmComputeLinkInformation& cli, std::string& libstring);
   void WriteLibOptions(std::string const& config);
   void WriteEvents(std::string const& configName);
-  void WriteEvent(const char* name, std::vector<cmCustomCommand> & commands,
+  void WriteEvent(const char* name,
+                  std::vector<cmCustomCommand> const& commands,
                   std::string const& configName);
   void WriteGroupSources(const char* name, ToolSources const& sources,
                          std::vector<cmSourceGroup>& );