cmGlobalVisualStudio14Generator.cxx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2014 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 "cmGlobalVisualStudio14Generator.h"
  11. #include "cmLocalVisualStudio10Generator.h"
  12. #include "cmMakefile.h"
  13. #include "cmAlgorithms.h"
  14. static const char vs14generatorName[] = "Visual Studio 14 2015";
  15. // Map generator name without year to name with year.
  16. static const char* cmVS14GenName(const std::string& name, std::string& genName)
  17. {
  18. if(strncmp(name.c_str(), vs14generatorName,
  19. sizeof(vs14generatorName)-6) != 0)
  20. {
  21. return 0;
  22. }
  23. const char* p = name.c_str() + sizeof(vs14generatorName) - 6;
  24. if(cmHasLiteralPrefix(p, " 2015"))
  25. {
  26. p += 5;
  27. }
  28. genName = std::string(vs14generatorName) + p;
  29. return p;
  30. }
  31. class cmGlobalVisualStudio14Generator::Factory
  32. : public cmGlobalGeneratorFactory
  33. {
  34. public:
  35. virtual cmGlobalGenerator* CreateGlobalGenerator(
  36. const std::string& name) const
  37. {
  38. std::string genName;
  39. const char* p = cmVS14GenName(name, genName);
  40. if(!p)
  41. { return 0; }
  42. if(!*p)
  43. {
  44. return new cmGlobalVisualStudio14Generator(
  45. genName, "");
  46. }
  47. if(*p++ != ' ')
  48. { return 0; }
  49. if(strcmp(p, "Win64") == 0)
  50. {
  51. return new cmGlobalVisualStudio14Generator(
  52. genName, "x64");
  53. }
  54. if(strcmp(p, "ARM") == 0)
  55. {
  56. return new cmGlobalVisualStudio14Generator(
  57. genName, "ARM");
  58. }
  59. return 0;
  60. }
  61. virtual void GetDocumentation(cmDocumentationEntry& entry) const
  62. {
  63. entry.Name = std::string(vs14generatorName) + " [arch]";
  64. entry.Brief =
  65. "Generates Visual Studio 2015 project files. "
  66. "Optional [arch] can be \"Win64\" or \"ARM\"."
  67. ;
  68. }
  69. virtual void GetGenerators(std::vector<std::string>& names) const
  70. {
  71. names.push_back(vs14generatorName);
  72. names.push_back(vs14generatorName + std::string(" ARM"));
  73. names.push_back(vs14generatorName + std::string(" Win64"));
  74. }
  75. };
  76. //----------------------------------------------------------------------------
  77. cmGlobalGeneratorFactory* cmGlobalVisualStudio14Generator::NewFactory()
  78. {
  79. return new Factory;
  80. }
  81. //----------------------------------------------------------------------------
  82. cmGlobalVisualStudio14Generator::cmGlobalVisualStudio14Generator(
  83. const std::string& name, const std::string& platformName)
  84. : cmGlobalVisualStudio12Generator(name, platformName)
  85. {
  86. std::string vc14Express;
  87. this->ExpressEdition = cmSystemTools::ReadRegistryValue(
  88. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\14.0\\Setup\\VC;"
  89. "ProductDir", vc14Express, cmSystemTools::KeyWOW64_32);
  90. this->DefaultPlatformToolset = "v140";
  91. }
  92. //----------------------------------------------------------------------------
  93. bool
  94. cmGlobalVisualStudio14Generator::MatchesGeneratorName(
  95. const std::string& name) const
  96. {
  97. std::string genName;
  98. if(cmVS14GenName(name, genName))
  99. {
  100. return genName == this->GetName();
  101. }
  102. return false;
  103. }
  104. //----------------------------------------------------------------------------
  105. void cmGlobalVisualStudio14Generator::WriteSLNHeader(std::ostream& fout)
  106. {
  107. // Visual Studio 14 writes .sln format 12.00
  108. fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
  109. if (this->ExpressEdition)
  110. {
  111. fout << "# Visual Studio Express 14 for Windows Desktop\n";
  112. }
  113. else
  114. {
  115. fout << "# Visual Studio 14\n";
  116. }
  117. }
  118. //----------------------------------------------------------------------------
  119. cmLocalGenerator *
  120. cmGlobalVisualStudio14Generator::CreateLocalGenerator(cmLocalGenerator* parent)
  121. {
  122. cmLocalVisualStudio10Generator* lg =
  123. new cmLocalVisualStudio10Generator(cmLocalVisualStudioGenerator::VS14,
  124. parent);
  125. lg->SetGlobalGenerator(this);
  126. return lg;
  127. }