cmGlobalVisualStudio11Generator.cxx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst 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, std::string const& name)
  16. : cmGlobalVisualStudio10Generator(cm, name)
  17. {
  18. }
  19. void cmGlobalVisualStudio11Generator::EnableLanguage(
  20. std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
  21. {
  22. for (std::string const& it : lang) {
  23. if (it == "ASM_MARMASM"_s) {
  24. this->MarmasmEnabled = true;
  25. }
  26. }
  27. this->AddPlatformDefinitions(mf);
  28. cmGlobalVisualStudio10Generator::EnableLanguage(lang, mf, optional);
  29. }
  30. bool cmGlobalVisualStudio11Generator::InitializeWindowsPhone(cmMakefile* mf)
  31. {
  32. if (!this->SelectWindowsPhoneToolset(this->DefaultPlatformToolset)) {
  33. std::string e;
  34. if (this->DefaultPlatformToolset.empty()) {
  35. e = cmStrCat(this->GetName(), " supports Windows Phone '8.0', but not '",
  36. this->SystemVersion, "'. Check CMAKE_SYSTEM_VERSION.");
  37. } else {
  38. e = cmStrCat(
  39. "A Windows Phone component with CMake requires both the Windows "
  40. "Desktop SDK as well as the Windows Phone '",
  41. this->SystemVersion,
  42. "' SDK. Please make sure that you have both installed");
  43. }
  44. mf->IssueMessage(MessageType::FATAL_ERROR, e);
  45. return false;
  46. }
  47. return true;
  48. }
  49. bool cmGlobalVisualStudio11Generator::InitializeWindowsStore(cmMakefile* mf)
  50. {
  51. if (!this->SelectWindowsStoreToolset(this->DefaultPlatformToolset)) {
  52. std::string e;
  53. if (this->DefaultPlatformToolset.empty()) {
  54. e = cmStrCat(this->GetName(), " supports Windows Store '8.0', but not '",
  55. this->SystemVersion, "'. Check CMAKE_SYSTEM_VERSION.");
  56. } else {
  57. e = cmStrCat(
  58. "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);
  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. std::set<std::string>
  97. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs()
  98. {
  99. char const sdksKey[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  100. "Windows CE Tools\\SDKs";
  101. std::vector<std::string> subkeys;
  102. cmSystemTools::GetRegistrySubKeys(sdksKey, subkeys,
  103. cmSystemTools::KeyWOW64_32);
  104. std::set<std::string> ret;
  105. for (std::string const& i : subkeys) {
  106. std::string key = sdksKey;
  107. key += '\\';
  108. key += i;
  109. key += ';';
  110. std::string path;
  111. if (cmSystemTools::ReadRegistryValue(key, path,
  112. cmSystemTools::KeyWOW64_32) &&
  113. !path.empty()) {
  114. ret.insert(i);
  115. }
  116. }
  117. return ret;
  118. }
  119. bool cmGlobalVisualStudio11Generator::TargetSystemSupportsDeployment() const
  120. {
  121. return this->SystemIsWindowsPhone || this->SystemIsWindowsStore ||
  122. cmGlobalVisualStudio10Generator::TargetSystemSupportsDeployment();
  123. }
  124. bool cmGlobalVisualStudio11Generator::IsWindowsDesktopToolsetInstalled() const
  125. {
  126. char const desktop80Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  127. "VisualStudio\\11.0\\VC\\Libraries\\Extended";
  128. char const VS2012DesktopExpressKey[] =
  129. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  130. "WDExpress\\11.0;InstallDir";
  131. std::vector<std::string> subkeys;
  132. std::string path;
  133. return cmSystemTools::ReadRegistryValue(VS2012DesktopExpressKey, path,
  134. cmSystemTools::KeyWOW64_32) ||
  135. cmSystemTools::GetRegistrySubKeys(desktop80Key, subkeys,
  136. cmSystemTools::KeyWOW64_32);
  137. }
  138. bool cmGlobalVisualStudio11Generator::IsWindowsPhoneToolsetInstalled() const
  139. {
  140. char const wp80Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  141. "Microsoft SDKs\\WindowsPhone\\v8.0\\"
  142. "Install Path;Install Path";
  143. std::string path;
  144. cmSystemTools::ReadRegistryValue(wp80Key, path, cmSystemTools::KeyWOW64_32);
  145. return !path.empty();
  146. }
  147. bool cmGlobalVisualStudio11Generator::IsWindowsStoreToolsetInstalled() const
  148. {
  149. char const win80Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  150. "VisualStudio\\11.0\\VC\\Libraries\\Core\\Arm";
  151. std::vector<std::string> subkeys;
  152. return cmSystemTools::GetRegistrySubKeys(win80Key, subkeys,
  153. cmSystemTools::KeyWOW64_32);
  154. }