cmVisualStudioWCEPlatformParser.cxx 4.07 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3
#include "cmVisualStudioWCEPlatformParser.h"
4

5 6 7 8 9
#include "cmGlobalVisualStudioGenerator.h"
#include "cmXMLParser.h"

int cmVisualStudioWCEPlatformParser::ParseVersion(const char* version)
{
10 11 12 13
  const std::string registryBase =
    cmGlobalVisualStudioGenerator::GetRegistryBase(version);
  const std::string vckey = registryBase + "\\Setup\\VC;ProductDir";
  const std::string vskey = registryBase + "\\Setup\\VS;ProductDir";
14

15 16 17 18
  if (!cmSystemTools::ReadRegistryValue(vckey.c_str(), this->VcInstallDir,
                                        cmSystemTools::KeyWOW64_32) ||
      !cmSystemTools::ReadRegistryValue(vskey.c_str(), this->VsInstallDir,
                                        cmSystemTools::KeyWOW64_32)) {
19
    return 0;
20
  }
21 22 23 24
  cmSystemTools::ConvertToUnixSlashes(this->VcInstallDir);
  cmSystemTools::ConvertToUnixSlashes(this->VsInstallDir);
  this->VcInstallDir.append("/");
  this->VsInstallDir.append("/");
25 26

  const std::string configFilename =
27
    this->VcInstallDir + "vcpackages/WCE.VCPlatform.config";
28 29 30 31 32 33

  return this->ParseFile(configFilename.c_str());
}

std::string cmVisualStudioWCEPlatformParser::GetOSVersion() const
{
34
  if (this->OSMinorVersion.empty()) {
35
    return OSMajorVersion;
36
  }
37 38 39 40 41 42 43 44

  return OSMajorVersion + "." + OSMinorVersion;
}

const char* cmVisualStudioWCEPlatformParser::GetArchitectureFamily() const
{
  std::map<std::string, std::string>::const_iterator it =
    this->Macros.find("ARCHFAM");
45
  if (it != this->Macros.end()) {
46
    return it->second.c_str();
47
  }
48 49 50 51

  return 0;
}

52
void cmVisualStudioWCEPlatformParser::StartElement(const std::string& name,
53 54
                                                   const char** attributes)
{
55
  if (this->FoundRequiredName) {
56
    return;
57
  }
58 59 60

  this->CharacterData = "";

61
  if (name == "PlatformData") {
62 63 64 65
    this->PlatformName = "";
    this->OSMajorVersion = "";
    this->OSMinorVersion = "";
    this->Macros.clear();
66
  }
67

68
  if (name == "Macro") {
69 70 71
    std::string macroName;
    std::string macroValue;

72 73
    for (const char** attr = attributes; *attr; attr += 2) {
      if (strcmp(attr[0], "Name") == 0) {
74
        macroName = attr[1];
75
      } else if (strcmp(attr[0], "Value") == 0) {
76 77
        macroValue = attr[1];
      }
78
    }
79

80
    if (!macroName.empty()) {
81 82
      this->Macros[macroName] = macroValue;
    }
83 84 85
  } else if (name == "Directories") {
    for (const char** attr = attributes; *attr; attr += 2) {
      if (strcmp(attr[0], "Include") == 0) {
86
        this->Include = attr[1];
87
      } else if (strcmp(attr[0], "Library") == 0) {
88
        this->Library = attr[1];
89
      } else if (strcmp(attr[0], "Path") == 0) {
90 91 92
        this->Path = attr[1];
      }
    }
93
  }
94 95
}

96
void cmVisualStudioWCEPlatformParser::EndElement(const std::string& name)
97
{
98 99
  if (!this->RequiredName) {
    if (name == "PlatformName") {
100 101
      this->AvailablePlatforms.push_back(this->CharacterData);
    }
102 103
    return;
  }
104

105
  if (this->FoundRequiredName) {
106
    return;
107
  }
108

109
  if (name == "PlatformName") {
110
    this->PlatformName = this->CharacterData;
111
  } else if (name == "OSMajorVersion") {
112
    this->OSMajorVersion = this->CharacterData;
113 114 115 116
  } else if (name == "OSMinorVersion") {
    this->OSMinorVersion = this->CharacterData;
  } else if (name == "Platform") {
    if (this->PlatformName == this->RequiredName) {
117 118
      this->FoundRequiredName = true;
    }
119
  }
120 121 122 123 124 125 126
}

void cmVisualStudioWCEPlatformParser::CharacterDataHandler(const char* data,
                                                           int length)
{
  this->CharacterData.append(data, length);
}
127 128

std::string cmVisualStudioWCEPlatformParser::FixPaths(
129
  const std::string& paths) const
130 131 132 133 134
{
  std::string ret = paths;
  cmSystemTools::ReplaceString(ret, "$(PATH)", "%PATH%");
  cmSystemTools::ReplaceString(ret, "$(VCInstallDir)", VcInstallDir.c_str());
  cmSystemTools::ReplaceString(ret, "$(VSInstallDir)", VsInstallDir.c_str());
135
  std::replace(ret.begin(), ret.end(), '\\', '/');
136
  cmSystemTools::ReplaceString(ret, "//", "/");
137
  std::replace(ret.begin(), ret.end(), '/', '\\');
138 139
  return ret;
}