cmGlobalVisualStudio11Generator.cxx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 "cmGlobalVisualStudio11Generator.h"
  4. #include <cstring>
  5. #include <sstream>
  6. #include <utility>
  7. #include <vector>
  8. #include <cmext/string_view>
  9. #include "cmGlobalGenerator.h"
  10. #include "cmGlobalVisualStudioGenerator.h"
  11. #include "cmMakefile.h"
  12. #include "cmMessageType.h"
  13. #include "cmStringAlgorithms.h"
  14. #include "cmSystemTools.h"
  15. cmGlobalVisualStudio11Generator::cmGlobalVisualStudio11Generator(
  16. cmake* cm, const std::string& name,
  17. std::string const& platformInGeneratorName)
  18. : cmGlobalVisualStudio10Generator(cm, name, platformInGeneratorName)
  19. {
  20. }
  21. void cmGlobalVisualStudio11Generator::EnableLanguage(
  22. std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
  23. {
  24. for (std::string const& it : lang) {
  25. if (it == "ASM_MARMASM"_s) {
  26. this->MarmasmEnabled = true;
  27. }
  28. }
  29. this->AddPlatformDefinitions(mf);
  30. cmGlobalVisualStudio10Generator::EnableLanguage(lang, mf, optional);
  31. }
  32. bool cmGlobalVisualStudio11Generator::InitializeWindowsPhone(cmMakefile* mf)
  33. {
  34. if (!this->SelectWindowsPhoneToolset(this->DefaultPlatformToolset)) {
  35. std::ostringstream e;
  36. if (this->DefaultPlatformToolset.empty()) {
  37. e << this->GetName() << " supports Windows Phone '8.0', but not '"
  38. << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  39. } else {
  40. e << "A Windows Phone component with CMake requires both the Windows "
  41. "Desktop SDK as well as the Windows Phone '"
  42. << this->SystemVersion
  43. << "' SDK. Please make sure that you have both installed";
  44. }
  45. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  46. return false;
  47. }
  48. return true;
  49. }
  50. bool cmGlobalVisualStudio11Generator::InitializeWindowsStore(cmMakefile* mf)
  51. {
  52. if (!this->SelectWindowsStoreToolset(this->DefaultPlatformToolset)) {
  53. std::ostringstream e;
  54. if (this->DefaultPlatformToolset.empty()) {
  55. e << this->GetName() << " supports Windows Store '8.0', but not '"
  56. << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  57. } else {
  58. e << "A Windows Store component with CMake requires both the Windows "
  59. "Desktop SDK as well as the Windows Store '"
  60. << this->SystemVersion
  61. << "' SDK. Please make sure that you have both installed";
  62. }
  63. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  64. return false;
  65. }
  66. return true;
  67. }
  68. bool cmGlobalVisualStudio11Generator::SelectWindowsPhoneToolset(
  69. std::string& toolset) const
  70. {
  71. if (this->SystemVersion == "8.0"_s) {
  72. if (this->IsWindowsPhoneToolsetInstalled() &&
  73. this->IsWindowsDesktopToolsetInstalled()) {
  74. toolset = "v110_wp80";
  75. return true;
  76. }
  77. return false;
  78. }
  79. return this->cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset(
  80. toolset);
  81. }
  82. bool cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset(
  83. std::string& toolset) const
  84. {
  85. if (this->SystemVersion == "8.0"_s) {
  86. if (this->IsWindowsStoreToolsetInstalled() &&
  87. this->IsWindowsDesktopToolsetInstalled()) {
  88. toolset = "v110";
  89. return true;
  90. }
  91. return false;
  92. }
  93. return this->cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset(
  94. toolset);
  95. }
  96. bool cmGlobalVisualStudio11Generator::UseFolderProperty() const
  97. {
  98. // Intentionally skip up to the top-level class implementation.
  99. // Folders are not supported by the Express editions in VS10 and earlier,
  100. // but they are in VS11 Express and above.
  101. // NOLINTNEXTLINE(bugprone-parent-virtual-call)
  102. return cmGlobalGenerator::UseFolderProperty();
  103. }
  104. std::set<std::string>
  105. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs()
  106. {
  107. const char sdksKey[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  108. "Windows CE Tools\\SDKs";
  109. std::vector<std::string> subkeys;
  110. cmSystemTools::GetRegistrySubKeys(sdksKey, subkeys,
  111. cmSystemTools::KeyWOW64_32);
  112. std::set<std::string> ret;
  113. for (std::string const& i : subkeys) {
  114. std::string key = sdksKey;
  115. key += '\\';
  116. key += i;
  117. key += ';';
  118. std::string path;
  119. if (cmSystemTools::ReadRegistryValue(key, path,
  120. cmSystemTools::KeyWOW64_32) &&
  121. !path.empty()) {
  122. ret.insert(i);
  123. }
  124. }
  125. return ret;
  126. }
  127. bool cmGlobalVisualStudio11Generator::TargetSystemSupportsDeployment() const
  128. {
  129. return this->SystemIsWindowsPhone || this->SystemIsWindowsStore ||
  130. cmGlobalVisualStudio10Generator::TargetSystemSupportsDeployment();
  131. }
  132. bool cmGlobalVisualStudio11Generator::IsWindowsDesktopToolsetInstalled() const
  133. {
  134. const char desktop80Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  135. "VisualStudio\\11.0\\VC\\Libraries\\Extended";
  136. const char VS2012DesktopExpressKey[] =
  137. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  138. "WDExpress\\11.0;InstallDir";
  139. std::vector<std::string> subkeys;
  140. std::string path;
  141. return cmSystemTools::ReadRegistryValue(VS2012DesktopExpressKey, path,
  142. cmSystemTools::KeyWOW64_32) ||
  143. cmSystemTools::GetRegistrySubKeys(desktop80Key, subkeys,
  144. cmSystemTools::KeyWOW64_32);
  145. }
  146. bool cmGlobalVisualStudio11Generator::IsWindowsPhoneToolsetInstalled() const
  147. {
  148. const char wp80Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  149. "Microsoft SDKs\\WindowsPhone\\v8.0\\"
  150. "Install Path;Install Path";
  151. std::string path;
  152. cmSystemTools::ReadRegistryValue(wp80Key, path, cmSystemTools::KeyWOW64_32);
  153. return !path.empty();
  154. }
  155. bool cmGlobalVisualStudio11Generator::IsWindowsStoreToolsetInstalled() const
  156. {
  157. const char win80Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  158. "VisualStudio\\11.0\\VC\\Libraries\\Core\\Arm";
  159. std::vector<std::string> subkeys;
  160. return cmSystemTools::GetRegistrySubKeys(win80Key, subkeys,
  161. cmSystemTools::KeyWOW64_32);
  162. }