FASTBuild: improve IDE project structure

Right now, all IDE projects are located at the top level which makes it pretty messy  when there are a lot of them.

With this change the generated IDE project will more closely mimic existing folder structure in the project.
This commit is contained in:
Eduard Voronkin
2025-09-12 13:58:38 -07:00
parent a3ccb05430
commit 9441f6cfb2
2 changed files with 38 additions and 7 deletions

View File

@@ -1453,11 +1453,12 @@ void cmGlobalFastbuildGenerator::AddGlobCheckExec()
void cmGlobalFastbuildGenerator::WriteSolution()
{
std::string const solutionName = LocalGenerators[0]->GetProjectName();
std::vector<std::string> VSProjects;
std::map<std::string /*folder*/, std::vector<std::string>> VSProjects;
std::vector<std::string> VSProjectsWithoutFolder;
for (auto const& IDEProj : IDEProjects) {
auto const VSProj = IDEProj.second.first;
VSProjects.emplace_back(VSProj.Alias);
VSProjects[VSProj.folder].emplace_back(VSProj.Alias);
}
WriteCommand("VSSolution", Quote("solution"));
@@ -1469,7 +1470,32 @@ void cmGlobalFastbuildGenerator::WriteSolution()
auto const& configs = IDEProjects.begin()->second.first.ProjectConfigs;
WriteIDEProjectConfig(configs, "SolutionConfigs");
WriteArray("SolutionProjects", Wrap(VSProjects), 1);
int folderNumber = 0;
std::vector<std::string> folders;
for (auto& item : VSProjects) {
auto const& pathToFolder = item.first;
auto& projectsInFolder = item.second;
if (pathToFolder.empty()) {
std::move(projectsInFolder.begin(), projectsInFolder.end(),
std::back_inserter(VSProjectsWithoutFolder));
} else {
std::string folderName =
cmStrCat("Folder_", std::to_string(++folderNumber));
WriteStruct(
folderName,
{ { "Path", Quote(pathToFolder) },
{ "Projects",
cmStrCat("{", cmJoin(Wrap(projectsInFolder), ","), "}") } },
1);
folders.emplace_back(std::move(folderName));
}
}
if (!folders.empty()) {
WriteArray("SolutionFolders ", Wrap(folders, ".", ""), 1);
}
if (!VSProjectsWithoutFolder.empty()) {
WriteArray("SolutionProjects", Wrap(VSProjectsWithoutFolder), 1);
}
*this->BuildFileStream << "}\n";
}
@@ -1697,17 +1723,21 @@ void cmGlobalFastbuildGenerator::AddIDEProject(FastbuildTarget const& target,
return;
}
auto& IDEProject = IDEProjects[target.BaseName];
auto const relativeSubdir = cmSystemTools::RelativePath(
this->GetCMakeInstance()->GetHomeDirectory(), target.BasePath);
// VS
auto& VSProject = IDEProject.first;
VSProject.Alias = target.BaseName + "-vcxproj";
VSProject.ProjectOutput =
cmStrCat("VisualStudio/Projects/", target.BaseName + ".vcxproj");
VSProject.ProjectOutput = cmStrCat("VisualStudio/Projects/", relativeSubdir,
'/', target.BaseName + ".vcxproj");
VSProject.ProjectBasePath = target.BasePath;
VSProject.folder = relativeSubdir;
// XCode
auto& XCodeProject = IDEProject.second;
XCodeProject.Alias = target.BaseName + "-xcodeproj";
XCodeProject.ProjectOutput = cmStrCat(
"XCode/Projects/", target.BaseName + ".xcodeproj/project.pbxproj");
XCodeProject.ProjectOutput =
cmStrCat("XCode/Projects/", relativeSubdir, '/',
target.BaseName + ".xcodeproj/project.pbxproj");
XCodeProject.ProjectBasePath = target.BasePath;
IDEProjectConfig VSConfig;

View File

@@ -247,6 +247,7 @@ struct XCodeProject : public IDEProjectCommon
struct VCXProject : public IDEProjectCommon
{
std::string folder;
};
struct FastbuildLinkerNode