cmGlobalVisualStudio12Generator.cxx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. std::vector<std::string> GetGeneratorNames() const override
  56. {
  57. std::vector<std::string> names;
  58. names.push_back(vs12generatorName);
  59. return names;
  60. }
  61. std::vector<std::string> GetGeneratorNamesWithPlatform() const override
  62. {
  63. std::vector<std::string> names;
  64. names.push_back(vs12generatorName + std::string(" ARM"));
  65. names.push_back(vs12generatorName + std::string(" Win64"));
  66. return names;
  67. }
  68. bool SupportsToolset() const override { return true; }
  69. bool SupportsPlatform() const override { return true; }
  70. std::vector<std::string> GetKnownPlatforms() const override
  71. {
  72. std::vector<std::string> platforms;
  73. platforms.emplace_back("x64");
  74. platforms.emplace_back("Win32");
  75. platforms.emplace_back("ARM");
  76. return platforms;
  77. }
  78. std::string GetDefaultPlatformName() const override { return "Win32"; }
  79. };
  80. cmGlobalGeneratorFactory* cmGlobalVisualStudio12Generator::NewFactory()
  81. {
  82. return new Factory;
  83. }
  84. cmGlobalVisualStudio12Generator::cmGlobalVisualStudio12Generator(
  85. cmake* cm, const std::string& name,
  86. std::string const& platformInGeneratorName)
  87. : cmGlobalVisualStudio11Generator(cm, name, platformInGeneratorName)
  88. {
  89. std::string vc12Express;
  90. this->ExpressEdition = cmSystemTools::ReadRegistryValue(
  91. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\12.0\\Setup\\VC;"
  92. "ProductDir",
  93. vc12Express, cmSystemTools::KeyWOW64_32);
  94. this->DefaultPlatformToolset = "v120";
  95. this->DefaultCLFlagTableName = "v12";
  96. this->DefaultCSharpFlagTableName = "v12";
  97. this->DefaultLibFlagTableName = "v12";
  98. this->DefaultLinkFlagTableName = "v12";
  99. this->DefaultMasmFlagTableName = "v12";
  100. this->DefaultRCFlagTableName = "v12";
  101. this->Version = VS12;
  102. }
  103. bool cmGlobalVisualStudio12Generator::MatchesGeneratorName(
  104. const std::string& name) const
  105. {
  106. std::string genName;
  107. if (cmVS12GenName(name, genName)) {
  108. return genName == this->GetName();
  109. }
  110. return false;
  111. }
  112. bool cmGlobalVisualStudio12Generator::ProcessGeneratorToolsetField(
  113. std::string const& key, std::string const& value)
  114. {
  115. if (key == "host" && value == "x64") {
  116. this->GeneratorToolsetHostArchitecture = "x64";
  117. return true;
  118. }
  119. return this->cmGlobalVisualStudio11Generator::ProcessGeneratorToolsetField(
  120. key, value);
  121. }
  122. bool cmGlobalVisualStudio12Generator::InitializeWindowsPhone(cmMakefile* mf)
  123. {
  124. if (!this->SelectWindowsPhoneToolset(this->DefaultPlatformToolset)) {
  125. std::ostringstream e;
  126. if (this->DefaultPlatformToolset.empty()) {
  127. e << this->GetName()
  128. << " supports Windows Phone '8.0' and '8.1', but "
  129. "not '"
  130. << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  131. } else {
  132. e << "A Windows Phone component with CMake requires both the Windows "
  133. << "Desktop SDK as well as the Windows Phone '" << this->SystemVersion
  134. << "' SDK. Please make sure that you have both installed";
  135. }
  136. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  137. return false;
  138. }
  139. return true;
  140. }
  141. bool cmGlobalVisualStudio12Generator::InitializeWindowsStore(cmMakefile* mf)
  142. {
  143. if (!this->SelectWindowsStoreToolset(this->DefaultPlatformToolset)) {
  144. std::ostringstream e;
  145. if (this->DefaultPlatformToolset.empty()) {
  146. e << this->GetName()
  147. << " supports Windows Store '8.0' and '8.1', but "
  148. "not '"
  149. << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  150. } else {
  151. e << "A Windows Store component with CMake requires both the Windows "
  152. << "Desktop SDK as well as the Windows Store '" << this->SystemVersion
  153. << "' SDK. Please make sure that you have both installed";
  154. }
  155. mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
  156. return false;
  157. }
  158. return true;
  159. }
  160. bool cmGlobalVisualStudio12Generator::SelectWindowsPhoneToolset(
  161. std::string& toolset) const
  162. {
  163. if (this->SystemVersion == "8.1") {
  164. if (this->IsWindowsPhoneToolsetInstalled() &&
  165. this->IsWindowsDesktopToolsetInstalled()) {
  166. toolset = "v120_wp81";
  167. return true;
  168. } else {
  169. return false;
  170. }
  171. }
  172. return this->cmGlobalVisualStudio11Generator::SelectWindowsPhoneToolset(
  173. toolset);
  174. }
  175. bool cmGlobalVisualStudio12Generator::SelectWindowsStoreToolset(
  176. std::string& toolset) const
  177. {
  178. if (this->SystemVersion == "8.1") {
  179. if (this->IsWindowsStoreToolsetInstalled() &&
  180. this->IsWindowsDesktopToolsetInstalled()) {
  181. toolset = "v120";
  182. return true;
  183. } else {
  184. return false;
  185. }
  186. }
  187. return this->cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset(
  188. toolset);
  189. }
  190. bool cmGlobalVisualStudio12Generator::IsWindowsDesktopToolsetInstalled() const
  191. {
  192. const char desktop81Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  193. "VisualStudio\\12.0\\VC\\LibraryDesktop";
  194. std::vector<std::string> subkeys;
  195. return cmSystemTools::GetRegistrySubKeys(desktop81Key, subkeys,
  196. cmSystemTools::KeyWOW64_32);
  197. }
  198. bool cmGlobalVisualStudio12Generator::IsWindowsPhoneToolsetInstalled() const
  199. {
  200. const char wp81Key[] =
  201. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  202. "Microsoft SDKs\\WindowsPhone\\v8.1\\Install Path;Install Path";
  203. std::string path;
  204. cmSystemTools::ReadRegistryValue(wp81Key, path, cmSystemTools::KeyWOW64_32);
  205. return !path.empty();
  206. }
  207. bool cmGlobalVisualStudio12Generator::IsWindowsStoreToolsetInstalled() const
  208. {
  209. const char win81Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  210. "VisualStudio\\12.0\\VC\\Libraries\\Core\\Arm";
  211. std::vector<std::string> subkeys;
  212. return cmSystemTools::GetRegistrySubKeys(win81Key, subkeys,
  213. cmSystemTools::KeyWOW64_32);
  214. }