cmVisualStudioWCEPlatformParser.cxx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2012 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmVisualStudioWCEPlatformParser.h"
  11. #include "cmGlobalVisualStudioGenerator.h"
  12. #include "cmXMLParser.h"
  13. int cmVisualStudioWCEPlatformParser::ParseVersion(const char* version)
  14. {
  15. const std::string registryBase =
  16. cmGlobalVisualStudioGenerator::GetRegistryBase(version);
  17. const std::string vckey = registryBase + "\\Setup\\VC;ProductDir";
  18. const std::string vskey = registryBase + "\\Setup\\VS;ProductDir";
  19. if(!cmSystemTools::ReadRegistryValue(vckey.c_str(), this->VcInstallDir) ||
  20. !cmSystemTools::ReadRegistryValue(vskey.c_str(), this->VsInstallDir))
  21. {
  22. return 0;
  23. }
  24. cmSystemTools::ConvertToUnixSlashes(this->VcInstallDir);
  25. cmSystemTools::ConvertToUnixSlashes(this->VsInstallDir);
  26. this->VcInstallDir.append("/");
  27. this->VsInstallDir.append("/");
  28. const std::string configFilename =
  29. this->VcInstallDir + "vcpackages/WCE.VCPlatform.config";
  30. return this->ParseFile(configFilename.c_str());
  31. }
  32. std::string cmVisualStudioWCEPlatformParser::GetOSVersion() const
  33. {
  34. if (this->OSMinorVersion.empty())
  35. {
  36. return OSMajorVersion;
  37. }
  38. return OSMajorVersion + "." + OSMinorVersion;
  39. }
  40. const char* cmVisualStudioWCEPlatformParser::GetArchitectureFamily() const
  41. {
  42. std::map<std::string, std::string>::const_iterator it =
  43. this->Macros.find("ARCHFAM");
  44. if (it != this->Macros.end())
  45. {
  46. return it->second.c_str();
  47. }
  48. return 0;
  49. }
  50. void cmVisualStudioWCEPlatformParser::StartElement(const char* name,
  51. const char** attributes)
  52. {
  53. if(this->FoundRequiredName)
  54. {
  55. return;
  56. }
  57. this->CharacterData = "";
  58. if(strcmp(name, "PlatformData") == 0)
  59. {
  60. this->PlatformName = "";
  61. this->OSMajorVersion = "";
  62. this->OSMinorVersion = "";
  63. this->Macros.clear();
  64. }
  65. if(strcmp(name, "Macro") == 0)
  66. {
  67. std::string macroName;
  68. std::string macroValue;
  69. for(const char** attr = attributes; *attr; attr += 2)
  70. {
  71. if(strcmp(attr[0], "Name") == 0)
  72. {
  73. macroName = attr[1];
  74. }
  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(strcmp(name, "Directories") == 0)
  86. {
  87. for(const char** attr = attributes; *attr; attr += 2)
  88. {
  89. if(strcmp(attr[0], "Include") == 0)
  90. {
  91. this->Include = attr[1];
  92. }
  93. else if(strcmp(attr[0], "Library") == 0)
  94. {
  95. this->Library = attr[1];
  96. }
  97. else if(strcmp(attr[0], "Path") == 0)
  98. {
  99. this->Path = attr[1];
  100. }
  101. }
  102. }
  103. }
  104. void cmVisualStudioWCEPlatformParser::EndElement(const char* name)
  105. {
  106. if(!this->RequiredName)
  107. {
  108. if(strcmp(name, "PlatformName") == 0)
  109. {
  110. this->AvailablePlatforms.push_back(this->CharacterData);
  111. }
  112. return;
  113. }
  114. if(this->FoundRequiredName)
  115. {
  116. return;
  117. }
  118. if(strcmp(name, "PlatformName") == 0)
  119. {
  120. this->PlatformName = this->CharacterData;
  121. }
  122. else if(strcmp(name, "OSMajorVersion") == 0)
  123. {
  124. this->OSMajorVersion = this->CharacterData;
  125. }
  126. else if(strcmp(name, "OSMinorVersion") == 0)
  127. {
  128. this->OSMinorVersion = this->CharacterData;
  129. }
  130. else if(strcmp(name, "Platform") == 0)
  131. {
  132. if(this->PlatformName == this->RequiredName)
  133. {
  134. this->FoundRequiredName = true;
  135. }
  136. }
  137. }
  138. void cmVisualStudioWCEPlatformParser::CharacterDataHandler(const char* data,
  139. int length)
  140. {
  141. this->CharacterData.append(data, length);
  142. }
  143. std::string cmVisualStudioWCEPlatformParser::FixPaths(
  144. const std::string& paths) const
  145. {
  146. std::string ret = paths;
  147. cmSystemTools::ReplaceString(ret, "$(PATH)", "%PATH%");
  148. cmSystemTools::ReplaceString(ret, "$(VCInstallDir)", VcInstallDir.c_str());
  149. cmSystemTools::ReplaceString(ret, "$(VSInstallDir)", VsInstallDir.c_str());
  150. cmSystemTools::ReplaceString(ret, "\\", "/");
  151. cmSystemTools::ReplaceString(ret, "//", "/");
  152. cmSystemTools::ReplaceString(ret, "/", "\\");
  153. return ret;
  154. }