From d0a403fd99e000f32467f66fe898d785f30435eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bj=C3=B6rk?= Date: Tue, 15 Feb 2011 14:34:14 +0100 Subject: CMake: Move tokenize to cmSystemTools --- Source/cmSourceGroupCommand.cxx | 33 +-------------------------------- Source/cmSystemTools.cxx | 32 ++++++++++++++++++++++++++++++++ Source/cmSystemTools.h | 3 +++ 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx index 27d90db..22f4d47 100644 --- a/Source/cmSourceGroupCommand.cxx +++ b/Source/cmSourceGroupCommand.cxx @@ -11,37 +11,6 @@ ============================================================================*/ #include "cmSourceGroupCommand.h" -inline std::vector tokenize(const std::string& str, - const std::string& sep) -{ - std::vector tokens; - std::string::size_type tokend = 0; - - do - { - std::string::size_type tokstart=str.find_first_not_of(sep, tokend); - if (tokstart==std::string::npos) - { - break; // no more tokens - } - tokend=str.find_first_of(sep,tokstart); - if (tokend==std::string::npos) - { - tokens.push_back(str.substr(tokstart)); - } - else - { - tokens.push_back(str.substr(tokstart,tokend-tokstart)); - } - } while (tokend!=std::string::npos); - - if (tokens.empty()) - { - tokens.push_back(""); - } - return tokens; -} - // cmSourceGroupCommand bool cmSourceGroupCommand ::InitialPass(std::vector const& args, cmExecutionStatus &) @@ -58,7 +27,7 @@ bool cmSourceGroupCommand delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER"); } - std::vector folders = tokenize(args[0], delimiter); + std::vector folders = cmSystemTools::tokenize(args[0], delimiter); cmSourceGroup* sg = 0; sg = this->Makefile->GetSourceGroup(folders); diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 7bc89a4..9341a4c 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -2833,3 +2833,35 @@ bool cmSystemTools::RepeatedRemoveDirectory(const char* dir) } return false; } + +//---------------------------------------------------------------------------- +std::vector cmSystemTools::tokenize(const std::string& str, + const std::string& sep) +{ + std::vector tokens; + std::string::size_type tokend = 0; + + do + { + std::string::size_type tokstart=str.find_first_not_of(sep, tokend); + if (tokstart==std::string::npos) + { + break; // no more tokens + } + tokend=str.find_first_of(sep,tokstart); + if (tokend==std::string::npos) + { + tokens.push_back(str.substr(tokstart)); + } + else + { + tokens.push_back(str.substr(tokstart,tokend-tokstart)); + } + } while (tokend!=std::string::npos); + + if (tokens.empty()) + { + tokens.push_back(""); + } + return tokens; +} diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 6f9147c..5b5c768 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -439,6 +439,9 @@ public: /** Remove a directory; repeat a few times in case of locked files. */ static bool RepeatedRemoveDirectory(const char* dir); + /** Tokenize a string */ + static std::vector tokenize(const std::string& str, + const std::string& sep); private: static bool s_ForceUnixPaths; static bool s_RunCommandHideConsole; -- cgit v0.12 From 59ed84e032922f4d44b973837aa24497d182d2d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bj=C3=B6rk?= Date: Tue, 15 Feb 2011 14:34:14 +0100 Subject: Xcode: Support multiple level nesting of XCode folders (#10039) --- Source/cmGlobalXCodeGenerator.cxx | 70 +++++++++++++++++++++++++++------------ Source/cmGlobalXCodeGenerator.h | 2 ++ 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 358721f..e7ae8be 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -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("")); + if(parentChildren) + parentChildren->AddObject(group); + return group; +} + //---------------------------------------------------------------------------- cmXCodeObject* cmGlobalXCodeGenerator ::CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg) { cmStdString s = cmtarget.GetName(); s += "/"; - s += sg->GetName(); + s += sg->GetFullName(); std::map::iterator i = this->GroupNameMap.find(s); if(i != this->GroupNameMap.end()) @@ -2477,41 +2498,46 @@ cmXCodeObject* cmGlobalXCodeGenerator } else { - tgroup = this->CreateObject(cmXCodeObject::PBXGroup); + tgroup = this->CreatePBXGroup(NULL,cmtarget.GetName()); 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("")); this->SourcesGroupChildren->AddObject(tgroup); } // If it's the default source group (empty name) then put the source file // directly in the tgroup... // - if (cmStdString(sg->GetName()) == "") + if (cmStdString(sg->GetFullName()) == "") { this->GroupNameMap[s] = tgroup; return tgroup; } - cmXCodeObject* tgroupChildren = tgroup->GetObject("children"); - cmXCodeObject* group = this->CreateObject(cmXCodeObject::PBXGroup); - cmXCodeObject* groupChildren = - this->CreateObject(cmXCodeObject::OBJECT_LIST); - group->AddAttribute("name", this->CreateString(sg->GetName())); - group->AddAttribute("children", groupChildren); - if(this->XcodeVersion == 15) + //It's a recursive folder structure, let's find the real parent group + if(std::string(sg->GetFullName()) != std::string(sg->GetName())) { - group->AddAttribute("refType", this->CreateString("4")); + std::vector folders = cmSystemTools::tokenize(sg->GetFullName(), "\\"); + cmStdString curr_folder = cmtarget.GetName(); + curr_folder += "/"; + for(std::vector::size_type i = 0; i < folders.size();i++) + { + curr_folder += folders[i]; + std::map::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; + } + else + { + tgroup = i_folder->second; + } + curr_folder = curr_folder + "\\"; + } + return tgroup; } - group->AddAttribute("sourceTree", this->CreateString("")); - tgroupChildren->AddObject(group); + cmXCodeObject *group = this->CreatePBXGroup(tgroup,sg->GetName()); this->GroupNameMap[s] = group; return group; } diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index 290532a..22a78f2 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -88,6 +88,8 @@ public: private: cmXCodeObject* CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg); + cmXCodeObject* CreatePBXGroup(cmXCodeObject *parent, + cmStdString name); void CreateGroups(cmLocalGenerator* root, std::vector& generators); -- cgit v0.12 From eeeeca1082a8be5890a6d2096b505ebe584fc2b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bj=C3=B6rk?= Date: Sun, 20 Feb 2011 14:05:41 +0100 Subject: XCode: Support target folders on XCode. --- Source/cmGlobalXCodeGenerator.cxx | 50 ++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index e7ae8be..688296e 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2481,27 +2481,55 @@ cmXCodeObject *cmGlobalXCodeGenerator cmXCodeObject* cmGlobalXCodeGenerator ::CreateOrGetPBXGroup(cmTarget& cmtarget, cmSourceGroup* sg) { - cmStdString s = cmtarget.GetName(); - s += "/"; + cmStdString s; + cmStdString target; + const char *targetFolder= cmtarget.GetProperty("FOLDER"); + if(targetFolder) { + target = targetFolder; + target += "/"; + } + target += cmtarget.GetName(); + s = target + "/"; s += sg->GetFullName(); - std::map::iterator i = + std::map::iterator it = this->GroupNameMap.find(s); - if(i != this->GroupNameMap.end()) + if(it != this->GroupNameMap.end()) { - return i->second; + return it->second; } - i = this->TargetGroup.find(cmtarget.GetName()); + + it = this->TargetGroup.find(target); cmXCodeObject* tgroup = 0; - if(i != this->TargetGroup.end()) + if(it != this->TargetGroup.end()) { - tgroup = i->second; + tgroup = it->second; } else { - tgroup = this->CreatePBXGroup(NULL,cmtarget.GetName()); - this->TargetGroup[cmtarget.GetName()] = tgroup; - this->SourcesGroupChildren->AddObject(tgroup); + std::vector tgt_folders = cmSystemTools::tokenize(target, "/"); + cmStdString curr_tgt_folder; + for(std::vector::size_type i = 0; i < tgt_folders.size();i++) + { + curr_tgt_folder += tgt_folders[i]; + it = this->TargetGroup.find(curr_tgt_folder); + if(it == this->TargetGroup.end()) + { + tgroup = this->CreatePBXGroup(tgroup,tgt_folders[i]); + this->TargetGroup[curr_tgt_folder] = tgroup; + } + else + { + tgroup = it->second; + continue; + } + if(i == 0) + { + this->SourcesGroupChildren->AddObject(tgroup); + } + curr_tgt_folder += "/"; + } } + this->TargetGroup[target] = tgroup; // If it's the default source group (empty name) then put the source file // directly in the tgroup... -- cgit v0.12 From f09ba0f1a2dbae3bca99b35b7d8c26c457c5824c Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 8 Jun 2011 07:54:33 -0400 Subject: Fix style errors added by parent and grandparent --- Source/cmGlobalXCodeGenerator.cxx | 9 ++++++--- Source/cmSourceGroupCommand.cxx | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 688296e..b0c095d 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2506,7 +2506,8 @@ cmXCodeObject* cmGlobalXCodeGenerator } else { - std::vector tgt_folders = cmSystemTools::tokenize(target, "/"); + std::vector tgt_folders = + cmSystemTools::tokenize(target, "/"); cmStdString curr_tgt_folder; for(std::vector::size_type i = 0; i < tgt_folders.size();i++) { @@ -2543,13 +2544,15 @@ cmXCodeObject* cmGlobalXCodeGenerator //It's a recursive folder structure, let's find the real parent group if(std::string(sg->GetFullName()) != std::string(sg->GetName())) { - std::vector folders = cmSystemTools::tokenize(sg->GetFullName(), "\\"); + std::vector folders = + cmSystemTools::tokenize(sg->GetFullName(), "\\"); cmStdString curr_folder = cmtarget.GetName(); curr_folder += "/"; for(std::vector::size_type i = 0; i < folders.size();i++) { curr_folder += folders[i]; - std::map::iterator i_folder = this->GroupNameMap.find(curr_folder); + std::map::iterator i_folder = + this->GroupNameMap.find(curr_folder); //Create new folder if(i_folder == this->GroupNameMap.end()) { diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx index 22f4d47..8e61d0a 100644 --- a/Source/cmSourceGroupCommand.cxx +++ b/Source/cmSourceGroupCommand.cxx @@ -27,7 +27,8 @@ bool cmSourceGroupCommand delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER"); } - std::vector folders = cmSystemTools::tokenize(args[0], delimiter); + std::vector folders = + cmSystemTools::tokenize(args[0], delimiter); cmSourceGroup* sg = 0; sg = this->Makefile->GetSourceGroup(folders); -- cgit v0.12