cmGlobalVisualStudio11Generator.cxx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2011 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmGlobalVisualStudio11Generator.h"
  11. #include "cmLocalVisualStudio10Generator.h"
  12. #include "cmMakefile.h"
  13. static const char vs11generatorName[] = "Visual Studio 11 2012";
  14. // Map generator name without year to name with year.
  15. static const char* cmVS11GenName(const std::string& name, std::string& genName)
  16. {
  17. if(strncmp(name.c_str(), vs11generatorName,
  18. sizeof(vs11generatorName)-6) != 0)
  19. {
  20. return 0;
  21. }
  22. const char* p = name.c_str() + sizeof(vs11generatorName) - 6;
  23. if(cmHasLiteralPrefix(p, " 2012"))
  24. {
  25. p += 5;
  26. }
  27. genName = std::string(vs11generatorName) + p;
  28. return p;
  29. }
  30. class cmGlobalVisualStudio11Generator::Factory
  31. : public cmGlobalGeneratorFactory
  32. {
  33. public:
  34. virtual cmGlobalGenerator* CreateGlobalGenerator(
  35. const std::string& name) const
  36. {
  37. std::string genName;
  38. const char* p = cmVS11GenName(name, genName);
  39. if(!p)
  40. { return 0; }
  41. if(!*p)
  42. {
  43. return new cmGlobalVisualStudio11Generator(
  44. genName, "");
  45. }
  46. if(*p++ != ' ')
  47. { return 0; }
  48. if(strcmp(p, "Win64") == 0)
  49. {
  50. return new cmGlobalVisualStudio11Generator(
  51. genName, "x64");
  52. }
  53. if(strcmp(p, "ARM") == 0)
  54. {
  55. return new cmGlobalVisualStudio11Generator(
  56. genName, "ARM");
  57. }
  58. std::set<std::string> installedSDKs =
  59. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
  60. if(installedSDKs.find(p) == installedSDKs.end())
  61. {
  62. return 0;
  63. }
  64. cmGlobalVisualStudio11Generator* ret =
  65. new cmGlobalVisualStudio11Generator(name, p);
  66. ret->WindowsCEVersion = "8.00";
  67. return ret;
  68. }
  69. virtual void GetDocumentation(cmDocumentationEntry& entry) const
  70. {
  71. entry.Name = vs11generatorName;
  72. entry.Brief = "Generates Visual Studio 11 (VS 2012) project files.";
  73. }
  74. virtual void GetGenerators(std::vector<std::string>& names) const
  75. {
  76. names.push_back(vs11generatorName);
  77. names.push_back(vs11generatorName + std::string(" ARM"));
  78. names.push_back(vs11generatorName + std::string(" Win64"));
  79. std::set<std::string> installedSDKs =
  80. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
  81. for(std::set<std::string>::const_iterator i =
  82. installedSDKs.begin(); i != installedSDKs.end(); ++i)
  83. {
  84. names.push_back(std::string(vs11generatorName) + " " + *i);
  85. }
  86. }
  87. };
  88. //----------------------------------------------------------------------------
  89. cmGlobalGeneratorFactory* cmGlobalVisualStudio11Generator::NewFactory()
  90. {
  91. return new Factory;
  92. }
  93. //----------------------------------------------------------------------------
  94. cmGlobalVisualStudio11Generator::cmGlobalVisualStudio11Generator(
  95. const std::string& name, const std::string& platformName)
  96. : cmGlobalVisualStudio10Generator(name, platformName)
  97. {
  98. std::string vc11Express;
  99. this->ExpressEdition = cmSystemTools::ReadRegistryValue(
  100. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\11.0\\Setup\\VC;"
  101. "ProductDir", vc11Express, cmSystemTools::KeyWOW64_32);
  102. this->DefaultPlatformToolset = "v110";
  103. }
  104. //----------------------------------------------------------------------------
  105. bool
  106. cmGlobalVisualStudio11Generator::MatchesGeneratorName(
  107. const std::string& name) const
  108. {
  109. std::string genName;
  110. if(cmVS11GenName(name, genName))
  111. {
  112. return genName == this->GetName();
  113. }
  114. return false;
  115. }
  116. //----------------------------------------------------------------------------
  117. bool cmGlobalVisualStudio11Generator::InitializeWindowsPhone(cmMakefile* mf)
  118. {
  119. if(!this->SelectWindowsPhoneToolset(this->DefaultPlatformToolset))
  120. {
  121. cmOStringStream e;
  122. if(this->DefaultPlatformToolset.empty())
  123. {
  124. e << this->GetName() << " supports Windows Phone '8.0', but not '"
  125. << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  126. }
  127. else
  128. {
  129. e << "A Windows Phone component with CMake requires both the Windows "
  130. << "Desktop SDK as well as the Windows Phone '" << this->SystemVersion
  131. << "' SDK. Please make sure that you have both installed";
  132. }
  133. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  134. return false;
  135. }
  136. return true;
  137. }
  138. //----------------------------------------------------------------------------
  139. bool cmGlobalVisualStudio11Generator::InitializeWindowsStore(cmMakefile* mf)
  140. {
  141. if(!this->SelectWindowsStoreToolset(this->DefaultPlatformToolset))
  142. {
  143. cmOStringStream e;
  144. if(this->DefaultPlatformToolset.empty())
  145. {
  146. e << this->GetName() << " supports Windows Store '8.0', but not '"
  147. << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  148. }
  149. else
  150. {
  151. e << "A Windows Store component with CMake requires both the Windows "
  152. << "Desktop SDK as well as the Windows Store '" << this->SystemVersion
  153. << "' SDK. Please make sure that you have both installed";
  154. }
  155. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  156. return false;
  157. }
  158. return true;
  159. }
  160. //----------------------------------------------------------------------------
  161. bool
  162. cmGlobalVisualStudio11Generator::SelectWindowsPhoneToolset(
  163. std::string& toolset) const
  164. {
  165. if(this->SystemVersion == "8.0")
  166. {
  167. if (this->IsWindowsPhoneToolsetInstalled() &&
  168. this->IsWindowsDesktopToolsetInstalled())
  169. {
  170. toolset = "v110_wp80";
  171. return true;
  172. }
  173. else
  174. {
  175. return false;
  176. }
  177. }
  178. return
  179. this->cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset(toolset);
  180. }
  181. //----------------------------------------------------------------------------
  182. bool
  183. cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset(
  184. std::string& toolset) const
  185. {
  186. if(this->SystemVersion == "8.0")
  187. {
  188. if(this->IsWindowsStoreToolsetInstalled() &&
  189. this->IsWindowsDesktopToolsetInstalled())
  190. {
  191. toolset = "v110";
  192. return true;
  193. }
  194. else
  195. {
  196. return false;
  197. }
  198. }
  199. return
  200. this->cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset(toolset);
  201. }
  202. //----------------------------------------------------------------------------
  203. void cmGlobalVisualStudio11Generator::WriteSLNHeader(std::ostream& fout)
  204. {
  205. fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
  206. if (this->ExpressEdition)
  207. {
  208. fout << "# Visual Studio Express 2012 for Windows Desktop\n";
  209. }
  210. else
  211. {
  212. fout << "# Visual Studio 2012\n";
  213. }
  214. }
  215. //----------------------------------------------------------------------------
  216. cmLocalGenerator *cmGlobalVisualStudio11Generator::CreateLocalGenerator()
  217. {
  218. cmLocalVisualStudio10Generator* lg =
  219. new cmLocalVisualStudio10Generator(cmLocalVisualStudioGenerator::VS11);
  220. lg->SetGlobalGenerator(this);
  221. return lg;
  222. }
  223. //----------------------------------------------------------------------------
  224. bool cmGlobalVisualStudio11Generator::UseFolderProperty()
  225. {
  226. // Intentionally skip over the parent class implementation and call the
  227. // grand-parent class's implementation. Folders are not supported by the
  228. // Express editions in VS10 and earlier, but they are in VS11 Express.
  229. return cmGlobalVisualStudio8Generator::UseFolderProperty();
  230. }
  231. //----------------------------------------------------------------------------
  232. std::set<std::string>
  233. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs()
  234. {
  235. const char sdksKey[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  236. "Windows CE Tools\\SDKs";
  237. std::vector<std::string> subkeys;
  238. cmSystemTools::GetRegistrySubKeys(sdksKey, subkeys,
  239. cmSystemTools::KeyWOW64_32);
  240. std::set<std::string> ret;
  241. for(std::vector<std::string>::const_iterator i =
  242. subkeys.begin(); i != subkeys.end(); ++i)
  243. {
  244. std::string key = sdksKey;
  245. key += '\\';
  246. key += *i;
  247. key += ';';
  248. std::string path;
  249. if(cmSystemTools::ReadRegistryValue(key.c_str(),
  250. path,
  251. cmSystemTools::KeyWOW64_32) &&
  252. !path.empty())
  253. {
  254. ret.insert(*i);
  255. }
  256. }
  257. return ret;
  258. }
  259. //----------------------------------------------------------------------------
  260. bool
  261. cmGlobalVisualStudio11Generator::NeedsDeploy(cmTarget::TargetType type) const
  262. {
  263. if((type == cmTarget::EXECUTABLE ||
  264. type == cmTarget::SHARED_LIBRARY) &&
  265. (this->SystemIsWindowsPhone ||
  266. this->SystemIsWindowsStore))
  267. {
  268. return true;
  269. }
  270. return cmGlobalVisualStudio10Generator::NeedsDeploy(type);
  271. }
  272. //----------------------------------------------------------------------------
  273. bool
  274. cmGlobalVisualStudio11Generator::IsWindowsDesktopToolsetInstalled() const
  275. {
  276. const char desktop80Key[] =
  277. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  278. "VisualStudio\\11.0\\VC\\Libraries\\Extended";
  279. const char VS2012DesktopExpressKey[] =
  280. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  281. "WDExpress\\11.0;InstallDir";
  282. std::vector<std::string> subkeys;
  283. std::string path;
  284. return cmSystemTools::ReadRegistryValue(VS2012DesktopExpressKey,
  285. path,
  286. cmSystemTools::KeyWOW64_32) ||
  287. cmSystemTools::GetRegistrySubKeys(desktop80Key,
  288. subkeys,
  289. cmSystemTools::KeyWOW64_32);
  290. }
  291. //----------------------------------------------------------------------------
  292. bool
  293. cmGlobalVisualStudio11Generator::IsWindowsPhoneToolsetInstalled() const
  294. {
  295. const char wp80Key[] =
  296. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  297. "Microsoft SDKs\\WindowsPhone\\v8.0\\"
  298. "Install Path;Install Path";
  299. std::string path;
  300. cmSystemTools::ReadRegistryValue(wp80Key,
  301. path,
  302. cmSystemTools::KeyWOW64_32);
  303. return !path.empty();
  304. }
  305. //----------------------------------------------------------------------------
  306. bool
  307. cmGlobalVisualStudio11Generator::IsWindowsStoreToolsetInstalled() const
  308. {
  309. const char win80Key[] =
  310. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  311. "VisualStudio\\11.0\\VC\\Libraries\\Core\\Arm";
  312. std::vector<std::string> subkeys;
  313. return cmSystemTools::GetRegistrySubKeys(win80Key,
  314. subkeys,
  315. cmSystemTools::KeyWOW64_32);
  316. }