cmGlobalVisualStudioGenerator.h 5.4 KB

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