cmGlobalVisualStudioGenerator.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmGlobalVisualStudioGenerator_h
  4. #define cmGlobalVisualStudioGenerator_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <iosfwd>
  7. #include <map>
  8. #include <set>
  9. #include <string>
  10. #include <vector>
  11. #include "cmGlobalGenerator.h"
  12. #include "cmTargetDepend.h"
  13. class cmCustomCommand;
  14. class cmGeneratorTarget;
  15. class cmLocalGenerator;
  16. class cmMakefile;
  17. class cmake;
  18. /** \class cmGlobalVisualStudioGenerator
  19. * \brief Base class for global Visual Studio generators.
  20. *
  21. * cmGlobalVisualStudioGenerator provides functionality common to all
  22. * global Visual Studio generators.
  23. */
  24. class cmGlobalVisualStudioGenerator : public cmGlobalGenerator
  25. {
  26. public:
  27. /** Known versions of Visual Studio. */
  28. enum VSVersion
  29. {
  30. VS9 = 90,
  31. VS10 = 100,
  32. VS11 = 110,
  33. VS12 = 120,
  34. /* VS13 = 130 was skipped */
  35. VS14 = 140,
  36. VS15 = 150
  37. };
  38. cmGlobalVisualStudioGenerator(cmake* cm);
  39. virtual ~cmGlobalVisualStudioGenerator();
  40. VSVersion GetVersion() const;
  41. void SetVersion(VSVersion v);
  42. /** Is the installed VS an Express edition? */
  43. bool IsExpressEdition() const { return this->ExpressEdition; }
  44. /**
  45. * Configure CMake's Visual Studio macros file into the user's Visual
  46. * Studio macros directory.
  47. */
  48. virtual void ConfigureCMakeVisualStudioMacros();
  49. /**
  50. * Where does this version of Visual Studio look for macros for the
  51. * current user? Returns the empty string if this version of Visual
  52. * Studio does not implement support for VB macros.
  53. */
  54. virtual std::string GetUserMacrosDirectory();
  55. /**
  56. * What is the reg key path to "vsmacros" for this version of Visual
  57. * Studio?
  58. */
  59. virtual std::string GetUserMacrosRegKeyBase();
  60. enum MacroName
  61. {
  62. MacroReload,
  63. MacroStop
  64. };
  65. /**
  66. * Call the ReloadProjects macro if necessary based on
  67. * GetFilesReplacedDuringGenerate results.
  68. */
  69. void CallVisualStudioMacro(MacroName m, const char* vsSolutionFile = 0);
  70. // return true if target is fortran only
  71. bool TargetIsFortranOnly(const cmGeneratorTarget* gt);
  72. /** Get the top-level registry key for this VS version. */
  73. std::string GetRegistryBase();
  74. /** Get the top-level registry key for the given VS version. */
  75. static std::string GetRegistryBase(const char* version);
  76. /** Return true if the generated build tree may contain multiple builds.
  77. i.e. "Can I build Debug and Release in the same tree?" */
  78. bool IsMultiConfig() const override { return true; }
  79. /** Return true if building for Windows CE */
  80. virtual bool TargetsWindowsCE() const { return false; }
  81. bool IsIncludeExternalMSProjectSupported() const override { return true; }
  82. class TargetSet : public std::set<cmGeneratorTarget const*>
  83. {
  84. };
  85. class TargetCompare
  86. {
  87. std::string First;
  88. public:
  89. TargetCompare(std::string const& first)
  90. : First(first)
  91. {
  92. }
  93. bool operator()(cmGeneratorTarget const* l,
  94. cmGeneratorTarget const* r) const;
  95. };
  96. class OrderedTargetDependSet;
  97. bool FindMakeProgram(cmMakefile*) override;
  98. std::string ExpandCFGIntDir(const std::string& str,
  99. const std::string& config) const override;
  100. void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
  101. std::string GetStartupProjectName(cmLocalGenerator const* root) const;
  102. void AddSymbolExportCommand(cmGeneratorTarget*,
  103. std::vector<cmCustomCommand>& commands,
  104. std::string const& configName);
  105. bool Open(const std::string& bindir, const std::string& projectName,
  106. bool dryRun) override;
  107. protected:
  108. void AddExtraIDETargets() override;
  109. // Does this VS version link targets to each other if there are
  110. // dependencies in the SLN file? This was done for VS versions
  111. // below 8.
  112. virtual bool VSLinksDependencies() const { return true; }
  113. const char* GetIDEVersion() const;
  114. void WriteSLNHeader(std::ostream& fout);
  115. bool ComputeTargetDepends() override;
  116. class VSDependSet : public std::set<std::string>
  117. {
  118. };
  119. class VSDependMap : public std::map<cmGeneratorTarget const*, VSDependSet>
  120. {
  121. };
  122. VSDependMap VSTargetDepends;
  123. void ComputeVSTargetDepends(cmGeneratorTarget*);
  124. bool CheckTargetLinks(cmGeneratorTarget& target, const std::string& name);
  125. std::string GetUtilityForTarget(cmGeneratorTarget& target,
  126. const std::string&);
  127. virtual std::string WriteUtilityDepend(cmGeneratorTarget const*) = 0;
  128. std::string GetUtilityDepend(const cmGeneratorTarget* target);
  129. typedef std::map<cmGeneratorTarget const*, std::string> UtilityDependsMap;
  130. UtilityDependsMap UtilityDepends;
  131. protected:
  132. VSVersion Version;
  133. bool ExpressEdition;
  134. private:
  135. virtual std::string GetVSMakeProgram() = 0;
  136. void PrintCompilerAdvice(std::ostream&, std::string const&,
  137. const char*) const override
  138. {
  139. }
  140. void FollowLinkDepends(cmGeneratorTarget const* target,
  141. std::set<cmGeneratorTarget const*>& linked);
  142. class TargetSetMap : public std::map<cmGeneratorTarget*, TargetSet>
  143. {
  144. };
  145. TargetSetMap TargetLinkClosure;
  146. void FillLinkClosure(const cmGeneratorTarget* target, TargetSet& linked);
  147. TargetSet const& GetTargetLinkClosure(cmGeneratorTarget* target);
  148. };
  149. class cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  150. : public std::multiset<cmTargetDepend,
  151. cmGlobalVisualStudioGenerator::TargetCompare>
  152. {
  153. typedef std::multiset<cmTargetDepend,
  154. cmGlobalVisualStudioGenerator::TargetCompare>
  155. derived;
  156. public:
  157. typedef cmGlobalGenerator::TargetDependSet TargetDependSet;
  158. typedef cmGlobalVisualStudioGenerator::TargetSet TargetSet;
  159. OrderedTargetDependSet(TargetDependSet const&, std::string const& first);
  160. OrderedTargetDependSet(TargetSet const&, std::string const& first);
  161. };
  162. #endif