cmGlobalVisualStudio11Generator.cxx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. void cmGlobalVisualStudio11Generator::WriteSLNHeader(std::ostream& fout)
  118. {
  119. fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
  120. if (this->ExpressEdition)
  121. {
  122. fout << "# Visual Studio Express 2012 for Windows Desktop\n";
  123. }
  124. else
  125. {
  126. fout << "# Visual Studio 2012\n";
  127. }
  128. }
  129. //----------------------------------------------------------------------------
  130. cmLocalGenerator *cmGlobalVisualStudio11Generator::CreateLocalGenerator()
  131. {
  132. cmLocalVisualStudio10Generator* lg =
  133. new cmLocalVisualStudio10Generator(cmLocalVisualStudioGenerator::VS11);
  134. lg->SetGlobalGenerator(this);
  135. return lg;
  136. }
  137. //----------------------------------------------------------------------------
  138. bool cmGlobalVisualStudio11Generator::UseFolderProperty()
  139. {
  140. // Intentionally skip over the parent class implementation and call the
  141. // grand-parent class's implementation. Folders are not supported by the
  142. // Express editions in VS10 and earlier, but they are in VS11 Express.
  143. return cmGlobalVisualStudio8Generator::UseFolderProperty();
  144. }
  145. //----------------------------------------------------------------------------
  146. std::set<std::string>
  147. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs()
  148. {
  149. const char sdksKey[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  150. "Windows CE Tools\\SDKs";
  151. std::vector<std::string> subkeys;
  152. cmSystemTools::GetRegistrySubKeys(sdksKey, subkeys,
  153. cmSystemTools::KeyWOW64_32);
  154. std::set<std::string> ret;
  155. for(std::vector<std::string>::const_iterator i =
  156. subkeys.begin(); i != subkeys.end(); ++i)
  157. {
  158. std::string key = sdksKey;
  159. key += '\\';
  160. key += *i;
  161. key += ';';
  162. std::string path;
  163. if(cmSystemTools::ReadRegistryValue(key.c_str(),
  164. path,
  165. cmSystemTools::KeyWOW64_32) &&
  166. !path.empty())
  167. {
  168. ret.insert(*i);
  169. }
  170. }
  171. return ret;
  172. }