BUG: fix #4057 (which had several duplicates): handle recursivew source groups better, i.e. multiple sourcegroups with the same end component work now
Alex
This commit is contained in:
parent
9a4e7ea742
commit
9220e97401
|
@ -1448,44 +1448,72 @@ cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#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.
|
cmSourceGroup* sg = 0;
|
||||||
for(std::vector<cmSourceGroup>::iterator sg = this->SourceGroups.begin();
|
|
||||||
sg != this->SourceGroups.end(); ++sg)
|
// first look for source group starting with the same as the one we wants
|
||||||
{
|
for (std::vector<cmSourceGroup>::iterator sgIt = this->SourceGroups.begin();
|
||||||
std::string sgName = sg->GetName();
|
sgIt != this->SourceGroups.end(); ++sgIt)
|
||||||
if(sgName == name)
|
|
||||||
{
|
|
||||||
return &(*sg);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cmSourceGroup *target = sg->lookupChild(name);
|
|
||||||
|
|
||||||
if(target)
|
|
||||||
{
|
{
|
||||||
return target;
|
std::string sgName = sgIt->GetName();
|
||||||
|
if(sgName == name[0])
|
||||||
|
{
|
||||||
|
sg = &(*sgIt);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return sg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmMakefile::AddSourceGroup(const char* name,
|
void cmMakefile::AddSourceGroup(const char* name,
|
||||||
const char* regex,
|
const char* regex,
|
||||||
const char* parent)
|
const char* parent)
|
||||||
{
|
{
|
||||||
// First see if the group exists. If so, replace its regular expression.
|
if (name)
|
||||||
for(unsigned int i=0;i<this->SourceGroups.size();++i)
|
|
||||||
{
|
{
|
||||||
cmSourceGroup *sg = &this->SourceGroups[i];
|
std::vector<std::string> nameVector;
|
||||||
|
nameVector.push_back(name);
|
||||||
|
AddSourceGroup(nameVector, regex, parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string sgName = sg->GetName();
|
void cmMakefile::AddSourceGroup(const std::vector<std::string>& name,
|
||||||
if(!parent)
|
const char* regex,
|
||||||
|
const char *parent)
|
||||||
{
|
{
|
||||||
if(sgName == name)
|
cmSourceGroup* sg = 0;
|
||||||
|
std::vector<std::string> currentName;
|
||||||
|
int i = 0;
|
||||||
|
const int lastElement = name.size()-1;
|
||||||
|
for(i=lastElement; i>=0; --i)
|
||||||
{
|
{
|
||||||
|
currentName.assign(name.begin(), name.begin()+i+1);
|
||||||
|
sg = this->GetSourceGroup(currentName);
|
||||||
|
if(sg != 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// i now contains the index of the last found component
|
||||||
|
if(i==lastElement)
|
||||||
|
{
|
||||||
|
// group already exists, replace its regular expression
|
||||||
if ( regex )
|
if ( regex )
|
||||||
{
|
{
|
||||||
// We only want to set the regular expression. If there are already
|
// We only want to set the regular expression. If there are already
|
||||||
|
@ -1494,59 +1522,25 @@ void cmMakefile::AddSourceGroup(const char* name,
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
else if(i==-1)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if(sgName == parent)
|
// group does not exists nor belong to any existing group
|
||||||
{
|
// add its first component
|
||||||
cmSourceGroup *localtarget = sg->lookupChild(name);
|
this->SourceGroups.push_back(cmSourceGroup(name[0].c_str(), regex));
|
||||||
if(localtarget)
|
sg = this->GetSourceGroup(currentName);
|
||||||
{
|
i = 0; // last component found
|
||||||
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.
|
// build the whole source group path
|
||||||
this->SourceGroups.push_back(cmSourceGroup(name, regex));
|
for(++i; i<=lastElement; ++i)
|
||||||
|
{
|
||||||
|
sg->AddChild(cmSourceGroup(name[i].c_str(), 0));
|
||||||
|
sg = sg->lookupChild(name[i].c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sg->SetGroupRegex(regex);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void cmMakefile::AddExtraDirectory(const char* dir)
|
void cmMakefile::AddExtraDirectory(const char* dir)
|
||||||
|
|
|
@ -291,10 +291,18 @@ public:
|
||||||
|
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#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,
|
void AddSourceGroup(const char* name, const char* regex=0,
|
||||||
const char* parent=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
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -541,7 +549,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Get the source group
|
* Get the source group
|
||||||
*/
|
*/
|
||||||
cmSourceGroup* GetSourceGroup(const char* name);
|
cmSourceGroup* GetSourceGroup(const std::vector<std::string>&name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -105,14 +105,6 @@ cmSourceGroup *cmSourceGroup::lookupChild(const char* name)
|
||||||
{
|
{
|
||||||
return &(*iter); // if it so return it
|
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
|
// if no child with this name was found return NULL
|
||||||
|
|
|
@ -66,16 +66,13 @@ bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args)
|
||||||
|
|
||||||
const char *parent = NULL;
|
const char *parent = NULL;
|
||||||
cmSourceGroup* sg = NULL;
|
cmSourceGroup* sg = NULL;
|
||||||
for(unsigned int i=0;i<folders.size();++i)
|
sg = this->Makefile->GetSourceGroup(folders);
|
||||||
{
|
|
||||||
sg = this->Makefile->GetSourceGroup(folders[i].c_str());
|
|
||||||
if(!sg)
|
if(!sg)
|
||||||
{
|
{
|
||||||
this->Makefile->AddSourceGroup(folders[i].c_str(), 0, parent);
|
this->Makefile->AddSourceGroup(folders);
|
||||||
}
|
sg = this->Makefile->GetSourceGroup(folders);
|
||||||
sg = this->Makefile->GetSourceGroup(folders[i].c_str());
|
|
||||||
parent = folders[i].c_str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!sg)
|
if(!sg)
|
||||||
{
|
{
|
||||||
this->SetError("Could not create or find source group");
|
this->SetError("Could not create or find source group");
|
||||||
|
|
Loading…
Reference in New Issue