cmVisualStudioWCEPlatformParser.cxx 4.1 KB

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