Xcode: Support multiple level nesting of XCode folders (#10039)

This commit is contained in:
Johan Björk 2011-02-15 14:34:14 +01:00 committed by Brad King
parent d0a403fd99
commit 59ed84e032
2 changed files with 50 additions and 22 deletions

View File

@ -2456,13 +2456,34 @@ void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root,
} }
} }
cmXCodeObject *cmGlobalXCodeGenerator
::CreatePBXGroup(cmXCodeObject *parent, cmStdString name)
{
cmXCodeObject* parentChildren = NULL;
if(parent)
parentChildren = parent->GetObject("children");
cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup);
cmXCodeObject* groupChildren =
this->CreateObject(cmXCodeObject::OBJECT_LIST);
group->AddAttribute("name", this->CreateString(name.c_str()));
group->AddAttribute("children", groupChildren);
if(this->XcodeVersion == 15)
{
group->AddAttribute("refType", this->CreateString("4"));
}
group->AddAttribute("sourceTree", this->CreateString("<group>"));
if(parentChildren)
parentChildren->AddObject(group);
return group;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmXCodeObject* cmGlobalXCodeGenerator cmXCodeObject* cmGlobalXCodeGenerator
::CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg) ::CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg)
{ {
cmStdString s = cmtarget.GetName(); cmStdString s = cmtarget.GetName();
s += "/"; s += "/";
s += sg->GetName(); s += sg->GetFullName();
std::map<cmStdString, cmXCodeObject* >::iterator i = std::map<cmStdString, cmXCodeObject* >::iterator i =
this->GroupNameMap.find(s); this->GroupNameMap.find(s);
if(i != this->GroupNameMap.end()) if(i != this->GroupNameMap.end())
@ -2477,41 +2498,46 @@ cmXCodeObject* cmGlobalXCodeGenerator
} }
else else
{ {
tgroup = this->CreateObject(cmXCodeObject::PBXGroup); tgroup = this->CreatePBXGroup(NULL,cmtarget.GetName());
this->TargetGroup[cmtarget.GetName()] = tgroup; this->TargetGroup[cmtarget.GetName()] = tgroup;
cmXCodeObject* tgroupChildren =
this->CreateObject(cmXCodeObject::OBJECT_LIST);
tgroup->AddAttribute("name", this->CreateString(cmtarget.GetName()));
tgroup->AddAttribute("children", tgroupChildren);
if(this->XcodeVersion == 15)
{
tgroup->AddAttribute("refType", this->CreateString("4"));
}
tgroup->AddAttribute("sourceTree", this->CreateString("<group>"));
this->SourcesGroupChildren->AddObject(tgroup); this->SourcesGroupChildren->AddObject(tgroup);
} }
// If it's the default source group (empty name) then put the source file // If it's the default source group (empty name) then put the source file
// directly in the tgroup... // directly in the tgroup...
// //
if (cmStdString(sg->GetName()) == "") if (cmStdString(sg->GetFullName()) == "")
{ {
this->GroupNameMap[s] = tgroup; this->GroupNameMap[s] = tgroup;
return tgroup; return tgroup;
} }
cmXCodeObject* tgroupChildren = tgroup->GetObject("children"); //It's a recursive folder structure, let's find the real parent group
cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup); if(std::string(sg->GetFullName()) != std::string(sg->GetName()))
cmXCodeObject* groupChildren =
this->CreateObject(cmXCodeObject::OBJECT_LIST);
group->AddAttribute("name", this->CreateString(sg->GetName()));
group->AddAttribute("children", groupChildren);
if(this->XcodeVersion == 15)
{ {
group->AddAttribute("refType", this->CreateString("4")); std::vector<std::string> folders = cmSystemTools::tokenize(sg->GetFullName(), "\\");
cmStdString curr_folder = cmtarget.GetName();
curr_folder += "/";
for(std::vector<std::string>::size_type i = 0; i < folders.size();i++)
{
curr_folder += folders[i];
std::map<cmStdString, cmXCodeObject* >::iterator i_folder = this->GroupNameMap.find(curr_folder);
//Create new folder
if(i_folder == this->GroupNameMap.end())
{
cmXCodeObject *group = this->CreatePBXGroup(tgroup,folders[i]);
this->GroupNameMap[curr_folder] = group;
tgroup = group;
} }
group->AddAttribute("sourceTree", this->CreateString("<group>")); else
tgroupChildren->AddObject(group); {
tgroup = i_folder->second;
}
curr_folder = curr_folder + "\\";
}
return tgroup;
}
cmXCodeObject *group = this->CreatePBXGroup(tgroup,sg->GetName());
this->GroupNameMap[s] = group; this->GroupNameMap[s] = group;
return group; return group;
} }

View File

@ -88,6 +88,8 @@ public:
private: private:
cmXCodeObject* CreateOrGetPBXGroup(cmTarget& cmtarget, cmXCodeObject* CreateOrGetPBXGroup(cmTarget& cmtarget,
cmSourceGroup* sg); cmSourceGroup* sg);
cmXCodeObject* CreatePBXGroup(cmXCodeObject *parent,
cmStdString name);
void CreateGroups(cmLocalGenerator* root, void CreateGroups(cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& std::vector<cmLocalGenerator*>&
generators); generators);