Attached Files | SourceGroup.patch [^] (7,976 bytes) 1969-12-31 19:00 [Show Content] [Hide Content]Index: cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.401
diff -u -r1.401 cmMakefile.cxx
--- cmMakefile.cxx 28 Jun 2007 13:09:26 -0000 1.401
+++ cmMakefile.cxx 30 Jun 2007 07:38:44 -0000
@@ -1437,104 +1437,87 @@
}
#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 = NULL;
+
+ // 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)
- {
- return &(*sg);
- }
- else
- {
- cmSourceGroup *target = sg->lookupChild(name);
+ std::string sgName = sgIt->GetName();
+ if(sgName == name[0])
+ {
+ sg = &(*sgIt);
+ break;
+ }
+ }
+ if(sg == NULL)
+ return NULL;
- if(target)
- {
- return target;
- }
- }
+ // iterate through its children to recursively find match source group
+ for(unsigned int i=1;i<name.size();++i)
+ {
+ sg = sg->lookupChild(name[i].c_str());
+ if(sg == NULL)
+ return NULL;
}
- return 0;
+ return sg;
}
void cmMakefile::AddSourceGroup(const char* name,
+ const char* regex,
+ const char* parent)
+{
+ std::vector<std::string> nameVector;
+ nameVector.push_back(name);
+ AddSourceGroup(nameVector);
+}
+
+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)
+ int i;
+ cmSourceGroup* sg;
+ std::vector<std::string> currentName;
+ int lastElement = name.size()-1;
+
+ for(i=lastElement;i>=0;--i)
+ {
+ currentName.assign(name.begin(), name.begin()+i+1);
+ sg = GetSourceGroup(currentName);
+ if(sg != NULL)
+ break;
+ }
+ // i now contains the index of the last found component
+
+ if(i==lastElement)
{
- cmSourceGroup *sg = &this->SourceGroups[i];
-
- std::string sgName = sg->GetName();
- if(!parent)
+ // group already exists, replace its regular expression
+ if ( regex )
{
- 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;
- }
- }
- 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;
- }
- }
- }
- }
-
- // The group doesn't exist. Add it.
- this->SourceGroups.push_back(cmSourceGroup(name, 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=GetSourceGroup(currentName);
+ i=0; // last component found
+ }
+
+ // 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
Index: cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.212
diff -u -r1.212 cmMakefile.h
--- cmMakefile.h 28 Jun 2007 13:09:26 -0000 1.212
+++ cmMakefile.h 30 Jun 2007 06:49:11 -0000
@@ -289,10 +289,16 @@
#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
/**
@@ -537,9 +543,9 @@
{ return this->SourceGroups; }
/**
- * Get the source group
+ * Get the source group using already tokenized name
*/
- cmSourceGroup* GetSourceGroup(const char* name);
+ cmSourceGroup* GetSourceGroup(const std::vector<std::string>& name);
#endif
/**
Index: cmSourceGroup.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSourceGroup.cxx,v
retrieving revision 1.18
diff -u -r1.18 cmSourceGroup.cxx
--- cmSourceGroup.cxx 15 Mar 2006 16:02:07 -0000 1.18
+++ cmSourceGroup.cxx 30 Jun 2007 05:40:49 -0000
@@ -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: cmSourceGroupCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSourceGroupCommand.cxx,v
retrieving revision 1.16
diff -u -r1.16 cmSourceGroupCommand.cxx
--- cmSourceGroupCommand.cxx 15 Mar 2006 16:02:07 -0000 1.16
+++ cmSourceGroupCommand.cxx 30 Jun 2007 18:27:30 -0000
@@ -67,16 +67,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");
SourceGroup-fixed-tokenizer.patch [^] (8,695 bytes) 1969-12-31 19:00 [Show Content] [Hide Content]? Build
? Utilities/Release/CMakeInstall.bmp
Index: Source/cmMakefile.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.cxx,v
retrieving revision 1.408
diff -u -r1.408 cmMakefile.cxx
--- Source/cmMakefile.cxx 20 Jul 2007 12:48:32 -0000 1.408
+++ Source/cmMakefile.cxx 22 Jul 2007 07:06:51 -0000
@@ -1448,104 +1448,87 @@
}
#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 = NULL;
+
+ // 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)
- {
- return &(*sg);
- }
- else
- {
- cmSourceGroup *target = sg->lookupChild(name);
+ std::string sgName = sgIt->GetName();
+ if(sgName == name[0])
+ {
+ sg = &(*sgIt);
+ break;
+ }
+ }
+ if(sg == NULL)
+ return NULL;
- if(target)
- {
- return target;
- }
- }
+ // iterate through its children to recursively find match source group
+ for(unsigned int i=1;i<name.size();++i)
+ {
+ sg = sg->lookupChild(name[i].c_str());
+ if(sg == NULL)
+ return NULL;
}
- return 0;
+ return sg;
}
void cmMakefile::AddSourceGroup(const char* name,
+ const char* regex,
+ const char* parent)
+{
+ std::vector<std::string> nameVector;
+ nameVector.push_back(name);
+ AddSourceGroup(nameVector);
+}
+
+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)
+ int i;
+ cmSourceGroup* sg;
+ std::vector<std::string> currentName;
+ int lastElement = name.size()-1;
+
+ for(i=lastElement;i>=0;--i)
+ {
+ currentName.assign(name.begin(), name.begin()+i+1);
+ sg = GetSourceGroup(currentName);
+ if(sg != NULL)
+ break;
+ }
+ // i now contains the index of the last found component
+
+ if(i==lastElement)
{
- cmSourceGroup *sg = &this->SourceGroups[i];
-
- std::string sgName = sg->GetName();
- if(!parent)
- {
- 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;
- }
- }
- else
+ // group already exists, replace its regular expression
+ if ( regex )
{
- 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;
- }
- }
+ // 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);
}
- }
-
- // The group doesn't exist. Add it.
- this->SourceGroups.push_back(cmSourceGroup(name, 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=GetSourceGroup(currentName);
+ i=0; // last component found
+ }
+
+ // 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
Index: Source/cmMakefile.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmMakefile.h,v
retrieving revision 1.213
diff -u -r1.213 cmMakefile.h
--- Source/cmMakefile.h 20 Jul 2007 12:36:16 -0000 1.213
+++ Source/cmMakefile.h 22 Jul 2007 07:06:51 -0000
@@ -291,10 +291,16 @@
#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
/**
@@ -539,9 +545,9 @@
{ return this->SourceGroups; }
/**
- * Get the source group
+ * Get the source group using already tokenized name
*/
- cmSourceGroup* GetSourceGroup(const char* name);
+ cmSourceGroup* GetSourceGroup(const std::vector<std::string>& name);
#endif
/**
Index: Source/cmSourceGroup.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSourceGroup.cxx,v
retrieving revision 1.18
diff -u -r1.18 cmSourceGroup.cxx
--- Source/cmSourceGroup.cxx 15 Mar 2006 16:02:07 -0000 1.18
+++ Source/cmSourceGroup.cxx 22 Jul 2007 07:06:51 -0000
@@ -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: Source/cmSourceGroupCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmSourceGroupCommand.cxx,v
retrieving revision 1.16
diff -u -r1.16 cmSourceGroupCommand.cxx
--- Source/cmSourceGroupCommand.cxx 15 Mar 2006 16:02:07 -0000 1.16
+++ Source/cmSourceGroupCommand.cxx 22 Jul 2007 07:32:17 -0000
@@ -45,6 +45,8 @@
tokens.push_back(str.substr(tokstart,tokend-tokstart));
}
} while (tokend!=std::string::npos);
+ if (tokens.empty())
+ tokens.push_back(str); // no separator has not been found
return tokens;
}
@@ -64,19 +66,15 @@
}
std::vector<std::string> folders = tokenize(args[0], delimiter);
-
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");
|