cmGlobalVisualStudio11Generator.cxx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 "cmGlobalVisualStudio11Generator.h"
  11. #include "cmLocalVisualStudio10Generator.h"
  12. #include "cmMakefile.h"
  13. static const char vs11generatorName[] = "Visual Studio 11 2012";
  14. // Map generator name without year to name with year.
  15. static const char* cmVS11GenName(const std::string& name, std::string& genName)
  16. {
  17. if(strncmp(name.c_str(), vs11generatorName,
  18. sizeof(vs11generatorName)-6) != 0)
  19. {
  20. return 0;
  21. }
  22. const char* p = name.c_str() + sizeof(vs11generatorName) - 6;
  23. if(cmHasLiteralPrefix(p, " 2012"))
  24. {
  25. p += 5;
  26. }
  27. genName = std::string(vs11generatorName) + p;
  28. return p;
  29. }
  30. class cmGlobalVisualStudio11Generator::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 = cmVS11GenName(name, genName);
  39. if(!p)
  40. { return 0; }
  41. if(!*p)
  42. {
  43. return new cmGlobalVisualStudio11Generator(
  44. genName, "");
  45. }
  46. if(*p++ != ' ')
  47. { return 0; }
  48. if(strcmp(p, "Win64") == 0)
  49. {
  50. return new cmGlobalVisualStudio11Generator(
  51. genName, "x64");
  52. }
  53. if(strcmp(p, "ARM") == 0)
  54. {
  55. return new cmGlobalVisualStudio11Generator(
  56. genName, "ARM");
  57. }
  58. std::set<std::string> installedSDKs =
  59. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
  60. if(installedSDKs.find(p) == installedSDKs.end())
  61. {
  62. return 0;
  63. }
  64. cmGlobalVisualStudio11Generator* ret =
  65. new cmGlobalVisualStudio11Generator(name, p);
  66. ret->WindowsCEVersion = "8.00";
  67. return ret;
  68. }
  69. virtual void GetDocumentation(cmDocumentationEntry& entry) const
  70. {
  71. entry.Name = vs11generatorName;
  72. entry.Brief = "Generates Visual Studio 11 (VS 2012) project files.";
  73. }
  74. virtual void GetGenerators(std::vector<std::string>& names) const
  75. {
  76. names.push_back(vs11generatorName);
  77. names.push_back(vs11generatorName + std::string(" ARM"));
  78. names.push_back(vs11generatorName + std::string(" Win64"));
  79. std::set<std::string> installedSDKs =
  80. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
  81. for(std::set<std::string>::const_iterator i =
  82. installedSDKs.begin(); i != installedSDKs.end(); ++i)
  83. {
  84. names.push_back(std::string(vs11generatorName) + " " + *i);
  85. }
  86. }
  87. };
  88. //----------------------------------------------------------------------------
  89. cmGlobalGeneratorFactory* cmGlobalVisualStudio11Generator::NewFactory()
  90. {
  91. return new Factory;
  92. }
  93. //----------------------------------------------------------------------------
  94. cmGlobalVisualStudio11Generator::cmGlobalVisualStudio11Generator(
  95. const std::string& name, const std::string& platformName)
  96. : cmGlobalVisualStudio10Generator(name, platformName)
  97. {
  98. std::string vc11Express;
  99. this->ExpressEdition = cmSystemTools::ReadRegistryValue(
  100. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\11.0\\Setup\\VC;"
  101. "ProductDir", vc11Express, cmSystemTools::KeyWOW64_32);
  102. this->DefaultPlatformToolset = "v110";
  103. }
  104. //----------------------------------------------------------------------------
  105. bool
  106. cmGlobalVisualStudio11Generator::MatchesGeneratorName(
  107. const std::string& name) const
  108. {
  109. std::string genName;
  110. if(cmVS11GenName(name, genName))
  111. {
  112. return genName == this->GetName();
  113. }
  114. return false;
  115. }
  116. //----------------------------------------------------------------------------
  117. bool cmGlobalVisualStudio11Generator::InitializeWindowsPhone(cmMakefile* mf)
  118. {
  119. this->DefaultPlatformToolset = this->SelectWindowsPhoneToolset();
  120. if(this->DefaultPlatformToolset.empty())
  121. {
  122. cmOStringStream e;
  123. e << this->GetName() << " supports Windows Phone '8.0', but not '"
  124. << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  125. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  126. return false;
  127. }
  128. return true;
  129. }
  130. //----------------------------------------------------------------------------
  131. bool cmGlobalVisualStudio11Generator::InitializeWindowsStore(cmMakefile* mf)
  132. {
  133. this->DefaultPlatformToolset = this->SelectWindowsStoreToolset();
  134. if(this->DefaultPlatformToolset.empty())
  135. {
  136. cmOStringStream e;
  137. e << this->GetName() << " supports Windows Store '8.0', but not '"
  138. << this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
  139. mf->IssueMessage(cmake::FATAL_ERROR, e.str());
  140. return false;
  141. }
  142. return true;
  143. }
  144. //----------------------------------------------------------------------------
  145. std::string cmGlobalVisualStudio11Generator::SelectWindowsPhoneToolset() const
  146. {
  147. if(this->SystemVersion == "8.0")
  148. {
  149. return "v110_wp80";
  150. }
  151. return this->cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset();
  152. }
  153. //----------------------------------------------------------------------------
  154. std::string cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset() const
  155. {
  156. if(this->SystemVersion == "8.0")
  157. {
  158. return "v110";
  159. }
  160. return this->cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset();
  161. }
  162. //----------------------------------------------------------------------------
  163. void cmGlobalVisualStudio11Generator::WriteSLNHeader(std::ostream& fout)
  164. {
  165. fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
  166. if (this->ExpressEdition)
  167. {
  168. fout << "# Visual Studio Express 2012 for Windows Desktop\n";
  169. }
  170. else
  171. {
  172. fout << "# Visual Studio 2012\n";
  173. }
  174. }
  175. //----------------------------------------------------------------------------
  176. cmLocalGenerator *cmGlobalVisualStudio11Generator::CreateLocalGenerator()
  177. {
  178. cmLocalVisualStudio10Generator* lg =
  179. new cmLocalVisualStudio10Generator(cmLocalVisualStudioGenerator::VS11);
  180. lg->SetGlobalGenerator(this);
  181. return lg;
  182. }
  183. //----------------------------------------------------------------------------
  184. bool cmGlobalVisualStudio11Generator::UseFolderProperty()
  185. {
  186. // Intentionally skip over the parent class implementation and call the
  187. // grand-parent class's implementation. Folders are not supported by the
  188. // Express editions in VS10 and earlier, but they are in VS11 Express.
  189. return cmGlobalVisualStudio8Generator::UseFolderProperty();
  190. }
  191. //----------------------------------------------------------------------------
  192. std::set<std::string>
  193. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs()
  194. {
  195. const char sdksKey[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  196. "Windows CE Tools\\SDKs";
  197. std::vector<std::string> subkeys;
  198. cmSystemTools::GetRegistrySubKeys(sdksKey, subkeys,
  199. cmSystemTools::KeyWOW64_32);
  200. std::set<std::string> ret;
  201. for(std::vector<std::string>::const_iterator i =
  202. subkeys.begin(); i != subkeys.end(); ++i)
  203. {
  204. std::string key = sdksKey;
  205. key += '\\';
  206. key += *i;
  207. key += ';';
  208. std::string path;
  209. if(cmSystemTools::ReadRegistryValue(key.c_str(),
  210. path,
  211. cmSystemTools::KeyWOW64_32) &&
  212. !path.empty())
  213. {
  214. ret.insert(*i);
  215. }
  216. }
  217. return ret;
  218. }