1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

Merge topic 'sort-xcode-folders'

4ca5e5480a Xcode: Order targets alphabetically

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11289
This commit is contained in:
Brad King
2025-10-08 13:32:15 +00:00
committed by Kitware Robot
2 changed files with 24 additions and 0 deletions

View File

@@ -4551,6 +4551,21 @@ bool cmGlobalXCodeGenerator::CreateGroups(
}
}
}
// Sort all children of each target group by name alphabetically.
auto const getName = [](cmXCodeObject* obj) -> cm::string_view {
cmXCodeObject* name = obj->GetAttribute("name");
return name ? name->GetString() : cm::string_view{ ""_s };
};
for (auto& group : this->TargetGroup) {
if (cmXCodeObject* children = group.second->GetAttribute("children")) {
children->SortObjectList(getName);
}
}
// Also sort the-top level group. Special groups like Products,
// Frameworks, and Resources are added later to the end of the list.
this->MainGroupChildren->SortObjectList(getName);
return true;
}

View File

@@ -163,6 +163,15 @@ public:
void SetComment(std::string const& c) { this->Comment = c; }
static void PrintString(std::ostream& os, std::string const& String);
template <typename Proj>
void SortObjectList(Proj projector)
{
std::sort(this->List.begin(), this->List.end(),
[&projector](cmXCodeObject* a, cmXCodeObject* b) {
return projector(a) < projector(b);
});
}
protected:
void PrintString(std::ostream& os) const;