diff options
author | David Cole <david.cole@kitware.com> | 2010-09-03 17:53:22 (GMT) |
---|---|---|
committer | David Cole <david.cole@kitware.com> | 2010-09-03 17:53:22 (GMT) |
commit | e6ac0aacf6c3ce17141870e252fda77d994782d3 (patch) | |
tree | 19890ba590b7c66cd20efe14c32841441e9d6a3e /Source/cmGlobalVisualStudio7Generator.cxx | |
parent | 11756b9608c7cf59a832296790b6938614cd6597 (diff) | |
download | CMake-e6ac0aacf6c3ce17141870e252fda77d994782d3.zip CMake-e6ac0aacf6c3ce17141870e252fda77d994782d3.tar.gz CMake-e6ac0aacf6c3ce17141870e252fda77d994782d3.tar.bz2 |
Add FOLDER target property, for IDEs (#3796)
This work was started from a patch by Thomas Schiffer.
Thanks, Thomas!
See the newly added documentation of the FOLDER target
property for details.
Also added global properties, USE_FOLDERS and
PREDEFINED_TARGETS_FOLDER. See new docs here, too.
By default, the FOLDER target property is used to organize
targets into folders in IDEs that have support for such
organization.
This commit adds "solution folder" support to the Visual
Studio generators. Currently works with versions 7 through
10.
Also, use the new FOLDER property in the ExternalProject
test and in the CMake project itself.
Diffstat (limited to 'Source/cmGlobalVisualStudio7Generator.cxx')
-rw-r--r-- | Source/cmGlobalVisualStudio7Generator.cxx | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 9631e9a..f455810 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -300,6 +300,48 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( cmLocalGenerator::START_OUTPUT); this->WriteProject(fout, vcprojName, dir.c_str(), *target); + + // Create "solution folder" information from FOLDER target property + // + if (this->UseFolderProperty()) + { + const char *targetFolder = target->GetProperty("FOLDER"); + if (targetFolder) + { + std::vector<cmsys::String> tokens = + cmSystemTools::SplitString(targetFolder, '/', false); + + std::string cumulativePath = ""; + + for(std::vector<cmsys::String>::iterator iter = tokens.begin(); + iter != tokens.end(); ++iter) + { + if(!iter->size()) + { + continue; + } + + if (cumulativePath.empty()) + { + cumulativePath = *iter; + } + else + { + VisualStudioFolders[cumulativePath].insert( + cumulativePath + "/" + *iter); + + cumulativePath = cumulativePath + "/" + *iter; + } + + this->CreateGUID(cumulativePath.c_str()); + } + + if (!cumulativePath.empty()) + { + VisualStudioFolders[cumulativePath].insert(target->GetName()); + } + } + } } } } @@ -327,6 +369,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetDepends( } } +//---------------------------------------------------------------------------- // Write a SLN file to the stream void cmGlobalVisualStudio7Generator ::WriteSLNFile(std::ostream& fout, @@ -344,6 +387,13 @@ void cmGlobalVisualStudio7Generator OrderedTargetDependSet orderedProjectTargets(projectTargets); this->WriteTargetsToSolution(fout, root, orderedProjectTargets); + + bool useFolderProperty = this->UseFolderProperty(); + if (useFolderProperty) + { + this->WriteFolders(fout); + } + // Write out the configurations information for the solution fout << "Global\n" << "\tGlobalSection(SolutionConfiguration) = preSolution\n"; @@ -361,6 +411,14 @@ void cmGlobalVisualStudio7Generator this->WriteTargetDepends(fout, orderedProjectTargets); fout << "\tEndGlobalSection\n"; + if (useFolderProperty) + { + // Write out project folders + fout << "\tGlobalSection(NestedProjects) = preSolution\n"; + this->WriteFoldersContent(fout); + fout << "\tEndGlobalSection\n"; + } + // Write out the configurations for all the targets in the project fout << "\tGlobalSection(ProjectConfiguration) = postSolution\n"; this->WriteTargetConfigurations(fout, root, orderedProjectTargets); @@ -371,6 +429,47 @@ void cmGlobalVisualStudio7Generator } //---------------------------------------------------------------------------- +void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout) +{ + std::string guidProjectTypeFolder = "2150E333-8FDC-42A3-9474-1A3956D46DE8"; + for(std::map<std::string,std::set<std::string> >::iterator iter = + VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter) + { + std::string fullName = iter->first; + std::string guid = this->GetGUID(fullName.c_str()); + std::string nameOnly = cmSystemTools::GetFilenameName(fullName); + cmSystemTools::ReplaceString(fullName, "/", "\\"); + + fout << "Project(\"{" << + guidProjectTypeFolder << "}\") = \"" << + nameOnly << "\", \"" << + fullName << "\", \"{" << + guid << + "}\"\nEndProject\n"; + } +} + +//---------------------------------------------------------------------------- +void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout) +{ + for(std::map<std::string,std::set<std::string> >::iterator iter = + VisualStudioFolders.begin(); iter != VisualStudioFolders.end(); ++iter) + { + std::string key(iter->first); + std::string guidParent(this->GetGUID(key.c_str())); + + for(std::set<std::string>::iterator it = iter->second.begin(); + it != iter->second.end(); ++it) + { + std::string value(*it); + std::string guid(this->GetGUID(value.c_str())); + + fout << "\t\t{" << guid << "} = {" << guidParent << "}\n"; + } + } +} + +//---------------------------------------------------------------------------- std::string cmGlobalVisualStudio7Generator::ConvertToSolutionPath(const char* path) { |