cmGlobalVisualStudio12Generator.cxx 8.2 KB

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