cmGlobalVisualStudioGenerator.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. VS8 = 80,
  31. VS9 = 90,
  32. VS10 = 100,
  33. VS11 = 110,
  34. VS12 = 120,
  35. /* VS13 = 130 was skipped */
  36. VS14 = 140,
  37. VS15 = 150
  38. };
  39. cmGlobalVisualStudioGenerator(cmake* cm);
  40. virtual ~cmGlobalVisualStudioGenerator();
  41. VSVersion GetVersion() const;
  42. void SetVersion(VSVersion v);
  43. /**
  44. * Configure CMake's Visual Studio macros file into the user's Visual
  45. * Studio macros directory.
  46. */
  47. virtual void ConfigureCMakeVisualStudioMacros();
  48. /**
  49. * Where does this version of Visual Studio look for macros for the
  50. * current user? Returns the empty string if this version of Visual
  51. * Studio does not implement support for VB macros.
  52. */
  53. virtual std::string GetUserMacrosDirectory();
  54. /**
  55. * What is the reg key path to "vsmacros" for this version of Visual
  56. * Studio?
  57. */
  58. virtual std::string GetUserMacrosRegKeyBase();
  59. enum MacroName
  60. {
  61. MacroReload,
  62. MacroStop
  63. };
  64. /**
  65. * Call the ReloadProjects macro if necessary based on
  66. * GetFilesReplacedDuringGenerate results.
  67. */
  68. void CallVisualStudioMacro(MacroName m, const char* vsSolutionFile = 0);
  69. // return true if target is fortran only
  70. bool TargetIsFortranOnly(const cmGeneratorTarget* gt);
  71. // return true if target is C# only
  72. static bool TargetIsCSharpOnly(cmGeneratorTarget const* gt);
  73. // return true if target can be referenced by C# targets
  74. bool TargetCanBeReferenced(cmGeneratorTarget const* gt);
  75. /** Get the top-level registry key for this VS version. */
  76. std::string GetRegistryBase();
  77. /** Get the top-level registry key for the given VS version. */
  78. static std::string GetRegistryBase(const char* version);
  79. /** Return true if the generated build tree may contain multiple builds.
  80. i.e. "Can I build Debug and Release in the same tree?" */
  81. bool IsMultiConfig() const override { return true; }
  82. /** Return true if building for Windows CE */
  83. virtual bool TargetsWindowsCE() const { return false; }
  84. bool IsIncludeExternalMSProjectSupported() const override { return true; }
  85. class TargetSet : public std::set<cmGeneratorTarget const*>
  86. {
  87. };
  88. class TargetCompare
  89. {
  90. std::string First;
  91. public:
  92. TargetCompare(std::string const& first)
  93. : First(first)
  94. {
  95. }
  96. bool operator()(cmGeneratorTarget const* l,
  97. cmGeneratorTarget const* r) const;
  98. };
  99. class OrderedTargetDependSet;
  100. bool FindMakeProgram(cmMakefile*) override;
  101. std::string ExpandCFGIntDir(const std::string& str,
  102. const std::string& config) const override;
  103. void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
  104. std::string GetStartupProjectName(cmLocalGenerator const* root) const;
  105. void AddSymbolExportCommand(cmGeneratorTarget*,
  106. std::vector<cmCustomCommand>& commands,
  107. std::string const& configName);
  108. bool Open(const std::string& bindir, const std::string& projectName,
  109. bool dryRun) override;
  110. protected:
  111. void AddExtraIDETargets() override;
  112. // Does this VS version link targets to each other if there are
  113. // dependencies in the SLN file? This was done for VS versions
  114. // below 8.
  115. virtual bool VSLinksDependencies() const { return true; }
  116. virtual const char* GetIDEVersion() = 0;
  117. bool ComputeTargetDepends() override;
  118. class VSDependSet : public std::set<std::string>
  119. {
  120. };
  121. class VSDependMap : public std::map<cmGeneratorTarget const*, VSDependSet>
  122. {
  123. };
  124. VSDependMap VSTargetDepends;
  125. void ComputeVSTargetDepends(cmGeneratorTarget*);
  126. bool CheckTargetLinks(cmGeneratorTarget& target, const std::string& name);
  127. std::string GetUtilityForTarget(cmGeneratorTarget& target,
  128. const std::string&);
  129. virtual std::string WriteUtilityDepend(cmGeneratorTarget const*) = 0;
  130. std::string GetUtilityDepend(const cmGeneratorTarget* target);
  131. typedef std::map<cmGeneratorTarget const*, std::string> UtilityDependsMap;
  132. UtilityDependsMap UtilityDepends;
  133. protected:
  134. VSVersion Version;
  135. private:
  136. virtual std::string GetVSMakeProgram() = 0;
  137. void PrintCompilerAdvice(std::ostream&, std::string const&,
  138. const char*) const
  139. {
  140. }
  141. void FollowLinkDepends(cmGeneratorTarget const* target,
  142. std::set<cmGeneratorTarget const*>& linked);
  143. class TargetSetMap : public std::map<cmGeneratorTarget*, TargetSet>
  144. {
  145. };
  146. TargetSetMap TargetLinkClosure;
  147. void FillLinkClosure(const cmGeneratorTarget* target, TargetSet& linked);
  148. TargetSet const& GetTargetLinkClosure(cmGeneratorTarget* target);
  149. };
  150. class cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  151. : public std::multiset<cmTargetDepend,
  152. cmGlobalVisualStudioGenerator::TargetCompare>
  153. {
  154. typedef std::multiset<cmTargetDepend,
  155. cmGlobalVisualStudioGenerator::TargetCompare>
  156. derived;
  157. public:
  158. typedef cmGlobalGenerator::TargetDependSet TargetDependSet;
  159. typedef cmGlobalVisualStudioGenerator::TargetSet TargetSet;
  160. OrderedTargetDependSet(TargetDependSet const&, std::string const& first);
  161. OrderedTargetDependSet(TargetSet const&, std::string const& first);
  162. };
  163. #endif