diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 8c644abc61..febbc99059 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -375,6 +375,40 @@ void cmGlobalVisualStudio7Generator::WriteTargetConfigurations( } } +cmVisualStudioFolder* cmGlobalVisualStudio7Generator::CreateSolutionFolders( + const std::string& path) +{ + if (path.empty()) { + return nullptr; + } + + std::vector tokens = + cmSystemTools::SplitString(path, '/', false); + + std::string cumulativePath; + + for (std::string const& iter : tokens) { + if (iter.empty()) { + continue; + } + + if (cumulativePath.empty()) { + cumulativePath = cmStrCat("CMAKE_FOLDER_GUID_", iter); + } else { + this->VisualStudioFolders[cumulativePath].Projects.insert( + cmStrCat(cumulativePath, '/', iter)); + + cumulativePath = cmStrCat(cumulativePath, '/', iter); + } + } + + if (cumulativePath.empty()) { + return nullptr; + } + + return &this->VisualStudioFolders[cumulativePath]; +} + void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( std::ostream& fout, cmLocalGenerator* root, OrderedTargetDependSet const& projectTargets) @@ -421,31 +455,11 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( // Create "solution folder" information from FOLDER target property // if (written && this->UseFolderProperty()) { - const std::string targetFolder = target->GetEffectiveFolderName(); - if (!targetFolder.empty()) { - std::vector tokens = - cmSystemTools::SplitString(targetFolder, '/', false); + cmVisualStudioFolder* folder = + this->CreateSolutionFolders(target->GetEffectiveFolderName()); - std::string cumulativePath; - - for (std::string const& iter : tokens) { - if (iter.empty()) { - continue; - } - - if (cumulativePath.empty()) { - cumulativePath = cmStrCat("CMAKE_FOLDER_GUID_", iter); - } else { - VisualStudioFolders[cumulativePath].insert( - cmStrCat(cumulativePath, '/', iter)); - - cumulativePath = cmStrCat(cumulativePath, '/', iter); - } - } - - if (!cumulativePath.empty()) { - VisualStudioFolders[cumulativePath].insert(target->GetName()); - } + if (folder != nullptr) { + folder->Projects.insert(target->GetName()); } } } @@ -477,7 +491,7 @@ void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout) std::string key(iter.first); std::string guidParent(this->GetGUID(key)); - for (std::string const& it : iter.second) { + for (std::string const& it : iter.second.Projects) { std::string const& value(it); std::string guid(this->GetGUID(value)); diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 2056b2f3d0..3ac2d2c5d8 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -25,6 +25,11 @@ class cmake; template class BT; +struct cmVisualStudioFolder +{ + std::set Projects; +}; + /** \class cmGlobalVisualStudio7Generator * \brief Write a Unix makefiles. * @@ -154,6 +159,8 @@ protected: virtual void WriteSLNFooter(std::ostream& fout); std::string WriteUtilityDepend(const cmGeneratorTarget* target) override; + cmVisualStudioFolder* CreateSolutionFolders(const std::string& path); + virtual void WriteTargetsToSolution( std::ostream& fout, cmLocalGenerator* root, OrderedTargetDependSet const& projectTargets); @@ -178,7 +185,7 @@ protected: virtual void WriteFolders(std::ostream& fout); virtual void WriteFoldersContent(std::ostream& fout); - std::map> VisualStudioFolders; + std::map VisualStudioFolders; // Set during OutputSLNFile with the name of the current project. // There is one SLN file per project.