Ver Fonte

added for each command

Ken Martin há 24 anos atrás
pai
commit
4ab2650802

+ 4 - 0
Source/cmCommands.cxx

@@ -19,12 +19,14 @@
 #include "cmConfigureGccXmlCommand.cxx"
 #include "cmElseCommand.cxx"
 #include "cmEnableTestingCommand.cxx"
+#include "cmEndForEachCommand.cxx"
 #include "cmEndIfCommand.cxx"
 #include "cmExecProgramCommand.cxx"
 #include "cmFindFileCommand.cxx"
 #include "cmFindLibraryCommand.cxx"
 #include "cmFindPathCommand.cxx"
 #include "cmFindProgramCommand.cxx"
+#include "cmForEachCommand.cxx"
 #include "cmGetFilenameComponentCommand.cxx"
 #include "cmIfCommand.cxx"
 #include "cmIncludeCommand.cxx"
@@ -71,12 +73,14 @@ void GetPredefinedCommands(std::list<cmCommand*>& commands)
   commands.push_back(new cmConfigureGccXmlCommand);
   commands.push_back(new cmElseCommand);
   commands.push_back(new cmEnableTestingCommand);  
+  commands.push_back(new cmEndForEachCommand);
   commands.push_back(new cmEndIfCommand);
   commands.push_back(new cmExecProgramCommand);
   commands.push_back(new cmFindFileCommand);
   commands.push_back(new cmFindLibraryCommand);
   commands.push_back(new cmFindPathCommand);
   commands.push_back(new cmFindProgramCommand);
+  commands.push_back(new cmForEachCommand);
   commands.push_back(new cmGetFilenameComponentCommand);
   commands.push_back(new cmIfCommand);
   commands.push_back(new cmIncludeCommand);

+ 3 - 3
Source/cmFunctionBlocker.h

@@ -56,7 +56,7 @@ public:
    * should a function be blocked
    */
   virtual bool IsFunctionBlocked(const char *name, const std::vector<std::string> &args, 
-                                 const cmMakefile &mf) const = 0;
+                                 cmMakefile &mf) = 0;
 
   /**
    * should this function blocker be removed, useful when one function adds a
@@ -64,14 +64,14 @@ public:
    */
   virtual bool ShouldRemove(const char *name, 
                             const std::vector<std::string> &args, 
-                            const cmMakefile &mf) const {return false;}
+                            cmMakefile &mf) {return false;}
 
   /**
    * When the end of a CMakeList file is reached this method is called.  It
    * is not called on the end of an INCLUDE cmake file, just at the end of a
    * regular CMakeList file 
    */
-  virtual void ScopeEnded(const cmMakefile &mf) const {}
+  virtual void ScopeEnded(cmMakefile &mf) {}
 
   virtual ~cmFunctionBlocker() {}
 };

+ 3 - 3
Source/cmIfCommand.cxx

@@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 bool cmIfFunctionBlocker::
 IsFunctionBlocked(const char *name, const std::vector<std::string> &args, 
-                  const cmMakefile &mf) const
+                  cmMakefile &mf)
 {
   if (!strcmp(name,"ELSE") || !strcmp(name,"ENDIF"))
     {
@@ -63,13 +63,13 @@ IsFunctionBlocked(const char *name, const std::vector<std::string> &args,
 
 bool cmIfFunctionBlocker::
 ShouldRemove(const char *name, const std::vector<std::string> &args, 
-             const cmMakefile &mf) const
+             cmMakefile &mf) 
 {
   return !this->IsFunctionBlocked(name,args,mf);
 }
 
 void cmIfFunctionBlocker::
-ScopeEnded(const cmMakefile &mf) const
+ScopeEnded(cmMakefile &mf)
 {
   cmSystemTools::Error("The end of a CMakeLists file was reached with an IF statement that was not closed properly. Within the directory: ", 
                        mf.GetCurrentDirectory(),

+ 3 - 3
Source/cmIfCommand.h

@@ -57,11 +57,11 @@ public:
   virtual ~cmIfFunctionBlocker() {}
   virtual bool IsFunctionBlocked(const char *name, 
                                  const std::vector<std::string> &args, 
-                                 const cmMakefile &mf) const;
+                                 cmMakefile &mf);
   virtual bool ShouldRemove(const char *name, 
                             const std::vector<std::string> &args, 
-                            const cmMakefile &mf) const;
-  virtual void ScopeEnded(const cmMakefile &mf) const;
+                            cmMakefile &mf);
+  virtual void ScopeEnded(cmMakefile &mf);
   
   std::string m_Define;
   bool m_Not;

+ 49 - 41
Source/cmMakefile.cxx

@@ -217,6 +217,52 @@ void cmMakefile::Print() const
     }
 }
 
+
+      
+void cmMakefile::ExecuteCommand(std::string &name,
+                                std::vector<std::string> &arguments)
+{
+  RegisteredCommandsMap::iterator pos = m_Commands.find(name);
+  if(pos != m_Commands.end())
+    {
+    cmCommand* rm = (*pos).second;
+    cmCommand* usedCommand = rm->Clone();
+    usedCommand->SetMakefile(this);
+    bool keepCommand = false;
+    if(usedCommand->GetEnabled())
+      {
+      // if not running in inherit mode or
+      // if the command is inherited then InitialPass it.
+      if(!m_Inheriting || usedCommand->IsInherited())
+        {
+        if(!usedCommand->InitialPass(arguments))
+          {
+          cmSystemTools::Error(usedCommand->GetName(),
+                               ": Error : \n",
+                               usedCommand->GetError(),
+                               m_cmCurrentDirectory.c_str());
+          }
+        else
+          {
+          // use the command
+          keepCommand = true;
+          m_UsedCommands.push_back(usedCommand);
+          }
+        }
+      }
+    // if the Cloned command was not used 
+    // then delete it
+    if(!keepCommand)
+      {
+      delete usedCommand;
+      }
+    }
+  else
+    {
+    cmSystemTools::Error("unknown CMake command ", name.c_str());
+    }
+}
+
 // Parse the given CMakeLists.txt file into a list of classes.
 // Reads in current CMakeLists file and all parent CMakeLists files
 // executing all inherited commands in the parents
@@ -273,7 +319,7 @@ bool cmMakefile::ReadListFile(const char* filename, const char* external)
   //
   //   this might, or might not be true, irrespective if we are
   //   off looking at an external makefile.
-  bool inheriting = (m_cmCurrentDirectory != m_cmStartDirectory);
+  m_Inheriting = (m_cmCurrentDirectory != m_cmStartDirectory);
                     
   // Now read the input file
   const char *filenametoread= filename;
@@ -299,45 +345,7 @@ bool cmMakefile::ReadListFile(const char* filename, const char* external)
     if(cmSystemTools::ParseFunction(fin, name, arguments) &&
        !this->IsFunctionBlocked(name.c_str(),arguments))
       {
-      RegisteredCommandsMap::iterator pos = m_Commands.find(name);
-      if(pos != m_Commands.end())
-        {
-        cmCommand* rm = (*pos).second;
-        cmCommand* usedCommand = rm->Clone();
-        usedCommand->SetMakefile(this);
-        bool keepCommand = false;
-        if(usedCommand->GetEnabled())
-          {
-          // if not running in inherit mode or
-          // if the command is inherited then InitialPass it.
-          if(!inheriting || usedCommand->IsInherited())
-            {
-            if(!usedCommand->InitialPass(arguments))
-              {
-              cmSystemTools::Error(usedCommand->GetName(),
-                                   ": Error : \n",
-                                   usedCommand->GetError(),
-                                   m_cmCurrentDirectory.c_str());
-              }
-            else
-              {
-              // use the command
-              keepCommand = true;
-              m_UsedCommands.push_back(usedCommand);
-              }
-            }
-          }
-        // if the Cloned command was not used 
-        // then delete it
-        if(!keepCommand)
-          {
-          delete usedCommand;
-          }
-        }
-      else
-        {
-        cmSystemTools::Error("unknown CMake command ", name.c_str(), filename);
-        }
+      this->ExecuteCommand(name,arguments);
       }
     }
 
@@ -923,7 +931,7 @@ cmMakefile::FindSourceGroup(const char* source,
 
 
 bool cmMakefile::IsFunctionBlocked(const char *name,
-                                   std::vector<std::string> &args) const
+                                   std::vector<std::string> &args)
 {
   // loop over all function blockers to see if any block this command
   std::set<cmFunctionBlocker *>::const_iterator pos;

+ 9 - 1
Source/cmMakefile.h

@@ -493,6 +493,13 @@ public:
   void RegisterData(const char*, cmData*);
   cmData* LookupData(const char*) const;
   
+  /**
+   * execute a single CMake command
+   */
+  void cmMakefile::ExecuteCommand(std::string &name,
+                                  std::vector<std::string> &args);
+  
+    
 protected:
   std::string m_Prefix;
   std::vector<std::string> m_AuxSourceDirectories; // 
@@ -531,7 +538,7 @@ protected:
   RegisteredCommandsMap m_Commands;
   std::vector<cmCommand*> m_UsedCommands;
   cmMakefileGenerator* m_MakefileGenerator;
-  bool IsFunctionBlocked(const char *name, std::vector<std::string> &args) const;
+  bool IsFunctionBlocked(const char *name, std::vector<std::string> &args);
   
 private:
   /**
@@ -550,6 +557,7 @@ private:
   
   typedef std::map<std::string, cmData*> DataMap;
   DataMap m_DataMap;
+  bool m_Inheriting;
 };