resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmVisualStudioWCEPlatformParser.cxx
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 "cmVisualStudioWCEPlatformParser.h"
4
5 #include <algorithm>
6 #include <cstring>
7 #include <utility>
8
9 #include "cmGlobalVisualStudioGenerator.h"
10 #include "cmSystemTools.h"
11
12 int cmVisualStudioWCEPlatformParser::ParseVersion(const char* version)
13 {
14   const std::string registryBase =
15     cmGlobalVisualStudioGenerator::GetRegistryBase(version);
16   const std::string vckey = registryBase + "\\Setup\\VC;ProductDir";
17   const std::string vskey = registryBase + "\\Setup\\VS;ProductDir";
18
19   if (!cmSystemTools::ReadRegistryValue(vckey.c_str(), this->VcInstallDir,
20                                         cmSystemTools::KeyWOW64_32) ||
21       !cmSystemTools::ReadRegistryValue(vskey.c_str(), this->VsInstallDir,
22                                         cmSystemTools::KeyWOW64_32)) {
23     return 0;
24   }
25   cmSystemTools::ConvertToUnixSlashes(this->VcInstallDir);
26   cmSystemTools::ConvertToUnixSlashes(this->VsInstallDir);
27   this->VcInstallDir.append("/");
28   this->VsInstallDir.append("/");
29
30   const std::string configFilename =
31     this->VcInstallDir + "vcpackages/WCE.VCPlatform.config";
32
33   return this->ParseFile(configFilename.c_str());
34 }
35
36 std::string cmVisualStudioWCEPlatformParser::GetOSVersion() const
37 {
38   if (this->OSMinorVersion.empty()) {
39     return OSMajorVersion;
40   }
41
42   return OSMajorVersion + "." + OSMinorVersion;
43 }
44
45 const char* cmVisualStudioWCEPlatformParser::GetArchitectureFamily() const
46 {
47   std::map<std::string, std::string>::const_iterator it =
48     this->Macros.find("ARCHFAM");
49   if (it != this->Macros.end()) {
50     return it->second.c_str();
51   }
52
53   return 0;
54 }
55
56 void cmVisualStudioWCEPlatformParser::StartElement(const std::string& name,
57                                                    const char** attributes)
58 {
59   if (this->FoundRequiredName) {
60     return;
61   }
62
63   this->CharacterData.clear();
64
65   if (name == "PlatformData") {
66     this->PlatformName.clear();
67     this->OSMajorVersion.clear();
68     this->OSMinorVersion.clear();
69     this->Macros.clear();
70   }
71
72   if (name == "Macro") {
73     std::string macroName;
74     std::string macroValue;
75
76     for (const char** attr = attributes; *attr; attr += 2) {
77       if (strcmp(attr[0], "Name") == 0) {
78         macroName = attr[1];
79       } else if (strcmp(attr[0], "Value") == 0) {
80         macroValue = attr[1];
81       }
82     }
83
84     if (!macroName.empty()) {
85       this->Macros[macroName] = macroValue;
86     }
87   } else if (name == "Directories") {
88     for (const char** attr = attributes; *attr; attr += 2) {
89       if (strcmp(attr[0], "Include") == 0) {
90         this->Include = attr[1];
91       } else if (strcmp(attr[0], "Library") == 0) {
92         this->Library = attr[1];
93       } else if (strcmp(attr[0], "Path") == 0) {
94         this->Path = attr[1];
95       }
96     }
97   }
98 }
99
100 void cmVisualStudioWCEPlatformParser::EndElement(const std::string& name)
101 {
102   if (!this->RequiredName) {
103     if (name == "PlatformName") {
104       this->AvailablePlatforms.push_back(this->CharacterData);
105     }
106     return;
107   }
108
109   if (this->FoundRequiredName) {
110     return;
111   }
112
113   if (name == "PlatformName") {
114     this->PlatformName = this->CharacterData;
115   } else if (name == "OSMajorVersion") {
116     this->OSMajorVersion = this->CharacterData;
117   } else if (name == "OSMinorVersion") {
118     this->OSMinorVersion = this->CharacterData;
119   } else if (name == "Platform") {
120     if (this->PlatformName == this->RequiredName) {
121       this->FoundRequiredName = true;
122     }
123   }
124 }
125
126 void cmVisualStudioWCEPlatformParser::CharacterDataHandler(const char* data,
127                                                            int length)
128 {
129   this->CharacterData.append(data, length);
130 }
131
132 std::string cmVisualStudioWCEPlatformParser::FixPaths(
133   const std::string& paths) const
134 {
135   std::string ret = paths;
136   cmSystemTools::ReplaceString(ret, "$(PATH)", "%PATH%");
137   cmSystemTools::ReplaceString(ret, "$(VCInstallDir)", VcInstallDir.c_str());
138   cmSystemTools::ReplaceString(ret, "$(VSInstallDir)", VsInstallDir.c_str());
139   std::replace(ret.begin(), ret.end(), '\\', '/');
140   cmSystemTools::ReplaceString(ret, "//", "/");
141   std::replace(ret.begin(), ret.end(), '/', '\\');
142   return ret;
143 }