cmVisualStudioWCEPlatformParser.cxx 4.1 KB

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