cmGlobalVisualStudio11Generator.cxx 5.9 KB

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