cmGlobalVisualStudio12Generator.cxx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmGlobalVisualStudio12Generator.h"
  4. #include "cmAlgorithms.h"
  5. #include "cmDocumentationEntry.h"
  6. #include "cmLocalVisualStudio10Generator.h"
  7. #include "cmMakefile.h"
  8. static const char vs12generatorName[] = "Visual Studio 12 2013";
  9. // Map generator name without year to name with year.
  10. static const char* cmVS12GenName(const std::string& name, std::string& genName)
  11. {
  12. if (strncmp(name.c_str(), vs12generatorName,
  13. sizeof(vs12generatorName) - 6) != 0) {
  14. return 0;
  15. }
  16. const char* p = name.c_str() + sizeof(vs12generatorName) - 6;
  17. if (cmHasLiteralPrefix(p, " 2013")) {
  18. p += 5;
  19. }
  20. genName = std::string(vs12generatorName) + p;
  21. return p;
  22. }
  23. class cmGlobalVisualStudio12Generator::Factory
  24. : public cmGlobalGeneratorFactory
  25. {
  26. public:
  27. cmGlobalGenerator* CreateGlobalGenerator(const std::string& name,
  28. cmake* cm) const override
  29. {
  30. std::string genName;
  31. const char* p = cmVS12GenName(name, genName);
  32. if (!p) {
  33. return 0;
  34. }
  35. if (!*p) {
  36. return new cmGlobalVisualStudio12Generator(cm, genName, "");
  37. }
  38. if (*p++ != ' ') {
  39. return 0;
  40. }
  41. if (strcmp(p, "Win64") == 0) {
  42. return new cmGlobalVisualStudio12Generator(cm, genName, "x64");
  43. }
  44. if (strcmp(p, "ARM") == 0) {
  45. return new cmGlobalVisualStudio12Generator(cm, genName, "ARM");
  46. }
  47. return 0;
  48. }
  49. void GetDocumentation(cmDocumentationEntry& entry) const override
  50. {
  51. entry.Name = std::string(vs12generatorName) + " [arch]";
  52. entry.Brief = "Generates Visual Studio 2013 project files. "
  53. "Optional [arch] can be \"Win64\" or \"ARM\".";
  54. }
  55. void GetGenerators(std::vector<std::string>& names) const override
  56. {
  57. names.push_back(vs12generatorName);
  58. names.push_back(vs12generatorName + std::string(" ARM"));
  59. names.push_back(vs12generatorName + std::string(" Win64"));
  60. }
  61. bool SupportsToolset() const override { return true; }
  62. bool SupportsPlatform() const override { return true; }
  63. };
  64. cmGlobalGeneratorFactory* cmGlobalVisualStudio12Generator::NewFactory()
  65. {
  66. return new Factory;
  67. }
  68. cmGlobalVisualStudio12Generator::cmGlobalVisualStudio12Generator(
  69. cmake* cm, const std::string& name, const std::string& platformName)
  70. : cmGlobalVisualStudio11Generator(cm, name, platformName)
  71. {
  72. std::string vc12Express;
  73. this->ExpressEdition = cmSystemTools::ReadRegistryValue(
  74. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\12.0\\Setup\\VC;"
  75. "ProductDir",
  76. vc12Express, cmSystemTools::KeyWOW64_32);
  77. this->DefaultPlatformToolset = "v120";
  78. this->DefaultCLFlagTableName = "v12";
  79. this->DefaultCSharpFlagTableName = "v12";
  80. this->DefaultLibFlagTableName = "v12";
  81. this->DefaultLinkFlagTableName = "v12";
  82. this->DefaultMasmFlagTableName = "v12";
  83. this->DefaultRCFlagTableName = "v12";
  84. this->Version = VS12;
  85. }
  86. bool cmGlobalVisualStudio12Generator::MatchesGeneratorName(
  87. const std::string& name) const
  88. {
  89. std::string genName;
  90. if (cmVS12GenName(name, genName)) {
  91. return genName == this->GetName();
  92. }
  93. return false;
  94. }
  95. bool cmGlobalVisualStudio12Generator::ProcessGeneratorToolsetField(
  96. std::string const& key, std::string const& value)
  97. {
  98. if (key == "host" && value == "x64") {
  99. this->GeneratorToolsetHostArchitecture = "x64";
  100. return true;
  101. }
  102. return this->cmGlobalVisualStudio11Generator::ProcessGeneratorToolsetField(
  103. key, value);
  104. }
  105. bool cmGlobalVisualStudio12Generator::InitializeWindowsPhone(cmMakefile* mf)
  106. {
  107. if (!this->SelectWindowsPhoneToolset(this->DefaultPlatformToolset)) {
  108. std::ostringstream e;
  109. if (this->DefaultPlatformToolset.empty()) {
  110. e << this->GetName()
  111. << " supports Windows Phone '8.0' and '8.1', but "
  112. "not '"
  113. << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  114. } else {
  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. bool cmGlobalVisualStudio12Generator::InitializeWindowsStore(cmMakefile* mf)
  125. {
  126. if (!this->SelectWindowsStoreToolset(this->DefaultPlatformToolset)) {
  127. std::ostringstream e;
  128. if (this->DefaultPlatformToolset.empty()) {
  129. e << this->GetName()
  130. << " supports Windows Store '8.0' and '8.1', but "
  131. "not '"
  132. << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  133. } else {
  134. e << "A Windows Store component with CMake requires both the Windows "
  135. << "Desktop SDK as well as the Windows Store '" << this->SystemVersion
  136. << "' SDK. Please make sure that you have both installed";
  137. }
  138. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  139. return false;
  140. }
  141. return true;
  142. }
  143. bool cmGlobalVisualStudio12Generator::SelectWindowsPhoneToolset(
  144. std::string& toolset) const
  145. {
  146. if (this->SystemVersion == "8.1") {
  147. if (this->IsWindowsPhoneToolsetInstalled() &&
  148. this->IsWindowsDesktopToolsetInstalled()) {
  149. toolset = "v120_wp81";
  150. return true;
  151. } else {
  152. return false;
  153. }
  154. }
  155. return this->cmGlobalVisualStudio11Generator::SelectWindowsPhoneToolset(
  156. toolset);
  157. }
  158. bool cmGlobalVisualStudio12Generator::SelectWindowsStoreToolset(
  159. std::string& toolset) const
  160. {
  161. if (this->SystemVersion == "8.1") {
  162. if (this->IsWindowsStoreToolsetInstalled() &&
  163. this->IsWindowsDesktopToolsetInstalled()) {
  164. toolset = "v120";
  165. return true;
  166. } else {
  167. return false;
  168. }
  169. }
  170. return this->cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset(
  171. toolset);
  172. }
  173. void cmGlobalVisualStudio12Generator::WriteSLNHeader(std::ostream& fout)
  174. {
  175. fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
  176. if (this->ExpressEdition) {
  177. fout << "# Visual Studio Express 2013 for Windows Desktop\n";
  178. } else {
  179. fout << "# Visual Studio 2013\n";
  180. }
  181. }
  182. bool cmGlobalVisualStudio12Generator::IsWindowsDesktopToolsetInstalled() const
  183. {
  184. const char desktop81Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  185. "VisualStudio\\12.0\\VC\\LibraryDesktop";
  186. std::vector<std::string> subkeys;
  187. return cmSystemTools::GetRegistrySubKeys(desktop81Key, subkeys,
  188. cmSystemTools::KeyWOW64_32);
  189. }
  190. bool cmGlobalVisualStudio12Generator::IsWindowsPhoneToolsetInstalled() const
  191. {
  192. const char wp81Key[] =
  193. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  194. "Microsoft SDKs\\WindowsPhone\\v8.1\\Install Path;Install Path";
  195. std::string path;
  196. cmSystemTools::ReadRegistryValue(wp81Key, path, cmSystemTools::KeyWOW64_32);
  197. return !path.empty();
  198. }
  199. bool cmGlobalVisualStudio12Generator::IsWindowsStoreToolsetInstalled() const
  200. {
  201. const char win81Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  202. "VisualStudio\\12.0\\VC\\Libraries\\Core\\Arm";
  203. std::vector<std::string> subkeys;
  204. return cmSystemTools::GetRegistrySubKeys(win81Key, subkeys,
  205. cmSystemTools::KeyWOW64_32);
  206. }