cmGlobalVisualStudio11Generator.cxx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 "cmAlgorithms.h"
  5. #include "cmDocumentationEntry.h"
  6. #include "cmLocalVisualStudio10Generator.h"
  7. #include "cmMakefile.h"
  8. static const char vs11generatorName[] = "Visual Studio 11 2012";
  9. // Map generator name without year to name with year.
  10. static const char* cmVS11GenName(const std::string& name, std::string& genName)
  11. {
  12. if (strncmp(name.c_str(), vs11generatorName,
  13. sizeof(vs11generatorName) - 6) != 0) {
  14. return 0;
  15. }
  16. const char* p = name.c_str() + sizeof(vs11generatorName) - 6;
  17. if (cmHasLiteralPrefix(p, " 2012")) {
  18. p += 5;
  19. }
  20. genName = std::string(vs11generatorName) + p;
  21. return p;
  22. }
  23. class cmGlobalVisualStudio11Generator::Factory
  24. : public cmGlobalGeneratorFactory
  25. {
  26. public:
  27. cmGlobalGenerator* CreateGlobalGenerator(const std::string& name,
  28. cmake* cm) const override
  29. {
  30. std::string genName;
  31. const char* p = cmVS11GenName(name, genName);
  32. if (!p) {
  33. return 0;
  34. }
  35. if (!*p) {
  36. return new cmGlobalVisualStudio11Generator(cm, genName, "");
  37. }
  38. if (*p++ != ' ') {
  39. return 0;
  40. }
  41. if (strcmp(p, "Win64") == 0) {
  42. return new cmGlobalVisualStudio11Generator(cm, genName, "x64");
  43. }
  44. if (strcmp(p, "ARM") == 0) {
  45. return new cmGlobalVisualStudio11Generator(cm, genName, "ARM");
  46. }
  47. std::set<std::string> installedSDKs =
  48. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
  49. if (installedSDKs.find(p) == installedSDKs.end()) {
  50. return 0;
  51. }
  52. cmGlobalVisualStudio11Generator* ret =
  53. new cmGlobalVisualStudio11Generator(cm, name, p);
  54. ret->WindowsCEVersion = "8.00";
  55. return ret;
  56. }
  57. void GetDocumentation(cmDocumentationEntry& entry) const override
  58. {
  59. entry.Name = std::string(vs11generatorName) + " [arch]";
  60. entry.Brief = "Generates Visual Studio 2012 project files. "
  61. "Optional [arch] can be \"Win64\" or \"ARM\".";
  62. }
  63. std::vector<std::string> GetGeneratorNames() const override
  64. {
  65. std::vector<std::string> names;
  66. names.push_back(vs11generatorName);
  67. return names;
  68. }
  69. std::vector<std::string> GetGeneratorNamesWithPlatform() const override
  70. {
  71. std::vector<std::string> names;
  72. names.push_back(vs11generatorName + std::string(" ARM"));
  73. names.push_back(vs11generatorName + std::string(" Win64"));
  74. std::set<std::string> installedSDKs =
  75. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
  76. for (std::string const& i : installedSDKs) {
  77. names.push_back(std::string(vs11generatorName) + " " + i);
  78. }
  79. return names;
  80. }
  81. bool SupportsToolset() const override { return true; }
  82. bool SupportsPlatform() const override { return true; }
  83. std::vector<std::string> GetKnownPlatforms() const override
  84. {
  85. std::vector<std::string> platforms;
  86. platforms.emplace_back("x64");
  87. platforms.emplace_back("Win32");
  88. platforms.emplace_back("ARM");
  89. std::set<std::string> installedSDKs =
  90. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
  91. for (std::string const& i : installedSDKs) {
  92. platforms.emplace_back(i);
  93. }
  94. return platforms;
  95. }
  96. std::string GetDefaultPlatformName() const override { return "Win32"; }
  97. };
  98. cmGlobalGeneratorFactory* cmGlobalVisualStudio11Generator::NewFactory()
  99. {
  100. return new Factory;
  101. }
  102. cmGlobalVisualStudio11Generator::cmGlobalVisualStudio11Generator(
  103. cmake* cm, const std::string& name,
  104. std::string const& platformInGeneratorName)
  105. : cmGlobalVisualStudio10Generator(cm, name, platformInGeneratorName)
  106. {
  107. std::string vc11Express;
  108. this->ExpressEdition = cmSystemTools::ReadRegistryValue(
  109. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\11.0\\Setup\\VC;"
  110. "ProductDir",
  111. vc11Express, cmSystemTools::KeyWOW64_32);
  112. this->DefaultPlatformToolset = "v110";
  113. this->DefaultCLFlagTableName = "v11";
  114. this->DefaultCSharpFlagTableName = "v11";
  115. this->DefaultLibFlagTableName = "v11";
  116. this->DefaultLinkFlagTableName = "v11";
  117. this->DefaultMasmFlagTableName = "v11";
  118. this->DefaultRCFlagTableName = "v11";
  119. this->Version = VS11;
  120. }
  121. bool cmGlobalVisualStudio11Generator::MatchesGeneratorName(
  122. const std::string& name) const
  123. {
  124. std::string genName;
  125. if (cmVS11GenName(name, genName)) {
  126. return genName == this->GetName();
  127. }
  128. return false;
  129. }
  130. bool cmGlobalVisualStudio11Generator::InitializeWindowsPhone(cmMakefile* mf)
  131. {
  132. if (!this->SelectWindowsPhoneToolset(this->DefaultPlatformToolset)) {
  133. std::ostringstream e;
  134. if (this->DefaultPlatformToolset.empty()) {
  135. e << this->GetName() << " supports Windows Phone '8.0', but not '"
  136. << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  137. } else {
  138. e << "A Windows Phone component with CMake requires both the Windows "
  139. << "Desktop SDK as well as the Windows Phone '" << this->SystemVersion
  140. << "' SDK. Please make sure that you have both installed";
  141. }
  142. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  143. return false;
  144. }
  145. return true;
  146. }
  147. bool cmGlobalVisualStudio11Generator::InitializeWindowsStore(cmMakefile* mf)
  148. {
  149. if (!this->SelectWindowsStoreToolset(this->DefaultPlatformToolset)) {
  150. std::ostringstream e;
  151. if (this->DefaultPlatformToolset.empty()) {
  152. e << this->GetName() << " supports Windows Store '8.0', but not '"
  153. << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  154. } else {
  155. e << "A Windows Store component with CMake requires both the Windows "
  156. << "Desktop SDK as well as the Windows Store '" << this->SystemVersion
  157. << "' SDK. Please make sure that you have both installed";
  158. }
  159. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  160. return false;
  161. }
  162. return true;
  163. }
  164. bool cmGlobalVisualStudio11Generator::SelectWindowsPhoneToolset(
  165. std::string& toolset) const
  166. {
  167. if (this->SystemVersion == "8.0") {
  168. if (this->IsWindowsPhoneToolsetInstalled() &&
  169. this->IsWindowsDesktopToolsetInstalled()) {
  170. toolset = "v110_wp80";
  171. return true;
  172. } else {
  173. return false;
  174. }
  175. }
  176. return this->cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset(
  177. toolset);
  178. }
  179. bool cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset(
  180. std::string& toolset) const
  181. {
  182. if (this->SystemVersion == "8.0") {
  183. if (this->IsWindowsStoreToolsetInstalled() &&
  184. this->IsWindowsDesktopToolsetInstalled()) {
  185. toolset = "v110";
  186. return true;
  187. } else {
  188. return false;
  189. }
  190. }
  191. return this->cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset(
  192. toolset);
  193. }
  194. bool cmGlobalVisualStudio11Generator::UseFolderProperty() const
  195. {
  196. // Intentionally skip up to the top-level class implementation.
  197. // Folders are not supported by the Express editions in VS10 and earlier,
  198. // but they are in VS11 Express and above.
  199. return cmGlobalGenerator::UseFolderProperty();
  200. }
  201. std::set<std::string>
  202. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs()
  203. {
  204. const char sdksKey[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  205. "Windows CE Tools\\SDKs";
  206. std::vector<std::string> subkeys;
  207. cmSystemTools::GetRegistrySubKeys(sdksKey, subkeys,
  208. cmSystemTools::KeyWOW64_32);
  209. std::set<std::string> ret;
  210. for (std::string const& i : subkeys) {
  211. std::string key = sdksKey;
  212. key += '\\';
  213. key += i;
  214. key += ';';
  215. std::string path;
  216. if (cmSystemTools::ReadRegistryValue(key, path,
  217. cmSystemTools::KeyWOW64_32) &&
  218. !path.empty()) {
  219. ret.insert(i);
  220. }
  221. }
  222. return ret;
  223. }
  224. bool cmGlobalVisualStudio11Generator::NeedsDeploy(
  225. cmStateEnums::TargetType type) const
  226. {
  227. if ((type == cmStateEnums::EXECUTABLE ||
  228. type == cmStateEnums::SHARED_LIBRARY) &&
  229. (this->SystemIsWindowsPhone || this->SystemIsWindowsStore)) {
  230. return true;
  231. }
  232. return cmGlobalVisualStudio10Generator::NeedsDeploy(type);
  233. }
  234. bool cmGlobalVisualStudio11Generator::IsWindowsDesktopToolsetInstalled() const
  235. {
  236. const char desktop80Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  237. "VisualStudio\\11.0\\VC\\Libraries\\Extended";
  238. const char VS2012DesktopExpressKey[] =
  239. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  240. "WDExpress\\11.0;InstallDir";
  241. std::vector<std::string> subkeys;
  242. std::string path;
  243. return cmSystemTools::ReadRegistryValue(VS2012DesktopExpressKey, path,
  244. cmSystemTools::KeyWOW64_32) ||
  245. cmSystemTools::GetRegistrySubKeys(desktop80Key, subkeys,
  246. cmSystemTools::KeyWOW64_32);
  247. }
  248. bool cmGlobalVisualStudio11Generator::IsWindowsPhoneToolsetInstalled() const
  249. {
  250. const char wp80Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  251. "Microsoft SDKs\\WindowsPhone\\v8.0\\"
  252. "Install Path;Install Path";
  253. std::string path;
  254. cmSystemTools::ReadRegistryValue(wp80Key, path, cmSystemTools::KeyWOW64_32);
  255. return !path.empty();
  256. }
  257. bool cmGlobalVisualStudio11Generator::IsWindowsStoreToolsetInstalled() const
  258. {
  259. const char win80Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  260. "VisualStudio\\11.0\\VC\\Libraries\\Core\\Arm";
  261. std::vector<std::string> subkeys;
  262. return cmSystemTools::GetRegistrySubKeys(win80Key, subkeys,
  263. cmSystemTools::KeyWOW64_32);
  264. }