cmGlobalVisualStudio12Generator.cxx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 "cmGlobalVisualStudio12Generator.h"
  11. #include "cmLocalVisualStudio10Generator.h"
  12. #include "cmMakefile.h"
  13. static const char vs12generatorName[] = "Visual Studio 12 2013";
  14. // Map generator name without year to name with year.
  15. static const char* cmVS12GenName(const std::string& name, std::string& genName)
  16. {
  17. if(strncmp(name.c_str(), vs12generatorName,
  18. sizeof(vs12generatorName)-6) != 0)
  19. {
  20. return 0;
  21. }
  22. const char* p = name.c_str() + sizeof(vs12generatorName) - 6;
  23. if(cmHasLiteralPrefix(p, " 2013"))
  24. {
  25. p += 5;
  26. }
  27. genName = std::string(vs12generatorName) + p;
  28. return p;
  29. }
  30. class cmGlobalVisualStudio12Generator::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 = cmVS12GenName(name, genName);
  39. if(!p)
  40. { return 0; }
  41. if(!*p)
  42. {
  43. return new cmGlobalVisualStudio12Generator(
  44. genName, "");
  45. }
  46. if(*p++ != ' ')
  47. { return 0; }
  48. if(strcmp(p, "Win64") == 0)
  49. {
  50. return new cmGlobalVisualStudio12Generator(
  51. genName, "x64");
  52. }
  53. if(strcmp(p, "ARM") == 0)
  54. {
  55. return new cmGlobalVisualStudio12Generator(
  56. genName, "ARM");
  57. }
  58. return 0;
  59. }
  60. virtual void GetDocumentation(cmDocumentationEntry& entry) const
  61. {
  62. entry.Name = vs12generatorName;
  63. entry.Brief = "Generates Visual Studio 12 (VS 2013) project files.";
  64. }
  65. virtual void GetGenerators(std::vector<std::string>& names) const
  66. {
  67. names.push_back(vs12generatorName);
  68. names.push_back(vs12generatorName + std::string(" ARM"));
  69. names.push_back(vs12generatorName + std::string(" Win64"));
  70. }
  71. };
  72. //----------------------------------------------------------------------------
  73. cmGlobalGeneratorFactory* cmGlobalVisualStudio12Generator::NewFactory()
  74. {
  75. return new Factory;
  76. }
  77. //----------------------------------------------------------------------------
  78. cmGlobalVisualStudio12Generator::cmGlobalVisualStudio12Generator(
  79. const std::string& name, const std::string& platformName)
  80. : cmGlobalVisualStudio11Generator(name, platformName)
  81. {
  82. std::string vc12Express;
  83. this->ExpressEdition = cmSystemTools::ReadRegistryValue(
  84. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\12.0\\Setup\\VC;"
  85. "ProductDir", vc12Express, cmSystemTools::KeyWOW64_32);
  86. this->DefaultPlatformToolset = "v120";
  87. }
  88. //----------------------------------------------------------------------------
  89. bool
  90. cmGlobalVisualStudio12Generator::MatchesGeneratorName(
  91. const std::string& name) const
  92. {
  93. std::string genName;
  94. if(cmVS12GenName(name, genName))
  95. {
  96. return genName == this->GetName();
  97. }
  98. return false;
  99. }
  100. //----------------------------------------------------------------------------
  101. bool cmGlobalVisualStudio12Generator::InitializeWindowsPhone(cmMakefile* mf)
  102. {
  103. if(!this->SelectWindowsPhoneToolset(this->DefaultPlatformToolset))
  104. {
  105. std::ostringstream e;
  106. if(this->DefaultPlatformToolset.empty())
  107. {
  108. e << this->GetName() << " supports Windows Phone '8.0' and '8.1', but "
  109. "not '" << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  110. }
  111. else
  112. {
  113. e << "A Windows Phone component with CMake requires both the Windows "
  114. << "Desktop SDK as well as the Windows Phone '" << this->SystemVersion
  115. << "' SDK. Please make sure that you have both installed";
  116. }
  117. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  118. return false;
  119. }
  120. return true;
  121. }
  122. //----------------------------------------------------------------------------
  123. bool cmGlobalVisualStudio12Generator::InitializeWindowsStore(cmMakefile* mf)
  124. {
  125. if(!this->SelectWindowsStoreToolset(this->DefaultPlatformToolset))
  126. {
  127. std::ostringstream e;
  128. if(this->DefaultPlatformToolset.empty())
  129. {
  130. e << this->GetName() << " supports Windows Store '8.0' and '8.1', but "
  131. "not '" << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  132. }
  133. else
  134. {
  135. e << "A Windows Store component with CMake requires both the Windows "
  136. << "Desktop SDK as well as the Windows Store '" << this->SystemVersion
  137. << "' SDK. Please make sure that you have both installed";
  138. }
  139. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  140. return false;
  141. }
  142. return true;
  143. }
  144. //----------------------------------------------------------------------------
  145. bool
  146. cmGlobalVisualStudio12Generator::SelectWindowsPhoneToolset(
  147. std::string& toolset) const
  148. {
  149. if(this->SystemVersion == "8.1")
  150. {
  151. if (this->IsWindowsPhoneToolsetInstalled() &&
  152. this->IsWindowsDesktopToolsetInstalled())
  153. {
  154. toolset = "v120_wp81";
  155. return true;
  156. }
  157. else
  158. {
  159. return false;
  160. }
  161. }
  162. return
  163. this->cmGlobalVisualStudio11Generator::SelectWindowsPhoneToolset(toolset);
  164. }
  165. //----------------------------------------------------------------------------
  166. bool
  167. cmGlobalVisualStudio12Generator::SelectWindowsStoreToolset(
  168. std::string& toolset) const
  169. {
  170. if(this->SystemVersion == "8.1")
  171. {
  172. if(this->IsWindowsStoreToolsetInstalled() &&
  173. this->IsWindowsDesktopToolsetInstalled())
  174. {
  175. toolset = "v120";
  176. return true;
  177. }
  178. else
  179. {
  180. return false;
  181. }
  182. }
  183. return
  184. this->cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset(toolset);
  185. }
  186. //----------------------------------------------------------------------------
  187. void cmGlobalVisualStudio12Generator::WriteSLNHeader(std::ostream& fout)
  188. {
  189. fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
  190. if (this->ExpressEdition)
  191. {
  192. fout << "# Visual Studio Express 2013 for Windows Desktop\n";
  193. }
  194. else
  195. {
  196. fout << "# Visual Studio 2013\n";
  197. }
  198. }
  199. //----------------------------------------------------------------------------
  200. cmLocalGenerator *cmGlobalVisualStudio12Generator::CreateLocalGenerator()
  201. {
  202. cmLocalVisualStudio10Generator* lg =
  203. new cmLocalVisualStudio10Generator(cmLocalVisualStudioGenerator::VS12);
  204. lg->SetGlobalGenerator(this);
  205. return lg;
  206. }
  207. //----------------------------------------------------------------------------
  208. bool
  209. cmGlobalVisualStudio12Generator::IsWindowsDesktopToolsetInstalled() const
  210. {
  211. const char desktop81Key[] =
  212. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  213. "VisualStudio\\12.0\\VC\\LibraryDesktop";
  214. std::vector<std::string> subkeys;
  215. return cmSystemTools::GetRegistrySubKeys(desktop81Key,
  216. subkeys,
  217. cmSystemTools::KeyWOW64_32);
  218. }
  219. //----------------------------------------------------------------------------
  220. bool
  221. cmGlobalVisualStudio12Generator::IsWindowsPhoneToolsetInstalled() const
  222. {
  223. const char wp81Key[] =
  224. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  225. "Microsoft SDKs\\WindowsPhone\\v8.1\\Install Path;Install Path";
  226. std::string path;
  227. cmSystemTools::ReadRegistryValue(wp81Key,
  228. path,
  229. cmSystemTools::KeyWOW64_32);
  230. return !path.empty();
  231. }
  232. //----------------------------------------------------------------------------
  233. bool
  234. cmGlobalVisualStudio12Generator::IsWindowsStoreToolsetInstalled() const
  235. {
  236. const char win81Key[] =
  237. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  238. "VisualStudio\\12.0\\VC\\Libraries\\Core\\Arm";
  239. std::vector<std::string> subkeys;
  240. return cmSystemTools::GetRegistrySubKeys(win81Key,
  241. subkeys,
  242. cmSystemTools::KeyWOW64_32);
  243. }