cmGlobalVisualStudio11Generator.cxx 6.0 KB

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