cmGlobalVisualStudio12Generator.cxx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. this->DefaultPlatformToolset = this->SelectWindowsPhoneToolset();
  104. if(this->DefaultPlatformToolset.empty())
  105. {
  106. cmOStringStream e;
  107. e << this->GetName() << " supports Windows Phone '8.0' and '8.1', "
  108. "but not '" << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  109. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  110. return false;
  111. }
  112. return true;
  113. }
  114. //----------------------------------------------------------------------------
  115. bool cmGlobalVisualStudio12Generator::InitializeWindowsStore(cmMakefile* mf)
  116. {
  117. this->DefaultPlatformToolset = this->SelectWindowsStoreToolset();
  118. if(this->DefaultPlatformToolset.empty())
  119. {
  120. cmOStringStream e;
  121. e << this->GetName() << " supports Windows Store '8.0' and '8.1', "
  122. "but not '" << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  123. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  124. return false;
  125. }
  126. return true;
  127. }
  128. //----------------------------------------------------------------------------
  129. std::string cmGlobalVisualStudio12Generator::SelectWindowsPhoneToolset() const
  130. {
  131. if(this->SystemVersion == "8.1")
  132. {
  133. return "v120_wp81";
  134. }
  135. return this->cmGlobalVisualStudio11Generator::SelectWindowsPhoneToolset();
  136. }
  137. //----------------------------------------------------------------------------
  138. std::string cmGlobalVisualStudio12Generator::SelectWindowsStoreToolset() const
  139. {
  140. if(this->SystemVersion == "8.1")
  141. {
  142. return "v120";
  143. }
  144. return this->cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset();
  145. }
  146. //----------------------------------------------------------------------------
  147. void cmGlobalVisualStudio12Generator::WriteSLNHeader(std::ostream& fout)
  148. {
  149. fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
  150. if (this->ExpressEdition)
  151. {
  152. fout << "# Visual Studio Express 2013 for Windows Desktop\n";
  153. }
  154. else
  155. {
  156. fout << "# Visual Studio 2013\n";
  157. }
  158. }
  159. //----------------------------------------------------------------------------
  160. cmLocalGenerator *cmGlobalVisualStudio12Generator::CreateLocalGenerator()
  161. {
  162. cmLocalVisualStudio10Generator* lg =
  163. new cmLocalVisualStudio10Generator(cmLocalVisualStudioGenerator::VS12);
  164. lg->SetGlobalGenerator(this);
  165. return lg;
  166. }