cmVisualStudioWCEPlatformParser.cxx 4.2 KB

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