CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmVisualStudioSlnData.cxx
blobf685158957f72fc6994878e356b8dda9894f2611
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #include "cmVisualStudioSlnData.h"
5 #include <cstddef>
6 #include <utility>
8 #include "cmStringAlgorithms.h"
9 #include "cmSystemTools.h"
11 void cmSlnProjectEntry::AddProjectConfiguration(
12 const std::string& solutionConfiguration,
13 const std::string& projectConfiguration)
15 projectConfigurationMap[solutionConfiguration] = projectConfiguration;
18 std::string cmSlnProjectEntry::GetProjectConfiguration(
19 const std::string& solutionConfiguration)
21 return projectConfigurationMap[solutionConfiguration];
24 cm::optional<cmSlnProjectEntry> cmSlnData::GetProjectByGUID(
25 const std::string& projectGUID) const
27 auto it(ProjectsByGUID.find(projectGUID));
28 if (it != ProjectsByGUID.end()) {
29 return it->second;
31 return cm::nullopt;
34 cm::optional<cmSlnProjectEntry> cmSlnData::GetProjectByName(
35 const std::string& projectName) const
37 auto it(ProjectNameIndex.find(projectName));
38 if (it != ProjectNameIndex.end()) {
39 return it->second->second;
41 return cm::nullopt;
44 std::vector<cmSlnProjectEntry> cmSlnData::GetProjects() const
46 auto it(this->ProjectNameIndex.begin());
47 auto itEnd(this->ProjectNameIndex.end());
48 std::vector<cmSlnProjectEntry> result;
49 for (; it != itEnd; ++it) {
50 result.push_back(it->second->second);
52 return result;
55 cmSlnProjectEntry* cmSlnData::AddProject(
56 const std::string& projectGUID, const std::string& projectName,
57 const std::string& projectRelativePath)
59 auto it(ProjectsByGUID.find(projectGUID));
60 if (it != ProjectsByGUID.end()) {
61 return nullptr;
63 it = ProjectsByGUID
64 .insert(ProjectStorage::value_type(
65 projectGUID,
66 cmSlnProjectEntry(projectGUID, projectName, projectRelativePath)))
67 .first;
68 ProjectNameIndex[projectName] = it;
69 return &it->second;
72 std::string cmSlnData::GetConfigurationTarget(
73 const std::string& projectName, const std::string& solutionConfiguration,
74 const std::string& platformName)
76 std::string solutionTarget =
77 cmStrCat(solutionConfiguration, '|', platformName);
78 cm::optional<cmSlnProjectEntry> project = GetProjectByName(projectName);
79 if (!project) {
80 return platformName;
83 std::string projectTarget = project->GetProjectConfiguration(solutionTarget);
84 if (projectTarget.empty()) {
85 return platformName;
88 std::vector<std::string> targetElements =
89 cmSystemTools::SplitString(projectTarget, '|');
90 if (targetElements.size() != 2) {
91 return platformName;
94 return targetElements[1];