cmGlobalVisualStudioGenerator.h 6.3 KB

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