cmGlobalVisualStudioGenerator.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <iosfwd>
  6. #include <map>
  7. #include <set>
  8. #include <string>
  9. #include <vector>
  10. #include "cm_codecvt_Encoding.hxx"
  11. #include "cmGlobalGenerator.h"
  12. #include "cmTargetDepend.h"
  13. #include "cmVSSolution.h"
  14. #include "cmVSVersion.h"
  15. #include "cmValue.h"
  16. class cmCustomCommand;
  17. class cmGeneratorTarget;
  18. class cmLocalGenerator;
  19. class cmMakefile;
  20. class cmake;
  21. /** \class cmGlobalVisualStudioGenerator
  22. * \brief Base class for global Visual Studio generators.
  23. *
  24. * cmGlobalVisualStudioGenerator provides functionality common to all
  25. * global Visual Studio generators.
  26. */
  27. class cmGlobalVisualStudioGenerator : public cmGlobalGenerator
  28. {
  29. public:
  30. using VSVersion = cm::VS::Version;
  31. ~cmGlobalVisualStudioGenerator() override;
  32. VSVersion GetVersion() const;
  33. void SetVersion(VSVersion v);
  34. /** Is the installed VS an Express edition? */
  35. bool IsExpressEdition() const { return this->ExpressEdition; }
  36. void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
  37. bool optional) override;
  38. bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override;
  39. /**
  40. * Get the name of the target platform (architecture) for which we generate.
  41. * The names are as defined by VS, e.g. "Win32", "x64", "Itanium", "ARM".
  42. */
  43. std::string const& GetPlatformName() const;
  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. cmValue GetDebuggerWorkingDirectory(cmGeneratorTarget* gt) const override;
  61. enum MacroName
  62. {
  63. MacroReload,
  64. MacroStop
  65. };
  66. /**
  67. * Call the ReloadProjects macro if necessary based on
  68. * GetFilesReplacedDuringGenerate results.
  69. */
  70. void CallVisualStudioMacro(MacroName m, std::string const& vsSolutionFile);
  71. // return true if target is fortran only
  72. bool TargetIsFortranOnly(cmGeneratorTarget const* gt) const;
  73. // return true if target should be included in solution.
  74. virtual bool IsInSolution(cmGeneratorTarget const* gt) const;
  75. // return true if project dependency should be included in solution.
  76. virtual bool IsDepInSolution(std::string const& targetName) const;
  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(char const* 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. /** Get encoding used by generator for generated source files
  88. */
  89. codecvt_Encoding GetMakefileEncoding() const override
  90. {
  91. return codecvt_Encoding::ANSI;
  92. }
  93. class TargetSet : public std::set<cmGeneratorTarget const*>
  94. {
  95. };
  96. class TargetCompare
  97. {
  98. std::string First;
  99. public:
  100. TargetCompare(std::string first)
  101. : First(std::move(first))
  102. {
  103. }
  104. bool operator()(cmGeneratorTarget const* l,
  105. cmGeneratorTarget const* r) const;
  106. };
  107. class OrderedTargetDependSet;
  108. bool FindMakeProgram(cmMakefile*) override;
  109. std::string ExpandCFGIntDir(std::string const& str,
  110. std::string const& config) const override;
  111. void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
  112. std::string GetStartupProjectName(cmLocalGenerator const* root) const;
  113. void AddSymbolExportCommand(cmGeneratorTarget*,
  114. std::vector<cmCustomCommand>& commands,
  115. std::string const& configName);
  116. bool Open(std::string const& bindir, std::string const& projectName,
  117. bool dryRun) override;
  118. bool IsVisualStudio() const override { return true; }
  119. //! Lookup a stored GUID or compute one deterministically.
  120. std::string GetGUID(std::string const& name) const;
  121. protected:
  122. cmGlobalVisualStudioGenerator(cmake* cm);
  123. virtual bool InitializePlatform(cmMakefile* mf);
  124. void AddExtraIDETargets() override;
  125. // Does this VS version link targets to each other if there are
  126. // dependencies in the SLN file? This was done for VS versions
  127. // below 8.
  128. virtual bool VSLinksDependencies() const { return true; }
  129. char const* GetIDEVersion() const;
  130. VSVersion Version;
  131. bool ExpressEdition;
  132. std::string GeneratorPlatform;
  133. std::string DefaultPlatformName;
  134. /** Return true if the configuration needs to be deployed */
  135. virtual bool NeedsDeploy(cmGeneratorTarget const& target,
  136. char const* config) const = 0;
  137. /** Returns true if the target system support debugging deployment. */
  138. virtual bool TargetSystemSupportsDeployment() const = 0;
  139. std::set<std::string> IsPartOfDefaultBuild(
  140. std::vector<std::string> const& configs,
  141. TargetDependSet const& projectTargets,
  142. cmGeneratorTarget const* target) const;
  143. bool IsDependedOn(TargetDependSet const& projectTargets,
  144. cmGeneratorTarget const* target) const;
  145. std::map<std::string, std::string> GUIDMap;
  146. cm::VS::Solution CreateSolution(cmLocalGenerator const* root,
  147. TargetDependSet const& projectTargets) const;
  148. cm::VS::Solution::Folder* CreateSolutionFolder(
  149. cm::VS::Solution& solution, cm::string_view rawName) const;
  150. void Generate() override;
  151. void GenerateSolution(cmLocalGenerator const* root,
  152. std::vector<cmLocalGenerator*> const& generators);
  153. private:
  154. virtual std::string GetVSMakeProgram() = 0;
  155. void PrintCompilerAdvice(std::ostream&, std::string const&,
  156. cmValue) const override
  157. {
  158. }
  159. };
  160. class cmGlobalVisualStudioGenerator::OrderedTargetDependSet
  161. : public std::multiset<cmTargetDepend,
  162. cmGlobalVisualStudioGenerator::TargetCompare>
  163. {
  164. using derived = std::multiset<cmTargetDepend,
  165. cmGlobalVisualStudioGenerator::TargetCompare>;
  166. public:
  167. using TargetDependSet = cmGlobalGenerator::TargetDependSet;
  168. using TargetSet = cmGlobalVisualStudioGenerator::TargetSet;
  169. OrderedTargetDependSet(TargetDependSet const&, std::string const& first);
  170. OrderedTargetDependSet(TargetSet const&, std::string const& first);
  171. };