From c07545b945c60e7e9bc5791ca960a6a059529c5e Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 29 Aug 2025 15:29:34 -0400 Subject: [PATCH 1/9] Tests/RunCMake/VS10Project: Enable case covering VS_SOLUTION_ITEMS This was missed in commit 0bb13ba0e6 (VS: Add support for Visual Studio solution items, 2024-10-27, v4.0.0-rc1~423^2). --- Tests/RunCMake/VS10Project/RunCMakeTest.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake index 72b1c78b29..fc7523741c 100644 --- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake +++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake @@ -18,6 +18,7 @@ run_cmake(ExplicitCMakeLists) run_cmake(InterfaceLibSources) run_cmake(NoImpLib) run_cmake(RuntimeLibrary) +run_cmake(SolutionItems) run_cmake(SourceGroupCMakeLists) run_cmake(SourceGroupTreeCMakeLists) run_cmake(SourceGroupFileSet) From 93e34a5e0e552d4e0f4e945f301d166c464a7a46 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 29 Aug 2025 11:45:07 -0400 Subject: [PATCH 2/9] cmGlobalGenerator: Constify GetTargetDirectDepends It should only be called for targets whose dependencies are already computed. --- Source/cmGlobalGenerator.cxx | 7 +++++-- Source/cmGlobalGenerator.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index bf155851c2..5d46d2a166 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -3389,9 +3389,12 @@ cmValue cmGlobalGenerator::GetDebuggerWorkingDirectory( } cmGlobalGenerator::TargetDependSet const& -cmGlobalGenerator::GetTargetDirectDepends(cmGeneratorTarget const* target) +cmGlobalGenerator::GetTargetDirectDepends( + cmGeneratorTarget const* target) const { - return this->TargetDependencies[target]; + auto i = this->TargetDependencies.find(target); + assert(i != this->TargetDependencies.end()); + return i->second; } bool cmGlobalGenerator::TargetOrderIndexLess(cmGeneratorTarget const* l, diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index e7b252859d..7d59d9a8bb 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -525,7 +525,7 @@ public: // what targets does the specified target depend on directly // via a target_link_libraries or add_dependencies TargetDependSet const& GetTargetDirectDepends( - cmGeneratorTarget const* target); + cmGeneratorTarget const* target) const; // Return true if target 'l' occurs before 'r' in a global ordering // of targets that respects inter-target dependencies. From ccbd61dd5333116f1e388f0f6839407e116df73f Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 29 Aug 2025 14:19:00 -0400 Subject: [PATCH 3/9] cmGlobalVisualStudio7Generator: Remove unused member --- Source/cmGlobalVisualStudio7Generator.cxx | 1 - Source/cmGlobalVisualStudio7Generator.h | 3 --- 2 files changed, 4 deletions(-) diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 03d457756f..e161bfa0c7 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -316,7 +316,6 @@ void cmGlobalVisualStudio7Generator::OutputSLNFile( if (generators.empty()) { return; } - this->CurrentProject = root->GetProjectName(); std::string fname = GetSLNFile(root); cmGeneratedFileStream fout(fname); fout.SetCopyIfDifferent(true); diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index c4f45b6a2a..697e868767 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -192,9 +192,6 @@ protected: std::map VisualStudioFolders; - // Set during OutputSLNFile with the name of the current project. - // There is one SLN file per project. - std::string CurrentProject; bool MarmasmEnabled; bool MasmEnabled; bool NasmEnabled; From 2297ba9399b9a43a2285cbc28b7e710476e94493 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 29 Aug 2025 14:39:06 -0400 Subject: [PATCH 4/9] cmGlobalVisualStudio7Generator: Remove redundant C++ modules check In commit 386465bf83 (cmTarget: add support for C++ module fileset types, 2022-04-08, v3.25.0-rc1~624^2~7) we added two calls to the same check in the VS generators. Remove one. --- Source/cmGlobalVisualStudio7Generator.cxx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index e161bfa0c7..ddbdd3fc2e 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -422,10 +422,6 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( } bool written = false; - for (auto const& c : configs) { - target->CheckCxxModuleStatus(c); - } - // handle external vc project files cmValue expath = target->GetProperty("EXTERNAL_MSPROJECT"); if (expath) { From 5582eb292e7f9c740cf2252fafdf54baf55e48e4 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 29 Aug 2025 11:23:43 -0400 Subject: [PATCH 5/9] cmGlobalVisualStudio7Generator: Update outdated comment --- Source/cmGlobalVisualStudio7Generator.cxx | 2 +- Source/cmGlobalVisualStudio7Generator.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index ddbdd3fc2e..b9343d4226 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -299,7 +299,7 @@ void cmGlobalVisualStudio7Generator::Generate() // first do the superclass method this->cmGlobalVisualStudioGenerator::Generate(); - // Now write out the DSW + // Now write out the VS Solution file. this->OutputSLNFile(); // If any solution or project files changed during the generation, // tell Visual Studio to reload them... diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 697e868767..3b82d8e603 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -83,7 +83,7 @@ public: std::vector()) override; /** - * Generate the DSW workspace file. + * Generate the VS Solution file. */ virtual void OutputSLNFile(); From 6ae4ed30d9849631e3e73d1e3b62b52e34225ca1 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 29 Aug 2025 14:54:16 -0400 Subject: [PATCH 6/9] cmGlobalVisualStudio7Generator: Factor target collection out of write method --- Source/cmGlobalVisualStudio71Generator.cxx | 10 +--------- Source/cmGlobalVisualStudio71Generator.h | 5 +++-- Source/cmGlobalVisualStudio7Generator.cxx | 11 ++++++++++- Source/cmGlobalVisualStudio7Generator.h | 5 +++-- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Source/cmGlobalVisualStudio71Generator.cxx b/Source/cmGlobalVisualStudio71Generator.cxx index 42a35b25f4..bb6ffe7e2e 100644 --- a/Source/cmGlobalVisualStudio71Generator.cxx +++ b/Source/cmGlobalVisualStudio71Generator.cxx @@ -25,7 +25,7 @@ cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator(cmake* cm) void cmGlobalVisualStudio71Generator::WriteSLNFile( std::ostream& fout, cmLocalGenerator* root, - std::vector& generators) + OrderedTargetDependSet const& orderedProjectTargets) { std::vector configs = root->GetMakefile()->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); @@ -33,14 +33,6 @@ void cmGlobalVisualStudio71Generator::WriteSLNFile( // Write out the header for a SLN file this->WriteSLNHeader(fout); - // Collect all targets under this root generator and the transitive - // closure of their dependencies. - TargetDependSet projectTargets; - TargetDependSet originalTargets; - this->GetTargetSets(projectTargets, originalTargets, root, generators); - OrderedTargetDependSet orderedProjectTargets( - projectTargets, this->GetStartupProjectName(root)); - // Generate the targets specification to a string. We will put this in // the actual .sln file later. As a side effect, this method also // populates the set of folders. diff --git a/Source/cmGlobalVisualStudio71Generator.h b/Source/cmGlobalVisualStudio71Generator.h index 8b8e37ecc1..dac7caa596 100644 --- a/Source/cmGlobalVisualStudio71Generator.h +++ b/Source/cmGlobalVisualStudio71Generator.h @@ -28,8 +28,9 @@ public: cmGlobalVisualStudio71Generator(cmake* cm); protected: - void WriteSLNFile(std::ostream& fout, cmLocalGenerator* root, - std::vector& generators) override; + void WriteSLNFile( + std::ostream& fout, cmLocalGenerator* root, + OrderedTargetDependSet const& orderedProjectTargets) override; virtual void WriteSolutionConfigurations( std::ostream& fout, std::vector const& configs); void WriteProject(std::ostream& fout, std::string const& name, diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index b9343d4226..c7335815c3 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -316,13 +316,22 @@ void cmGlobalVisualStudio7Generator::OutputSLNFile( if (generators.empty()) { return; } + + // Collect all targets under this root generator and the transitive + // closure of their dependencies. + TargetDependSet projectTargets; + TargetDependSet originalTargets; + this->GetTargetSets(projectTargets, originalTargets, root, generators); + OrderedTargetDependSet orderedProjectTargets( + projectTargets, this->GetStartupProjectName(root)); + std::string fname = GetSLNFile(root); cmGeneratedFileStream fout(fname); fout.SetCopyIfDifferent(true); if (!fout) { return; } - this->WriteSLNFile(fout, root, generators); + this->WriteSLNFile(fout, root, orderedProjectTargets); if (fout.Close()) { this->FileReplacedDuringGenerate(fname); } diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 3b82d8e603..4a6da5332e 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -141,8 +141,9 @@ protected: virtual void OutputSLNFile(cmLocalGenerator* root, std::vector& generators); - virtual void WriteSLNFile(std::ostream& fout, cmLocalGenerator* root, - std::vector& generators) = 0; + virtual void WriteSLNFile( + std::ostream& fout, cmLocalGenerator* root, + OrderedTargetDependSet const& orderedProjectTargets) = 0; virtual void WriteProject(std::ostream& fout, std::string const& name, std::string const& path, cmGeneratorTarget const* t) = 0; From 5004602715fd6ff054e88323344cee1ce9926f17 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 29 Aug 2025 15:24:37 -0400 Subject: [PATCH 7/9] cmGlobalVisualStudio7Generator: Factor folder collection out of write method --- Source/cmGlobalVisualStudio14Generator.cxx | 7 +-- Source/cmGlobalVisualStudio14Generator.h | 2 +- Source/cmGlobalVisualStudio71Generator.cxx | 21 +++----- Source/cmGlobalVisualStudio71Generator.h | 6 +-- Source/cmGlobalVisualStudio7Generator.cxx | 60 +++++++++++++--------- Source/cmGlobalVisualStudio7Generator.h | 22 +++++--- 6 files changed, 65 insertions(+), 53 deletions(-) diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index 5d4ebbdd4a..5c526c7280 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -522,7 +522,8 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion( return std::string(); } -void cmGlobalVisualStudio14Generator::AddSolutionItems(cmLocalGenerator* root) +void cmGlobalVisualStudio14Generator::AddSolutionItems(cmLocalGenerator* root, + VSFolders& vsFolders) { cmValue n = root->GetMakefile()->GetProperty("VS_SOLUTION_ITEMS"); if (cmNonempty(n)) { @@ -552,11 +553,11 @@ void cmGlobalVisualStudio14Generator::AddSolutionItems(cmLocalGenerator* root) std::string folderPath = sg->GetFullName(); // Source groups use '\' while solution folders use '/'. cmSystemTools::ReplaceString(folderPath, "\\", "/"); - folder = this->CreateSolutionFolders(folderPath); + folder = vsFolders.Create(folderPath); } else { // Lazily initialize the default solution items folder. if (defaultFolder == nullptr) { - defaultFolder = this->CreateSolutionFolders("Solution Items"); + defaultFolder = vsFolders.Create("Solution Items"); } folder = defaultFolder; } diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h index aed5de6d0b..3f73574eec 100644 --- a/Source/cmGlobalVisualStudio14Generator.h +++ b/Source/cmGlobalVisualStudio14Generator.h @@ -66,7 +66,7 @@ protected: std::string GetWindows10SDKVersion(cmMakefile* mf); - void AddSolutionItems(cmLocalGenerator* root) override; + void AddSolutionItems(cmLocalGenerator* root, VSFolders& vsFolders) override; void WriteFolderSolutionItems(std::ostream& fout, cmVisualStudioFolder const& folder) override; diff --git a/Source/cmGlobalVisualStudio71Generator.cxx b/Source/cmGlobalVisualStudio71Generator.cxx index bb6ffe7e2e..5f00bda01c 100644 --- a/Source/cmGlobalVisualStudio71Generator.cxx +++ b/Source/cmGlobalVisualStudio71Generator.cxx @@ -25,7 +25,8 @@ cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator(cmake* cm) void cmGlobalVisualStudio71Generator::WriteSLNFile( std::ostream& fout, cmLocalGenerator* root, - OrderedTargetDependSet const& orderedProjectTargets) + OrderedTargetDependSet const& orderedProjectTargets, + VSFolders const& vsFolders) { std::vector configs = root->GetMakefile()->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); @@ -33,21 +34,13 @@ void cmGlobalVisualStudio71Generator::WriteSLNFile( // Write out the header for a SLN file this->WriteSLNHeader(fout); - // Generate the targets specification to a string. We will put this in - // the actual .sln file later. As a side effect, this method also - // populates the set of folders. - std::ostringstream targetsSlnString; - this->WriteTargetsToSolution(targetsSlnString, root, orderedProjectTargets); - - this->AddSolutionItems(root); - // Generate folder specification. - if (!this->VisualStudioFolders.empty()) { - this->WriteFolders(fout); + if (!vsFolders.Folders.empty()) { + this->WriteFolders(fout, vsFolders); } // Now write the actual target specification content. - fout << targetsSlnString.str(); + this->WriteTargetsToSolution(fout, root, orderedProjectTargets); // Write out the configurations information for the solution fout << "Global\n"; @@ -59,10 +52,10 @@ void cmGlobalVisualStudio71Generator::WriteSLNFile( this->WriteTargetConfigurations(fout, configs, orderedProjectTargets); fout << "\tEndGlobalSection\n"; - if (!this->VisualStudioFolders.empty()) { + if (!vsFolders.Folders.empty()) { // Write out project folders fout << "\tGlobalSection(NestedProjects) = preSolution\n"; - this->WriteFoldersContent(fout); + this->WriteFoldersContent(fout, vsFolders); fout << "\tEndGlobalSection\n"; } diff --git a/Source/cmGlobalVisualStudio71Generator.h b/Source/cmGlobalVisualStudio71Generator.h index dac7caa596..d25b52087e 100644 --- a/Source/cmGlobalVisualStudio71Generator.h +++ b/Source/cmGlobalVisualStudio71Generator.h @@ -28,9 +28,9 @@ public: cmGlobalVisualStudio71Generator(cmake* cm); protected: - void WriteSLNFile( - std::ostream& fout, cmLocalGenerator* root, - OrderedTargetDependSet const& orderedProjectTargets) override; + void WriteSLNFile(std::ostream& fout, cmLocalGenerator* root, + OrderedTargetDependSet const& orderedProjectTargets, + VSFolders const& vsFolders) override; virtual void WriteSolutionConfigurations( std::ostream& fout, std::vector const& configs); void WriteProject(std::ostream& fout, std::string const& name, diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index c7335815c3..e52eca20d6 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -325,13 +325,16 @@ void cmGlobalVisualStudio7Generator::OutputSLNFile( OrderedTargetDependSet orderedProjectTargets( projectTargets, this->GetStartupProjectName(root)); + VSFolders vsFolders = this->CreateSolutionFolders(orderedProjectTargets); + this->AddSolutionItems(root, vsFolders); + std::string fname = GetSLNFile(root); cmGeneratedFileStream fout(fname); fout.SetCopyIfDifferent(true); if (!fout) { return; } - this->WriteSLNFile(fout, root, orderedProjectTargets); + this->WriteSLNFile(fout, root, orderedProjectTargets, vsFolders); if (fout.Close()) { this->FileReplacedDuringGenerate(fname); } @@ -382,7 +385,29 @@ void cmGlobalVisualStudio7Generator::WriteTargetConfigurations( } } -cmVisualStudioFolder* cmGlobalVisualStudio7Generator::CreateSolutionFolders( +cmGlobalVisualStudio7Generator::VSFolders +cmGlobalVisualStudio7Generator::CreateSolutionFolders( + OrderedTargetDependSet const& orderedProjectTargets) +{ + VSFolders vsFolders; + if (!this->UseFolderProperty()) { + return vsFolders; + } + for (cmGeneratorTarget const* target : orderedProjectTargets) { + if (this->IsInSolution(target) && + (target->GetProperty("EXTERNAL_MSPROJECT") || + target->GetProperty("GENERATOR_FILE_NAME"))) { + // Create "solution folder" information from FOLDER target property + if (cmVisualStudioFolder* folder = + vsFolders.Create(target->GetEffectiveFolderName())) { + folder->Projects.insert(target->GetName()); + } + } + } + return vsFolders; +} + +cmVisualStudioFolder* cmGlobalVisualStudio7Generator::VSFolders::Create( std::string const& path) { if (path.empty()) { @@ -402,7 +427,7 @@ cmVisualStudioFolder* cmGlobalVisualStudio7Generator::CreateSolutionFolders( if (cumulativePath.empty()) { cumulativePath = cmStrCat("CMAKE_FOLDER_GUID_", iter); } else { - this->VisualStudioFolders[cumulativePath].Projects.insert( + this->Folders[cumulativePath].Projects.insert( cmStrCat(cumulativePath, '/', iter)); cumulativePath = cmStrCat(cumulativePath, '/', iter); @@ -413,15 +438,13 @@ cmVisualStudioFolder* cmGlobalVisualStudio7Generator::CreateSolutionFolders( return nullptr; } - return &this->VisualStudioFolders[cumulativePath]; + return &this->Folders[cumulativePath]; } void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( std::ostream& fout, cmLocalGenerator* root, OrderedTargetDependSet const& projectTargets) { - VisualStudioFolders.clear(); - std::vector configs = root->GetMakefile()->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); @@ -429,8 +452,6 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( if (!this->IsInSolution(target)) { continue; } - bool written = false; - // handle external vc project files cmValue expath = target->GetProperty("EXTERNAL_MSPROJECT"); if (expath) { @@ -440,7 +461,6 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( this->WriteExternalProject(fout, project, location, target->GetProperty("VS_PROJECT_TYPE"), target->GetUtilities()); - written = true; } else { cmValue vcprojName = target->GetProperty("GENERATOR_FILE_NAME"); if (vcprojName) { @@ -451,28 +471,17 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( dir.clear(); // msbuild cannot handle ".\" prefix } this->WriteProject(fout, *vcprojName, dir, target); - written = true; - } - } - - // Create "solution folder" information from FOLDER target property - // - if (written && this->UseFolderProperty()) { - cmVisualStudioFolder* folder = - this->CreateSolutionFolders(target->GetEffectiveFolderName()); - - if (folder != nullptr) { - folder->Projects.insert(target->GetName()); } } } } -void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout) +void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout, + VSFolders const& vsFolders) { cm::string_view const prefix = "CMAKE_FOLDER_GUID_"; std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8"; - for (auto const& iter : VisualStudioFolders) { + for (auto const& iter : vsFolders.Folders) { std::string fullName = iter.first; std::string guid = this->GetGUID(fullName); @@ -494,9 +503,10 @@ void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout) } } -void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout) +void cmGlobalVisualStudio7Generator::WriteFoldersContent( + std::ostream& fout, VSFolders const& vsFolders) { - for (auto const& iter : VisualStudioFolders) { + for (auto const& iter : vsFolders.Folders) { std::string key(iter.first); std::string guidParent(this->GetGUID(key)); diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 4a6da5332e..f1ae133b23 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -134,6 +134,12 @@ protected: void Generate() override; + struct VSFolders + { + std::map Folders; + cmVisualStudioFolder* Create(std::string const& path); + }; + std::string const& GetDevEnvCommand(); virtual std::string FindDevEnvCommand(); @@ -143,7 +149,8 @@ protected: std::vector& generators); virtual void WriteSLNFile( std::ostream& fout, cmLocalGenerator* root, - OrderedTargetDependSet const& orderedProjectTargets) = 0; + OrderedTargetDependSet const& orderedProjectTargets, + VSFolders const& vsFolders) = 0; virtual void WriteProject(std::ostream& fout, std::string const& name, std::string const& path, cmGeneratorTarget const* t) = 0; @@ -160,7 +167,8 @@ protected: virtual void WriteSLNFooter(std::ostream& fout); std::string WriteUtilityDepend(cmGeneratorTarget const* target) override; - cmVisualStudioFolder* CreateSolutionFolders(std::string const& path); + VSFolders CreateSolutionFolders( + OrderedTargetDependSet const& orderedProjectTargets); virtual void WriteTargetsToSolution( std::ostream& fout, cmLocalGenerator* root, @@ -184,15 +192,15 @@ protected: cmGeneratorTarget const* target); std::map GUIDMap; - virtual void WriteFolders(std::ostream& fout); - virtual void WriteFoldersContent(std::ostream& fout); + virtual void WriteFolders(std::ostream& fout, VSFolders const& vsFolders); + virtual void WriteFoldersContent(std::ostream& fout, + VSFolders const& vsFolders); - virtual void AddSolutionItems(cmLocalGenerator* root) = 0; + virtual void AddSolutionItems(cmLocalGenerator* root, + VSFolders& vsFolders) = 0; virtual void WriteFolderSolutionItems( std::ostream& fout, cmVisualStudioFolder const& folder) = 0; - std::map VisualStudioFolders; - bool MarmasmEnabled; bool MasmEnabled; bool NasmEnabled; From 034cc29b89c30ebae02884f598cf0cd5b28e2641 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 29 Aug 2025 11:46:00 -0400 Subject: [PATCH 8/9] cmGlobalVisualStudio7Generator: Constify .sln write methods --- Source/cmGlobalVisualStudio14Generator.cxx | 2 +- Source/cmGlobalVisualStudio14Generator.h | 4 +-- Source/cmGlobalVisualStudio71Generator.cxx | 22 ++++++++------- Source/cmGlobalVisualStudio71Generator.h | 12 ++++---- Source/cmGlobalVisualStudio7Generator.cxx | 24 ++++++++-------- Source/cmGlobalVisualStudio7Generator.h | 33 +++++++++++----------- Source/cmGlobalVisualStudio8Generator.cxx | 6 ++-- Source/cmGlobalVisualStudio8Generator.h | 7 +++-- Source/cmGlobalVisualStudioGenerator.cxx | 4 +-- Source/cmGlobalVisualStudioGenerator.h | 4 +-- 10 files changed, 62 insertions(+), 56 deletions(-) diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index 5c526c7280..2cebf6e478 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -568,7 +568,7 @@ void cmGlobalVisualStudio14Generator::AddSolutionItems(cmLocalGenerator* root, } void cmGlobalVisualStudio14Generator::WriteFolderSolutionItems( - std::ostream& fout, cmVisualStudioFolder const& folder) + std::ostream& fout, cmVisualStudioFolder const& folder) const { fout << "\tProjectSection(SolutionItems) = preProject\n"; diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h index 3f73574eec..a71326f934 100644 --- a/Source/cmGlobalVisualStudio14Generator.h +++ b/Source/cmGlobalVisualStudio14Generator.h @@ -68,8 +68,8 @@ protected: void AddSolutionItems(cmLocalGenerator* root, VSFolders& vsFolders) override; - void WriteFolderSolutionItems(std::ostream& fout, - cmVisualStudioFolder const& folder) override; + void WriteFolderSolutionItems( + std::ostream& fout, cmVisualStudioFolder const& folder) const override; private: class Factory; diff --git a/Source/cmGlobalVisualStudio71Generator.cxx b/Source/cmGlobalVisualStudio71Generator.cxx index 5f00bda01c..0abce6bf10 100644 --- a/Source/cmGlobalVisualStudio71Generator.cxx +++ b/Source/cmGlobalVisualStudio71Generator.cxx @@ -26,7 +26,7 @@ cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator(cmake* cm) void cmGlobalVisualStudio71Generator::WriteSLNFile( std::ostream& fout, cmLocalGenerator* root, OrderedTargetDependSet const& orderedProjectTargets, - VSFolders const& vsFolders) + VSFolders const& vsFolders) const { std::vector configs = root->GetMakefile()->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); @@ -67,7 +67,7 @@ void cmGlobalVisualStudio71Generator::WriteSLNFile( } void cmGlobalVisualStudio71Generator::WriteSolutionConfigurations( - std::ostream& fout, std::vector const& configs) + std::ostream& fout, std::vector const& configs) const { fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n"; for (std::string const& i : configs) { @@ -79,10 +79,9 @@ void cmGlobalVisualStudio71Generator::WriteSolutionConfigurations( // Write a dsp file into the SLN file, // Note, that dependencies from executables to // the libraries it uses are also done here -void cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout, - std::string const& dspname, - std::string const& dir, - cmGeneratorTarget const* t) +void cmGlobalVisualStudio71Generator::WriteProject( + std::ostream& fout, std::string const& dspname, std::string const& dir, + cmGeneratorTarget const* t) const { // check to see if this is a fortran build std::string ext = ".vcproj"; @@ -133,9 +132,11 @@ void cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout, // the libraries it uses are also done here void cmGlobalVisualStudio71Generator::WriteProjectDepends( std::ostream& fout, std::string const&, std::string const&, - cmGeneratorTarget const* target) + cmGeneratorTarget const* target) const { - VSDependSet const& depends = this->VSTargetDepends[target]; + auto i = this->VSTargetDepends.find(target); + assert(i != this->VSTargetDepends.end()); + VSDependSet const& depends = i->second; for (std::string const& name : depends) { std::string guid = this->GetGUID(name); if (guid.empty()) { @@ -151,7 +152,8 @@ void cmGlobalVisualStudio71Generator::WriteProjectDepends( // executables to the libraries it uses are also done here void cmGlobalVisualStudio71Generator::WriteExternalProject( std::ostream& fout, std::string const& name, std::string const& location, - cmValue typeGuid, std::set>> const& depends) + cmValue typeGuid, + std::set>> const& depends) const { fout << "Project(\"{" << (typeGuid ? *typeGuid @@ -185,7 +187,7 @@ void cmGlobalVisualStudio71Generator::WriteProjectConfigurations( std::ostream& fout, std::string const& name, cmGeneratorTarget const& target, std::vector const& configs, std::set const& configsPartOfDefaultBuild, - std::string const& platformMapping) + std::string const& platformMapping) const { std::string const& platformName = !platformMapping.empty() ? platformMapping : this->GetPlatformName(); diff --git a/Source/cmGlobalVisualStudio71Generator.h b/Source/cmGlobalVisualStudio71Generator.h index d25b52087e..0d0e83881d 100644 --- a/Source/cmGlobalVisualStudio71Generator.h +++ b/Source/cmGlobalVisualStudio71Generator.h @@ -30,24 +30,24 @@ public: protected: void WriteSLNFile(std::ostream& fout, cmLocalGenerator* root, OrderedTargetDependSet const& orderedProjectTargets, - VSFolders const& vsFolders) override; + VSFolders const& vsFolders) const override; virtual void WriteSolutionConfigurations( - std::ostream& fout, std::vector const& configs); + std::ostream& fout, std::vector const& configs) const; void WriteProject(std::ostream& fout, std::string const& name, std::string const& path, - cmGeneratorTarget const* t) override; + cmGeneratorTarget const* t) const override; void WriteProjectDepends(std::ostream& fout, std::string const& name, std::string const& path, - cmGeneratorTarget const* t) override; + cmGeneratorTarget const* t) const override; void WriteProjectConfigurations( std::ostream& fout, std::string const& name, cmGeneratorTarget const& target, std::vector const& configs, std::set const& configsPartOfDefaultBuild, - std::string const& platformMapping = "") override; + std::string const& platformMapping = "") const override; void WriteExternalProject( std::ostream& fout, std::string const& name, std::string const& path, cmValue typeGuid, - std::set>> const& depends) override; + std::set>> const& depends) const override; // Folders are not supported by VS 7.1. bool UseFolderProperty() const override { return false; } diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index e52eca20d6..9fe69ee569 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -350,7 +350,7 @@ void cmGlobalVisualStudio7Generator::OutputSLNFile() void cmGlobalVisualStudio7Generator::WriteTargetConfigurations( std::ostream& fout, std::vector const& configs, - OrderedTargetDependSet const& projectTargets) + OrderedTargetDependSet const& projectTargets) const { // loop over again and write out configurations for each target // in the solution @@ -443,7 +443,7 @@ cmVisualStudioFolder* cmGlobalVisualStudio7Generator::VSFolders::Create( void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( std::ostream& fout, cmLocalGenerator* root, - OrderedTargetDependSet const& projectTargets) + OrderedTargetDependSet const& projectTargets) const { std::vector configs = root->GetMakefile()->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); @@ -476,8 +476,8 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( } } -void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout, - VSFolders const& vsFolders) +void cmGlobalVisualStudio7Generator::WriteFolders( + std::ostream& fout, VSFolders const& vsFolders) const { cm::string_view const prefix = "CMAKE_FOLDER_GUID_"; std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8"; @@ -504,7 +504,7 @@ void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout, } void cmGlobalVisualStudio7Generator::WriteFoldersContent( - std::ostream& fout, VSFolders const& vsFolders) + std::ostream& fout, VSFolders const& vsFolders) const { for (auto const& iter : vsFolders.Folders) { std::string key(iter.first); @@ -520,7 +520,7 @@ void cmGlobalVisualStudio7Generator::WriteFoldersContent( } std::string cmGlobalVisualStudio7Generator::ConvertToSolutionPath( - std::string const& path) + std::string const& path) const { // Convert to backslashes. Do not use ConvertToOutputPath because // we will add quoting ourselves, and we know these projects always @@ -534,7 +534,7 @@ std::string cmGlobalVisualStudio7Generator::ConvertToSolutionPath( } void cmGlobalVisualStudio7Generator::WriteSLNGlobalSections( - std::ostream& fout, cmLocalGenerator* root) + std::ostream& fout, cmLocalGenerator* root) const { std::string const guid = this->GetGUID(cmStrCat(root->GetProjectName(), ".sln")); @@ -600,7 +600,7 @@ void cmGlobalVisualStudio7Generator::WriteSLNGlobalSections( } // Standard end of dsw file -void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout) +void cmGlobalVisualStudio7Generator::WriteSLNFooter(std::ostream& fout) const { fout << "EndGlobal\n"; } @@ -668,7 +668,8 @@ std::string cmGlobalVisualStudio7Generator::WriteUtilityDepend( return pname; } -std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name) +std::string cmGlobalVisualStudio7Generator::GetGUID( + std::string const& name) const { std::string const& guidStoreName = cmStrCat(name, "_GUID_CMAKE"); if (cmValue storedGUID = @@ -702,7 +703,7 @@ void cmGlobalVisualStudio7Generator::AppendDirectoryForConfig( std::set cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild( std::vector const& configs, OrderedTargetDependSet const& projectTargets, - cmGeneratorTarget const* target) + cmGeneratorTarget const* target) const { std::set activeConfigs; // if it is a utility target then only make it part of the @@ -745,7 +746,8 @@ std::set cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild( } bool cmGlobalVisualStudio7Generator::IsDependedOn( - OrderedTargetDependSet const& projectTargets, cmGeneratorTarget const* gtIn) + OrderedTargetDependSet const& projectTargets, + cmGeneratorTarget const* gtIn) const { return std::any_of(projectTargets.begin(), projectTargets.end(), [this, gtIn](cmTargetDepend const& l) { diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index f1ae133b23..f35f6c6b60 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -88,7 +88,7 @@ public: virtual void OutputSLNFile(); //! Lookup a stored GUID or compute one deterministically. - std::string GetGUID(std::string const& name); + std::string GetGUID(std::string const& name) const; /** Append the subdirectory for the given configuration. */ void AppendDirectoryForConfig(std::string const& prefix, @@ -150,21 +150,21 @@ protected: virtual void WriteSLNFile( std::ostream& fout, cmLocalGenerator* root, OrderedTargetDependSet const& orderedProjectTargets, - VSFolders const& vsFolders) = 0; + VSFolders const& vsFolders) const = 0; virtual void WriteProject(std::ostream& fout, std::string const& name, std::string const& path, - cmGeneratorTarget const* t) = 0; + cmGeneratorTarget const* t) const = 0; virtual void WriteProjectDepends(std::ostream& fout, std::string const& name, std::string const& path, - cmGeneratorTarget const* t) = 0; + cmGeneratorTarget const* t) const = 0; virtual void WriteProjectConfigurations( std::ostream& fout, std::string const& name, cmGeneratorTarget const& target, std::vector const& configs, std::set const& configsPartOfDefaultBuild, - std::string const& platformMapping = "") = 0; + std::string const& platformMapping = "") const = 0; virtual void WriteSLNGlobalSections(std::ostream& fout, - cmLocalGenerator* root); - virtual void WriteSLNFooter(std::ostream& fout); + cmLocalGenerator* root) const; + virtual void WriteSLNFooter(std::ostream& fout) const; std::string WriteUtilityDepend(cmGeneratorTarget const* target) override; VSFolders CreateSolutionFolders( @@ -172,34 +172,35 @@ protected: virtual void WriteTargetsToSolution( std::ostream& fout, cmLocalGenerator* root, - OrderedTargetDependSet const& projectTargets); + OrderedTargetDependSet const& projectTargets) const; virtual void WriteTargetConfigurations( std::ostream& fout, std::vector const& configs, - OrderedTargetDependSet const& projectTargets); + OrderedTargetDependSet const& projectTargets) const; virtual void WriteExternalProject( std::ostream& fout, std::string const& name, std::string const& path, cmValue typeGuid, - std::set>> const& dependencies) = 0; + std::set>> const& dependencies) const = 0; - std::string ConvertToSolutionPath(std::string const& path); + std::string ConvertToSolutionPath(std::string const& path) const; std::set IsPartOfDefaultBuild( std::vector const& configs, OrderedTargetDependSet const& projectTargets, - cmGeneratorTarget const* target); + cmGeneratorTarget const* target) const; bool IsDependedOn(OrderedTargetDependSet const& projectTargets, - cmGeneratorTarget const* target); + cmGeneratorTarget const* target) const; std::map GUIDMap; - virtual void WriteFolders(std::ostream& fout, VSFolders const& vsFolders); + virtual void WriteFolders(std::ostream& fout, + VSFolders const& vsFolders) const; virtual void WriteFoldersContent(std::ostream& fout, - VSFolders const& vsFolders); + VSFolders const& vsFolders) const; virtual void AddSolutionItems(cmLocalGenerator* root, VSFolders& vsFolders) = 0; virtual void WriteFolderSolutionItems( - std::ostream& fout, cmVisualStudioFolder const& folder) = 0; + std::ostream& fout, cmVisualStudioFolder const& folder) const = 0; bool MarmasmEnabled; bool MasmEnabled; diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index e8edb0354e..db7b1419e6 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -363,7 +363,7 @@ void cmGlobalVisualStudio8Generator::AddExtraIDETargets() } void cmGlobalVisualStudio8Generator::WriteSolutionConfigurations( - std::ostream& fout, std::vector const& configs) + std::ostream& fout, std::vector const& configs) const { fout << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n"; for (std::string const& i : configs) { @@ -377,7 +377,7 @@ void cmGlobalVisualStudio8Generator::WriteProjectConfigurations( std::ostream& fout, std::string const& name, cmGeneratorTarget const& target, std::vector const& configs, std::set const& configsPartOfDefaultBuild, - std::string const& platformMapping) + std::string const& platformMapping) const { std::string guid = this->GetGUID(name); for (std::string const& i : configs) { @@ -460,7 +460,7 @@ bool cmGlobalVisualStudio8Generator::ComputeTargetDepends() void cmGlobalVisualStudio8Generator::WriteProjectDepends( std::ostream& fout, std::string const&, std::string const&, - cmGeneratorTarget const* gt) + cmGeneratorTarget const* gt) const { TargetDependSet const& unordered = this->GetTargetDirectDepends(gt); OrderedTargetDependSet depends(unordered, std::string()); diff --git a/Source/cmGlobalVisualStudio8Generator.h b/Source/cmGlobalVisualStudio8Generator.h index 52f94bfabf..23032d71aa 100644 --- a/Source/cmGlobalVisualStudio8Generator.h +++ b/Source/cmGlobalVisualStudio8Generator.h @@ -73,16 +73,17 @@ protected: static cmIDEFlagTable const* GetExtraFlagTableVS8(); void WriteSolutionConfigurations( - std::ostream& fout, std::vector const& configs) override; + std::ostream& fout, + std::vector const& configs) const override; void WriteProjectConfigurations( std::ostream& fout, std::string const& name, cmGeneratorTarget const& target, std::vector const& configs, std::set const& configsPartOfDefaultBuild, - std::string const& platformMapping = "") override; + std::string const& platformMapping = "") const override; bool ComputeTargetDepends() override; void WriteProjectDepends(std::ostream& fout, std::string const& name, std::string const& path, - cmGeneratorTarget const* t) override; + cmGeneratorTarget const* t) const override; bool UseFolderProperty() const override; diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index c905a4e8e1..c903f74f02 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -119,7 +119,7 @@ char const* cmGlobalVisualStudioGenerator::GetIDEVersion() const return ""; } -void cmGlobalVisualStudioGenerator::WriteSLNHeader(std::ostream& fout) +void cmGlobalVisualStudioGenerator::WriteSLNHeader(std::ostream& fout) const { char utf8bom[] = { char(0xEF), char(0xBB), char(0xBF) }; fout.write(utf8bom, 3); @@ -780,7 +780,7 @@ void RegisterVisualStudioMacros(std::string const& macrosFile, } } bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly( - cmGeneratorTarget const* gt) + cmGeneratorTarget const* gt) const { // If there's only one source language, Fortran has to be used // in order for the sources to compile. diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h index 2fce9bbcdc..3a68ec655f 100644 --- a/Source/cmGlobalVisualStudioGenerator.h +++ b/Source/cmGlobalVisualStudioGenerator.h @@ -93,7 +93,7 @@ public: void CallVisualStudioMacro(MacroName m, std::string const& vsSolutionFile); // return true if target is fortran only - bool TargetIsFortranOnly(cmGeneratorTarget const* gt); + bool TargetIsFortranOnly(cmGeneratorTarget const* gt) const; // return true if target should be included in solution. virtual bool IsInSolution(cmGeneratorTarget const* gt) const; @@ -172,7 +172,7 @@ protected: char const* GetIDEVersion() const; - void WriteSLNHeader(std::ostream& fout); + void WriteSLNHeader(std::ostream& fout) const; bool ComputeTargetDepends() override; class VSDependSet : public std::set From 78d9564d5056d59ffd74d911800e729dfc6698a2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 29 Aug 2025 15:47:46 -0400 Subject: [PATCH 9/9] cmGlobalVisualStudio7Generator: Inline short method at only call site --- Source/cmGlobalVisualStudio7Generator.cxx | 15 +++++---------- Source/cmGlobalVisualStudio7Generator.h | 5 ----- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 9fe69ee569..9e4ead484e 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -299,8 +299,11 @@ void cmGlobalVisualStudio7Generator::Generate() // first do the superclass method this->cmGlobalVisualStudioGenerator::Generate(); - // Now write out the VS Solution file. - this->OutputSLNFile(); + // Now write out the VS Solution files. + for (auto& it : this->ProjectMap) { + this->OutputSLNFile(it.second[0], it.second); + } + // If any solution or project files changed during the generation, // tell Visual Studio to reload them... if (!cmSystemTools::GetErrorOccurredFlag() && @@ -340,14 +343,6 @@ void cmGlobalVisualStudio7Generator::OutputSLNFile( } } -// output the SLN file -void cmGlobalVisualStudio7Generator::OutputSLNFile() -{ - for (auto& it : this->ProjectMap) { - this->OutputSLNFile(it.second[0], it.second); - } -} - void cmGlobalVisualStudio7Generator::WriteTargetConfigurations( std::ostream& fout, std::vector const& configs, OrderedTargetDependSet const& projectTargets) const diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index f35f6c6b60..a63bc4c254 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -82,11 +82,6 @@ public: std::vector const& makeOptions = std::vector()) override; - /** - * Generate the VS Solution file. - */ - virtual void OutputSLNFile(); - //! Lookup a stored GUID or compute one deterministically. std::string GetGUID(std::string const& name) const;