cmGlobalVisualStudio11Generator.cxx 5.9 KB

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