cmGlobalVisualStudio12Generator.cxx 7.9 KB

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