cmGlobalVisualStudioGenerator.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. virtual bool IsMultiConfig() const { return true; }
  82. /** Return true if building for Windows CE */
  83. virtual bool TargetsWindowsCE() const { return false; }
  84. class TargetSet : public std::set<cmGeneratorTarget const*>
  85. {
  86. };
  87. class TargetCompare
  88. {
  89. std::string First;
  90. public:
  91. TargetCompare(std::string const& first)
  92. : First(first)
  93. {
  94. }
  95. bool operator()(cmGeneratorTarget const* l,
  96. cmGeneratorTarget const* r) const;
  97. };
  98. class OrderedTargetDependSet;
  99. bool FindMakeProgram(cmMakefile*) CM_OVERRIDE;
  100. virtual std::string ExpandCFGIntDir(const std::string& str,
  101. const std::string& config) const;
  102. void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
  103. std::string GetStartupProjectName(cmLocalGenerator const* root) const;
  104. void AddSymbolExportCommand(cmGeneratorTarget*,
  105. std::vector<cmCustomCommand>& commands,
  106. std::string const& configName);
  107. protected:
  108. virtual void AddExtraIDETargets();
  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. virtual const char* GetIDEVersion() = 0;
  114. virtual bool ComputeTargetDepends();
  115. class VSDependSet : public std::set<std::string>
  116. {
  117. };
  118. class VSDependMap : public std::map<cmGeneratorTarget const*, VSDependSet>
  119. {
  120. };
  121. VSDependMap VSTargetDepends;
  122. void ComputeVSTargetDepends(cmGeneratorTarget*);
  123. bool CheckTargetLinks(cmGeneratorTarget& target, const std::string& name);
  124. std::string GetUtilityForTarget(cmGeneratorTarget& target,
  125. const std::string&);
  126. virtual std::string WriteUtilityDepend(cmGeneratorTarget const*) = 0;
  127. std::string GetUtilityDepend(const cmGeneratorTarget* target);
  128. typedef std::map<cmGeneratorTarget const*, std::string> UtilityDependsMap;
  129. UtilityDependsMap UtilityDepends;
  130. protected:
  131. VSVersion Version;
  132. private:
  133. virtual std::string GetVSMakeProgram() = 0;
  134. void PrintCompilerAdvice(std::ostream&, std::string const&,
  135. const char*) const
  136. {
  137. }
  138. void FollowLinkDepends(cmGeneratorTarget const* target,
  139. std::set<cmGeneratorTarget const*>& linked);
  140. class TargetSetMap : public std::map<cmGeneratorTarget*, TargetSet>
  141. {
  142. };
  143. TargetSetMap TargetLinkClosure;
  144. void FillLinkClosure(const cmGeneratorTarget* target, TargetSet& linked);
  145. TargetSet const& GetTargetLinkClosure(cmGeneratorTarget* target);
  146. };
  147. class cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  148. : public std::multiset<cmTargetDepend,
  149. cmGlobalVisualStudioGenerator::TargetCompare>
  150. {
  151. typedef std::multiset<cmTargetDepend,
  152. cmGlobalVisualStudioGenerator::TargetCompare>
  153. derived;
  154. public:
  155. typedef cmGlobalGenerator::TargetDependSet TargetDependSet;
  156. typedef cmGlobalVisualStudioGenerator::TargetSet TargetSet;
  157. OrderedTargetDependSet(TargetDependSet const&, std::string const& first);
  158. OrderedTargetDependSet(TargetSet const&, std::string const& first);
  159. };
  160. #endif