cmGlobalVisualStudio11Generator.cxx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 char* name, std::string& genName)
  16. {
  17. if(strncmp(name, vs11generatorName, sizeof(vs11generatorName)-6) != 0)
  18. {
  19. return 0;
  20. }
  21. const char* p = name + sizeof(vs11generatorName) - 6;
  22. if(strncmp(p, " 2012", 5) == 0)
  23. {
  24. p += 5;
  25. }
  26. genName = std::string(vs11generatorName) + p;
  27. return p;
  28. }
  29. class cmGlobalVisualStudio11Generator::Factory
  30. : public cmGlobalGeneratorFactory
  31. {
  32. public:
  33. virtual cmGlobalGenerator* CreateGlobalGenerator(const char* name) const
  34. {
  35. std::string genName;
  36. const char* p = cmVS11GenName(name, genName);
  37. if(!p)
  38. { return 0; }
  39. name = genName.c_str();
  40. if(strcmp(p, "") == 0)
  41. {
  42. return new cmGlobalVisualStudio11Generator(
  43. name, NULL, NULL);
  44. }
  45. if(strcmp(p, " Win64") == 0)
  46. {
  47. return new cmGlobalVisualStudio11Generator(
  48. name, "x64", "CMAKE_FORCE_WIN64");
  49. }
  50. if(strcmp(p, " ARM") == 0)
  51. {
  52. return new cmGlobalVisualStudio11Generator(
  53. name, "ARM", NULL);
  54. }
  55. if(*p++ != ' ')
  56. {
  57. return 0;
  58. }
  59. std::set<std::string> installedSDKs =
  60. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
  61. if(installedSDKs.find(p) == installedSDKs.end())
  62. {
  63. return 0;
  64. }
  65. cmGlobalVisualStudio11Generator* ret =
  66. new cmGlobalVisualStudio11Generator(name, p, NULL);
  67. ret->WindowsCEVersion = "8.00";
  68. return ret;
  69. }
  70. virtual void GetDocumentation(cmDocumentationEntry& entry) const
  71. {
  72. entry.Name = vs11generatorName;
  73. entry.Brief = "Generates Visual Studio 11 (VS 2012) project files.";
  74. }
  75. virtual void GetGenerators(std::vector<std::string>& names) const
  76. {
  77. names.push_back(vs11generatorName);
  78. names.push_back(vs11generatorName + std::string(" ARM"));
  79. names.push_back(vs11generatorName + std::string(" Win64"));
  80. std::set<std::string> installedSDKs =
  81. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
  82. for(std::set<std::string>::const_iterator i =
  83. installedSDKs.begin(); i != installedSDKs.end(); ++i)
  84. {
  85. names.push_back(std::string(vs11generatorName) + " " + *i);
  86. }
  87. }
  88. };
  89. //----------------------------------------------------------------------------
  90. cmGlobalGeneratorFactory* cmGlobalVisualStudio11Generator::NewFactory()
  91. {
  92. return new Factory;
  93. }
  94. //----------------------------------------------------------------------------
  95. cmGlobalVisualStudio11Generator::cmGlobalVisualStudio11Generator(
  96. const char* name, const char* platformName,
  97. const char* additionalPlatformDefinition)
  98. : cmGlobalVisualStudio10Generator(name, platformName,
  99. additionalPlatformDefinition)
  100. {
  101. this->FindMakeProgramFile = "CMakeVS11FindMake.cmake";
  102. std::string vc11Express;
  103. this->ExpressEdition = cmSystemTools::ReadRegistryValue(
  104. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\11.0\\Setup\\VC;"
  105. "ProductDir", vc11Express, cmSystemTools::KeyWOW64_32);
  106. this->PlatformToolset = "v110";
  107. }
  108. //----------------------------------------------------------------------------
  109. bool
  110. cmGlobalVisualStudio11Generator::MatchesGeneratorName(const char* name) const
  111. {
  112. std::string genName;
  113. if(cmVS11GenName(name, genName))
  114. {
  115. return genName == this->GetName();
  116. }
  117. return false;
  118. }
  119. //----------------------------------------------------------------------------
  120. void cmGlobalVisualStudio11Generator::WriteSLNHeader(std::ostream& fout)
  121. {
  122. fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
  123. if (this->ExpressEdition)
  124. {
  125. fout << "# Visual Studio Express 2012 for Windows Desktop\n";
  126. }
  127. else
  128. {
  129. fout << "# Visual Studio 2012\n";
  130. }
  131. }
  132. //----------------------------------------------------------------------------
  133. cmLocalGenerator *cmGlobalVisualStudio11Generator::CreateLocalGenerator()
  134. {
  135. cmLocalVisualStudio10Generator* lg =
  136. new cmLocalVisualStudio10Generator(cmLocalVisualStudioGenerator::VS11);
  137. lg->SetPlatformName(this->GetPlatformName());
  138. lg->SetGlobalGenerator(this);
  139. return lg;
  140. }
  141. //----------------------------------------------------------------------------
  142. bool cmGlobalVisualStudio11Generator::UseFolderProperty()
  143. {
  144. // Intentionally skip over the parent class implementation and call the
  145. // grand-parent class's implementation. Folders are not supported by the
  146. // Express editions in VS10 and earlier, but they are in VS11 Express.
  147. return cmGlobalVisualStudio8Generator::UseFolderProperty();
  148. }
  149. //----------------------------------------------------------------------------
  150. std::set<std::string>
  151. cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs()
  152. {
  153. const char sdksKey[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
  154. "Windows CE Tools\\SDKs";
  155. std::vector<std::string> subkeys;
  156. cmSystemTools::GetRegistrySubKeys(sdksKey, subkeys,
  157. cmSystemTools::KeyWOW64_32);
  158. std::set<std::string> ret;
  159. for(std::vector<std::string>::const_iterator i =
  160. subkeys.begin(); i != subkeys.end(); ++i)
  161. {
  162. std::string key = sdksKey;
  163. key += '\\';
  164. key += *i;
  165. key += ';';
  166. std::string path;
  167. if(cmSystemTools::ReadRegistryValue(key.c_str(),
  168. path,
  169. cmSystemTools::KeyWOW64_32) &&
  170. !path.empty())
  171. {
  172. ret.insert(*i);
  173. }
  174. }
  175. return ret;
  176. }