Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmVisualStudioWCEPlatformParser.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2012 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmVisualStudioWCEPlatformParser.h"
13 #include "cmGlobalVisualStudioGenerator.h"
14 #include "cmXMLParser.h"
15
16 int cmVisualStudioWCEPlatformParser::ParseVersion(const char* version)
17 {
18   const std::string registryBase =
19     cmGlobalVisualStudioGenerator::GetRegistryBase(version);
20   const std::string vckey = registryBase + "\\Setup\\VC;ProductDir";
21   const std::string vskey = registryBase + "\\Setup\\VS;ProductDir";
22
23   if(!cmSystemTools::ReadRegistryValue(vckey.c_str(),
24                                        this->VcInstallDir,
25                                        cmSystemTools::KeyWOW64_32) ||
26      !cmSystemTools::ReadRegistryValue(vskey.c_str(),
27                                        this->VsInstallDir,
28                                        cmSystemTools::KeyWOW64_32))
29     {
30     return 0;
31     }
32   cmSystemTools::ConvertToUnixSlashes(this->VcInstallDir);
33   cmSystemTools::ConvertToUnixSlashes(this->VsInstallDir);
34   this->VcInstallDir.append("/");
35   this->VsInstallDir.append("/");
36
37   const std::string configFilename =
38     this->VcInstallDir + "vcpackages/WCE.VCPlatform.config";
39
40   return this->ParseFile(configFilename.c_str());
41 }
42
43 std::string cmVisualStudioWCEPlatformParser::GetOSVersion() const
44 {
45   if (this->OSMinorVersion.empty())
46     {
47     return OSMajorVersion;
48     }
49
50   return OSMajorVersion + "." + OSMinorVersion;
51 }
52
53 const char* cmVisualStudioWCEPlatformParser::GetArchitectureFamily() const
54 {
55   std::map<std::string, std::string>::const_iterator it =
56     this->Macros.find("ARCHFAM");
57   if (it != this->Macros.end())
58     {
59     return it->second.c_str();
60     }
61
62   return 0;
63 }
64
65 void cmVisualStudioWCEPlatformParser::StartElement(const char* name,
66                                                    const char** attributes)
67 {
68   if(this->FoundRequiredName)
69     {
70     return;
71     }
72
73   this->CharacterData = "";
74
75   if(strcmp(name, "PlatformData") == 0)
76     {
77     this->PlatformName = "";
78     this->OSMajorVersion = "";
79     this->OSMinorVersion = "";
80     this->Macros.clear();
81     }
82
83   if(strcmp(name, "Macro") == 0)
84     {
85     std::string macroName;
86     std::string macroValue;
87
88     for(const char** attr = attributes; *attr; attr += 2)
89       {
90       if(strcmp(attr[0], "Name") == 0)
91         {
92         macroName = attr[1];
93         }
94       else if(strcmp(attr[0], "Value") == 0)
95         {
96         macroValue = attr[1];
97         }
98       }
99
100     if(!macroName.empty())
101       {
102       this->Macros[macroName] = macroValue;
103       }
104     }
105   else if(strcmp(name, "Directories") == 0)
106     {
107     for(const char** attr = attributes; *attr; attr += 2)
108       {
109       if(strcmp(attr[0], "Include") == 0)
110         {
111         this->Include = attr[1];
112         }
113       else if(strcmp(attr[0], "Library") == 0)
114         {
115         this->Library = attr[1];
116         }
117       else if(strcmp(attr[0], "Path") == 0)
118         {
119         this->Path = attr[1];
120         }
121       }
122     }
123 }
124
125 void cmVisualStudioWCEPlatformParser::EndElement(const char* name)
126 {
127   if(!this->RequiredName)
128     {
129     if(strcmp(name, "PlatformName") == 0)
130       {
131       this->AvailablePlatforms.push_back(this->CharacterData);
132       }
133     return;
134     }
135
136   if(this->FoundRequiredName)
137     {
138     return;
139     }
140
141   if(strcmp(name, "PlatformName") == 0)
142     {
143     this->PlatformName = this->CharacterData;
144     }
145   else if(strcmp(name, "OSMajorVersion") == 0)
146     {
147     this->OSMajorVersion = this->CharacterData;
148     }
149   else if(strcmp(name, "OSMinorVersion") == 0)
150    {
151    this->OSMinorVersion = this->CharacterData;
152    }
153   else if(strcmp(name, "Platform") == 0)
154     {
155     if(this->PlatformName == this->RequiredName)
156       {
157       this->FoundRequiredName = true;
158       }
159     }
160 }
161
162 void cmVisualStudioWCEPlatformParser::CharacterDataHandler(const char* data,
163                                                            int length)
164 {
165   this->CharacterData.append(data, length);
166 }
167
168 std::string cmVisualStudioWCEPlatformParser::FixPaths(
169     const std::string& paths) const
170 {
171   std::string ret = paths;
172   cmSystemTools::ReplaceString(ret, "$(PATH)", "%PATH%");
173   cmSystemTools::ReplaceString(ret, "$(VCInstallDir)", VcInstallDir.c_str());
174   cmSystemTools::ReplaceString(ret, "$(VSInstallDir)", VsInstallDir.c_str());
175   cmSystemTools::ReplaceString(ret, "\\", "/");
176   cmSystemTools::ReplaceString(ret, "//", "/");
177   cmSystemTools::ReplaceString(ret, "/", "\\");
178   return ret;
179 }