cmVisualStudioWCEPlatformParser.cxx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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(),
  20. this->VcInstallDir,
  21. cmSystemTools::KeyWOW64_32) ||
  22. !cmSystemTools::ReadRegistryValue(vskey.c_str(),
  23. this->VsInstallDir,
  24. cmSystemTools::KeyWOW64_32))
  25. {
  26. return 0;
  27. }
  28. cmSystemTools::ConvertToUnixSlashes(this->VcInstallDir);
  29. cmSystemTools::ConvertToUnixSlashes(this->VsInstallDir);
  30. this->VcInstallDir.append("/");
  31. this->VsInstallDir.append("/");
  32. const std::string configFilename =
  33. this->VcInstallDir + "vcpackages/WCE.VCPlatform.config";
  34. return this->ParseFile(configFilename.c_str());
  35. }
  36. std::string cmVisualStudioWCEPlatformParser::GetOSVersion() const
  37. {
  38. if (this->OSMinorVersion.empty())
  39. {
  40. return OSMajorVersion;
  41. }
  42. return OSMajorVersion + "." + OSMinorVersion;
  43. }
  44. const char* cmVisualStudioWCEPlatformParser::GetArchitectureFamily() const
  45. {
  46. std::map<std::string, std::string>::const_iterator it =
  47. this->Macros.find("ARCHFAM");
  48. if (it != this->Macros.end())
  49. {
  50. return it->second.c_str();
  51. }
  52. return 0;
  53. }
  54. void cmVisualStudioWCEPlatformParser::StartElement(const std::string& name,
  55. const char** attributes)
  56. {
  57. if(this->FoundRequiredName)
  58. {
  59. return;
  60. }
  61. this->CharacterData = "";
  62. if(name == "PlatformData")
  63. {
  64. this->PlatformName = "";
  65. this->OSMajorVersion = "";
  66. this->OSMinorVersion = "";
  67. this->Macros.clear();
  68. }
  69. if(name == "Macro")
  70. {
  71. std::string macroName;
  72. std::string macroValue;
  73. for(const char** attr = attributes; *attr; attr += 2)
  74. {
  75. if(strcmp(attr[0], "Name") == 0)
  76. {
  77. macroName = attr[1];
  78. }
  79. else if(strcmp(attr[0], "Value") == 0)
  80. {
  81. macroValue = attr[1];
  82. }
  83. }
  84. if(!macroName.empty())
  85. {
  86. this->Macros[macroName] = macroValue;
  87. }
  88. }
  89. else if(name == "Directories")
  90. {
  91. for(const char** attr = attributes; *attr; attr += 2)
  92. {
  93. if(strcmp(attr[0], "Include") == 0)
  94. {
  95. this->Include = attr[1];
  96. }
  97. else if(strcmp(attr[0], "Library") == 0)
  98. {
  99. this->Library = attr[1];
  100. }
  101. else if(strcmp(attr[0], "Path") == 0)
  102. {
  103. this->Path = attr[1];
  104. }
  105. }
  106. }
  107. }
  108. void cmVisualStudioWCEPlatformParser::EndElement(const std::string& name)
  109. {
  110. if(!this->RequiredName)
  111. {
  112. if(name == "PlatformName")
  113. {
  114. this->AvailablePlatforms.push_back(this->CharacterData);
  115. }
  116. return;
  117. }
  118. if(this->FoundRequiredName)
  119. {
  120. return;
  121. }
  122. if(name == "PlatformName")
  123. {
  124. this->PlatformName = this->CharacterData;
  125. }
  126. else if(name == "OSMajorVersion")
  127. {
  128. this->OSMajorVersion = this->CharacterData;
  129. }
  130. else if(name == "OSMinorVersion")
  131. {
  132. this->OSMinorVersion = this->CharacterData;
  133. }
  134. else if(name == "Platform")
  135. {
  136. if(this->PlatformName == this->RequiredName)
  137. {
  138. this->FoundRequiredName = true;
  139. }
  140. }
  141. }
  142. void cmVisualStudioWCEPlatformParser::CharacterDataHandler(const char* data,
  143. int length)
  144. {
  145. this->CharacterData.append(data, length);
  146. }
  147. std::string cmVisualStudioWCEPlatformParser::FixPaths(
  148. const std::string& paths) const
  149. {
  150. std::string ret = paths;
  151. cmSystemTools::ReplaceString(ret, "$(PATH)", "%PATH%");
  152. cmSystemTools::ReplaceString(ret, "$(VCInstallDir)", VcInstallDir.c_str());
  153. cmSystemTools::ReplaceString(ret, "$(VSInstallDir)", VsInstallDir.c_str());
  154. cmSystemTools::ReplaceString(ret, "\\", "/");
  155. cmSystemTools::ReplaceString(ret, "//", "/");
  156. cmSystemTools::ReplaceString(ret, "/", "\\");
  157. return ret;
  158. }