[cmake-commits] alex committed cmMakefile.cxx 1.411 1.412 cmMakefile.h 1.213 1.214 cmSourceGroup.cxx 1.18 1.19 cmSourceGroupCommand.cxx 1.17 1.18

cmake-commits at cmake.org cmake-commits at cmake.org
Fri Aug 24 14:21:51 EDT 2007


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

Modified Files:
	cmMakefile.cxx cmMakefile.h cmSourceGroup.cxx 
	cmSourceGroupCommand.cxx 
Log Message:
BUG: fix #4057 (which had several duplicates): handle recursivew source groups better, i.e. multiple sourcegroups with the same end component work now

Alex


Index: cmSourceGroup.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSourceGroup.cxx,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- cmSourceGroup.cxx	15 Mar 2006 16:02:07 -0000	1.18
+++ cmSourceGroup.cxx	24 Aug 2007 18:21:49 -0000	1.19
@@ -105,14 +105,6 @@
       {
       return &(*iter); // if it so return it 
       }
-    // if the descendend isn't the one where looking for ask it's traverse
-    cmSourceGroup *result = iter->lookupChild(name);
-                
-    // if one of it's descendeds is the one we're looking for return it 
-    if(result)
-      {
-      return result;
-      }
     }
 
   // if no child with this name was found return NULL

Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.213
retrieving revision 1.214
diff -u -d -r1.213 -r1.214
--- cmMakefile.h	20 Jul 2007 12:36:16 -0000	1.213
+++ cmMakefile.h	24 Aug 2007 18:21:49 -0000	1.214
@@ -291,10 +291,18 @@
 
 #if defined(CMAKE_BUILD_WITH_CMAKE)
   /**
-   * Add a source group for consideration when adding a new source.
+   * Add a root source group for consideration when adding a new source.
    */
   void AddSourceGroup(const char* name, const char* regex=0, 
                       const char* parent=0);
+
+  /**
+   * Add a source group for consideration when adding a new source.
+   * name is tokenized.
+   */
+  void AddSourceGroup(const std::vector<std::string>& name, 
+                      const char* regex=0, const char* parent=0);
+
 #endif
   
   /**
@@ -541,7 +549,7 @@
   /**
    * Get the source group
    */
-  cmSourceGroup* GetSourceGroup(const char* name); 
+  cmSourceGroup* GetSourceGroup(const std::vector<std::string>&name);
 #endif
 
   /**

Index: cmSourceGroupCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSourceGroupCommand.cxx,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- cmSourceGroupCommand.cxx	24 Aug 2007 14:58:53 -0000	1.17
+++ cmSourceGroupCommand.cxx	24 Aug 2007 18:21:49 -0000	1.18
@@ -66,16 +66,13 @@
  
   const char *parent = NULL;
   cmSourceGroup* sg = NULL;
-  for(unsigned int i=0;i<folders.size();++i)
+  sg = this->Makefile->GetSourceGroup(folders);
+  if(!sg)
     {
-    sg = this->Makefile->GetSourceGroup(folders[i].c_str());
-    if(!sg)
-      {
-      this->Makefile->AddSourceGroup(folders[i].c_str(), 0, parent);
-      }
-    sg = this->Makefile->GetSourceGroup(folders[i].c_str());
-    parent = folders[i].c_str();
+    this->Makefile->AddSourceGroup(folders);
+    sg = this->Makefile->GetSourceGroup(folders);
     }
+
   if(!sg)
     {
     this->SetError("Could not create or find source group");

Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.411
retrieving revision 1.412
diff -u -d -r1.411 -r1.412
--- cmMakefile.cxx	10 Aug 2007 13:07:38 -0000	1.411
+++ cmMakefile.cxx	24 Aug 2007 18:21:49 -0000	1.412
@@ -1448,105 +1448,99 @@
 }
 
 #if defined(CMAKE_BUILD_WITH_CMAKE)
-cmSourceGroup* cmMakefile::GetSourceGroup(const char* name)
+cmSourceGroup* cmMakefile::GetSourceGroup(const std::vector<std::string>&name)
 {
-  // First see if the group exists.  If so, replace its regular expression.
-  for(std::vector<cmSourceGroup>::iterator sg = this->SourceGroups.begin();
-      sg != this->SourceGroups.end(); ++sg)
+  cmSourceGroup* sg = 0;
+
+  // first look for source group starting with the same as the one we wants
+  for (std::vector<cmSourceGroup>::iterator sgIt = this->SourceGroups.begin();
+       sgIt != this->SourceGroups.end(); ++sgIt)
+
     {
-    std::string sgName = sg->GetName();
-    if(sgName == name)
+    std::string sgName = sgIt->GetName();
+    if(sgName == name[0])
       {
-      return &(*sg);
+      sg = &(*sgIt);
+      break;
       }
-    else
-      {
-      cmSourceGroup *target = sg->lookupChild(name);
+    }
 
-      if(target)
+  if(sg != 0)
+    {
+    // iterate through its children to find match source group
+    for(unsigned int i=1; i<name.size(); ++i)
+      {
+      sg = sg->lookupChild(name[i].c_str());
+      if(sg == 0)
         {
-        return target;
+        break;
         }
       }
     }
-  return 0;
+  return sg;
 }
 
-void cmMakefile::AddSourceGroup(const char* name,
+ void cmMakefile::AddSourceGroup(const char* name,
+                                 const char* regex,
+                                 const char* parent)
+{
+  if (name)
+    {
+    std::vector<std::string> nameVector;
+    nameVector.push_back(name);
+    AddSourceGroup(nameVector, regex, parent);
+    }
+}
+
+void cmMakefile::AddSourceGroup(const std::vector<std::string>& name,
                                 const char* regex,
                                 const char *parent)
 {
-  // First see if the group exists.  If so, replace its regular expression.
-  for(unsigned int i=0;i<this->SourceGroups.size();++i)
+  cmSourceGroup* sg = 0;
+  std::vector<std::string> currentName;
+  int i = 0;
+  const int lastElement = name.size()-1;
+  for(i=lastElement; i>=0; --i)
     {
-    cmSourceGroup *sg = &this->SourceGroups[i];
-
-    std::string sgName = sg->GetName();
-    if(!parent)
+    currentName.assign(name.begin(), name.begin()+i+1);
+    sg = this->GetSourceGroup(currentName);
+    if(sg != 0)
       {
-      if(sgName == name)
-        {
-        if ( regex )
-          {
-          // We only want to set the regular expression.  If there are already
-          // source files in the group, we don't want to remove them.
-          sg->SetGroupRegex(regex);
-          }
-        return;
-        }
+      break;
       }
-    else
-      {
-      if(sgName == parent)
-        {
-        cmSourceGroup *localtarget = sg->lookupChild(name);
-        if(localtarget)
-          {
-          if ( regex )
-            {
-            // We only want to set the regular expression.  If there are
-            // already source files in the group, we don't want to remove
-            // them.
-            localtarget->SetGroupRegex(regex);
-            }
-          }
-        else
-          {
-          sg->AddChild(cmSourceGroup(name, regex));
-          }
-        return;
-        }
-      else
-        {
-        cmSourceGroup *localtarget = sg->lookupChild(parent);
-
-        if(localtarget)
-          {
-          cmSourceGroup *addtarget = localtarget->lookupChild(name);
+    }
 
-          if(addtarget)
-            {
-            if ( regex )
-              {
-              // We only want to set the regular expression.  If there are
-              // already source files in the group, we don't want to
-              // remove them.
-              addtarget->SetGroupRegex(regex);
-              }
-            }
-          else
-            {
-            localtarget->AddChild(cmSourceGroup(name, regex));
-            }
-          return;
-          }
-        }
+  // i now contains the index of the last found component
+  if(i==lastElement)
+    {
+    // group already exists, replace its regular expression
+    if ( regex )
+      {
+      // We only want to set the regular expression.  If there are already
+      // source files in the group, we don't want to remove them.
+      sg->SetGroupRegex(regex);
       }
+    return;
+    }
+  else if(i==-1)
+    {
+    // group does not exists nor belong to any existing group
+    // add its first component
+    this->SourceGroups.push_back(cmSourceGroup(name[0].c_str(), regex));
+    sg = this->GetSourceGroup(currentName);
+    i = 0; // last component found
     }
 
-  // The group doesn't exist.  Add it.
-  this->SourceGroups.push_back(cmSourceGroup(name, regex));
+  // build the whole source group path
+  for(++i; i<=lastElement; ++i)
+    {
+    sg->AddChild(cmSourceGroup(name[i].c_str(), 0));
+    sg = sg->lookupChild(name[i].c_str());
+    }
+
+  sg->SetGroupRegex(regex);
 }
+
 #endif
 
 void cmMakefile::AddExtraDirectory(const char* dir)



More information about the Cmake-commits mailing list