cmVisualStudioWCEPlatformParser.cxx 4.1 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 "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. std::map<std::string, std::string>::const_iterator it =
  39. this->Macros.find("ARCHFAM");
  40. if (it != this->Macros.end()) {
  41. return it->second.c_str();
  42. }
  43. return 0;
  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") {
  53. this->PlatformName.clear();
  54. this->OSMajorVersion.clear();
  55. this->OSMinorVersion.clear();
  56. this->Macros.clear();
  57. }
  58. if (name == "Macro") {
  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") {
  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") {
  87. this->AvailablePlatforms.push_back(this->CharacterData);
  88. }
  89. return;
  90. }
  91. if (this->FoundRequiredName) {
  92. return;
  93. }
  94. if (name == "PlatformName") {
  95. this->PlatformName = this->CharacterData;
  96. } else if (name == "OSMajorVersion") {
  97. this->OSMajorVersion = this->CharacterData;
  98. } else if (name == "OSMinorVersion") {
  99. this->OSMinorVersion = this->CharacterData;
  100. } else if (name == "Platform") {
  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. }