cmGlobalVisualStudio12Generator.cxx 7.3 KB

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