cmake/Source/cmVisualStudioWCEPlatformParser.cxx

140 lines
4.1 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2013-03-16 19:13:01 +02:00
#include "cmVisualStudioWCEPlatformParser.h"
2016-07-09 11:21:54 +02:00
2013-03-16 19:13:01 +02:00
#include "cmGlobalVisualStudioGenerator.h"
#include "cmXMLParser.h"
int cmVisualStudioWCEPlatformParser::ParseVersion(const char* version)
{
const std::string registryBase =
cmGlobalVisualStudioGenerator::GetRegistryBase(version);
const std::string vckey = registryBase + "\\Setup\\VC;ProductDir";
const std::string vskey = registryBase + "\\Setup\\VS;ProductDir";
2016-07-09 11:21:54 +02:00
if (!cmSystemTools::ReadRegistryValue(vckey.c_str(), this->VcInstallDir,
cmSystemTools::KeyWOW64_32) ||
!cmSystemTools::ReadRegistryValue(vskey.c_str(), this->VsInstallDir,
cmSystemTools::KeyWOW64_32)) {
2013-03-16 19:13:01 +02:00
return 0;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
cmSystemTools::ConvertToUnixSlashes(this->VcInstallDir);
cmSystemTools::ConvertToUnixSlashes(this->VsInstallDir);
this->VcInstallDir.append("/");
this->VsInstallDir.append("/");
const std::string configFilename =
this->VcInstallDir + "vcpackages/WCE.VCPlatform.config";
return this->ParseFile(configFilename.c_str());
}
std::string cmVisualStudioWCEPlatformParser::GetOSVersion() const
{
2016-07-09 11:21:54 +02:00
if (this->OSMinorVersion.empty()) {
2013-03-16 19:13:01 +02:00
return OSMajorVersion;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
return OSMajorVersion + "." + OSMinorVersion;
}
const char* cmVisualStudioWCEPlatformParser::GetArchitectureFamily() const
{
std::map<std::string, std::string>::const_iterator it =
this->Macros.find("ARCHFAM");
2016-07-09 11:21:54 +02:00
if (it != this->Macros.end()) {
2013-03-16 19:13:01 +02:00
return it->second.c_str();
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
return 0;
}
2015-04-27 22:25:09 +02:00
void cmVisualStudioWCEPlatformParser::StartElement(const std::string& name,
2013-03-16 19:13:01 +02:00
const char** attributes)
{
2016-07-09 11:21:54 +02:00
if (this->FoundRequiredName) {
2013-03-16 19:13:01 +02:00
return;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2018-01-26 17:06:56 +01:00
this->CharacterData.clear();
2013-03-16 19:13:01 +02:00
2016-07-09 11:21:54 +02:00
if (name == "PlatformData") {
2018-01-26 17:06:56 +01:00
this->PlatformName.clear();
this->OSMajorVersion.clear();
this->OSMinorVersion.clear();
2013-03-16 19:13:01 +02:00
this->Macros.clear();
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2016-07-09 11:21:54 +02:00
if (name == "Macro") {
2013-03-16 19:13:01 +02:00
std::string macroName;
std::string macroValue;
2016-07-09 11:21:54 +02:00
for (const char** attr = attributes; *attr; attr += 2) {
if (strcmp(attr[0], "Name") == 0) {
2013-03-16 19:13:01 +02:00
macroName = attr[1];
2016-07-09 11:21:54 +02:00
} else if (strcmp(attr[0], "Value") == 0) {
2013-03-16 19:13:01 +02:00
macroValue = attr[1];
}
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2016-07-09 11:21:54 +02:00
if (!macroName.empty()) {
2013-03-16 19:13:01 +02:00
this->Macros[macroName] = macroValue;
}
2016-07-09 11:21:54 +02:00
} else if (name == "Directories") {
for (const char** attr = attributes; *attr; attr += 2) {
if (strcmp(attr[0], "Include") == 0) {
2013-03-16 19:13:01 +02:00
this->Include = attr[1];
2016-07-09 11:21:54 +02:00
} else if (strcmp(attr[0], "Library") == 0) {
2013-03-16 19:13:01 +02:00
this->Library = attr[1];
2016-07-09 11:21:54 +02:00
} else if (strcmp(attr[0], "Path") == 0) {
2013-03-16 19:13:01 +02:00
this->Path = attr[1];
}
}
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
}
2015-04-27 22:25:09 +02:00
void cmVisualStudioWCEPlatformParser::EndElement(const std::string& name)
2013-03-16 19:13:01 +02:00
{
2016-07-09 11:21:54 +02:00
if (!this->RequiredName) {
if (name == "PlatformName") {
2013-03-16 19:13:01 +02:00
this->AvailablePlatforms.push_back(this->CharacterData);
}
2016-07-09 11:21:54 +02:00
return;
}
2013-03-16 19:13:01 +02:00
2016-07-09 11:21:54 +02:00
if (this->FoundRequiredName) {
2013-03-16 19:13:01 +02:00
return;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2016-07-09 11:21:54 +02:00
if (name == "PlatformName") {
2013-03-16 19:13:01 +02:00
this->PlatformName = this->CharacterData;
2016-07-09 11:21:54 +02:00
} else if (name == "OSMajorVersion") {
2013-03-16 19:13:01 +02:00
this->OSMajorVersion = this->CharacterData;
2016-07-09 11:21:54 +02:00
} else if (name == "OSMinorVersion") {
this->OSMinorVersion = this->CharacterData;
} else if (name == "Platform") {
if (this->PlatformName == this->RequiredName) {
2013-03-16 19:13:01 +02:00
this->FoundRequiredName = true;
}
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
}
void cmVisualStudioWCEPlatformParser::CharacterDataHandler(const char* data,
int length)
{
this->CharacterData.append(data, length);
}
std::string cmVisualStudioWCEPlatformParser::FixPaths(
2016-07-09 11:21:54 +02:00
const std::string& paths) const
2013-03-16 19:13:01 +02:00
{
std::string ret = paths;
cmSystemTools::ReplaceString(ret, "$(PATH)", "%PATH%");
cmSystemTools::ReplaceString(ret, "$(VCInstallDir)", VcInstallDir.c_str());
cmSystemTools::ReplaceString(ret, "$(VSInstallDir)", VsInstallDir.c_str());
2016-07-09 11:21:54 +02:00
std::replace(ret.begin(), ret.end(), '\\', '/');
2013-03-16 19:13:01 +02:00
cmSystemTools::ReplaceString(ret, "//", "/");
2016-07-09 11:21:54 +02:00
std::replace(ret.begin(), ret.end(), '/', '\\');
2013-03-16 19:13:01 +02:00
return ret;
}