Xcode: Order targets alphabetically

Fixes: #21659
This commit is contained in:
Peter Steneteg
2025-10-07 09:39:37 +02:00
committed by Brad King
parent 53716f6bfd
commit 4ca5e5480a
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;