cmComputeLinkInformation.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 cmComputeLinkInformation_h
  4. #define cmComputeLinkInformation_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include "cmsys/RegularExpression.hxx"
  7. #include <iosfwd>
  8. #include <set>
  9. #include <string>
  10. #include <vector>
  11. class cmGeneratorTarget;
  12. class cmGlobalGenerator;
  13. class cmMakefile;
  14. class cmOrderDirectories;
  15. class cmake;
  16. /** \class cmComputeLinkInformation
  17. * \brief Compute link information for a target in one configuration.
  18. */
  19. class cmComputeLinkInformation
  20. {
  21. public:
  22. cmComputeLinkInformation(cmGeneratorTarget const* target,
  23. const std::string& config);
  24. ~cmComputeLinkInformation();
  25. bool Compute();
  26. struct Item
  27. {
  28. Item()
  29. : Value()
  30. , IsPath(true)
  31. , Target(nullptr)
  32. {
  33. }
  34. Item(std::string const& v, bool p,
  35. cmGeneratorTarget const* target = nullptr)
  36. : Value(v)
  37. , IsPath(p)
  38. , Target(target)
  39. {
  40. }
  41. std::string Value;
  42. bool IsPath;
  43. cmGeneratorTarget const* Target;
  44. };
  45. typedef std::vector<Item> ItemVector;
  46. ItemVector const& GetItems();
  47. std::vector<std::string> const& GetDirectories();
  48. std::vector<std::string> const& GetDepends();
  49. std::vector<std::string> const& GetFrameworkPaths();
  50. std::string GetLinkLanguage() const { return this->LinkLanguage; }
  51. std::vector<std::string> const& GetRuntimeSearchPath();
  52. std::string const& GetRuntimeFlag() const { return this->RuntimeFlag; }
  53. std::string const& GetRuntimeSep() const { return this->RuntimeSep; }
  54. void GetRPath(std::vector<std::string>& runtimeDirs, bool for_install);
  55. std::string GetRPathString(bool for_install);
  56. std::string GetChrpathString();
  57. std::set<cmGeneratorTarget const*> const& GetSharedLibrariesLinked();
  58. std::string const& GetRPathLinkFlag() const { return this->RPathLinkFlag; }
  59. std::string GetRPathLinkString();
  60. std::string GetConfig() const { return this->Config; }
  61. private:
  62. void AddItem(std::string const& item, const cmGeneratorTarget* tgt);
  63. void AddSharedDepItem(std::string const& item, cmGeneratorTarget const* tgt);
  64. // Output information.
  65. ItemVector Items;
  66. std::vector<std::string> Directories;
  67. std::vector<std::string> Depends;
  68. std::vector<std::string> FrameworkPaths;
  69. std::vector<std::string> RuntimeSearchPath;
  70. std::set<cmGeneratorTarget const*> SharedLibrariesLinked;
  71. // Context information.
  72. cmGeneratorTarget const* Target;
  73. cmMakefile* Makefile;
  74. cmGlobalGenerator* GlobalGenerator;
  75. cmake* CMakeInstance;
  76. // Configuration information.
  77. std::string Config;
  78. std::string LinkLanguage;
  79. // Modes for dealing with dependent shared libraries.
  80. enum SharedDepMode
  81. {
  82. SharedDepModeNone, // Drop
  83. SharedDepModeDir, // List dir in -rpath-link flag
  84. SharedDepModeLibDir, // List dir in linker search path
  85. SharedDepModeLink // List file on link line
  86. };
  87. const char* LoaderFlag;
  88. std::string LibLinkFlag;
  89. std::string LibLinkFileFlag;
  90. std::string LibLinkSuffix;
  91. std::string RuntimeFlag;
  92. std::string RuntimeSep;
  93. std::string RuntimeAlways;
  94. std::string RPathLinkFlag;
  95. SharedDepMode SharedDependencyMode;
  96. enum LinkType
  97. {
  98. LinkUnknown,
  99. LinkStatic,
  100. LinkShared
  101. };
  102. void SetCurrentLinkType(LinkType lt);
  103. // Link type adjustment.
  104. void ComputeLinkTypeInfo();
  105. LinkType StartLinkType;
  106. LinkType CurrentLinkType;
  107. std::string StaticLinkTypeFlag;
  108. std::string SharedLinkTypeFlag;
  109. // Link item parsing.
  110. void ComputeItemParserInfo();
  111. std::vector<std::string> StaticLinkExtensions;
  112. std::vector<std::string> SharedLinkExtensions;
  113. std::vector<std::string> LinkExtensions;
  114. std::set<std::string> LinkPrefixes;
  115. cmsys::RegularExpression ExtractStaticLibraryName;
  116. cmsys::RegularExpression ExtractSharedLibraryName;
  117. cmsys::RegularExpression ExtractAnyLibraryName;
  118. std::string SharedRegexString;
  119. void AddLinkPrefix(const char* p);
  120. void AddLinkExtension(const char* e, LinkType type);
  121. std::string CreateExtensionRegex(std::vector<std::string> const& exts,
  122. LinkType type);
  123. std::string NoCaseExpression(const char* str);
  124. // Handling of link items.
  125. void AddTargetItem(std::string const& item, const cmGeneratorTarget* target);
  126. void AddFullItem(std::string const& item);
  127. bool CheckImplicitDirItem(std::string const& item);
  128. void AddUserItem(std::string const& item, bool pathNotKnown);
  129. void AddDirectoryItem(std::string const& item);
  130. void AddFrameworkItem(std::string const& item);
  131. void DropDirectoryItem(std::string const& item);
  132. bool CheckSharedLibNoSOName(std::string const& item);
  133. void AddSharedLibNoSOName(std::string const& item);
  134. void HandleBadFullItem(std::string const& item, std::string const& file);
  135. // Framework info.
  136. void ComputeFrameworkInfo();
  137. void AddFrameworkPath(std::string const& p);
  138. std::set<std::string> FrameworkPathsEmmitted;
  139. cmsys::RegularExpression SplitFramework;
  140. // Linker search path computation.
  141. cmOrderDirectories* OrderLinkerSearchPath;
  142. bool FinishLinkerSearchDirectories();
  143. void PrintLinkPolicyDiagnosis(std::ostream&);
  144. // Implicit link libraries and directories for linker language.
  145. void LoadImplicitLinkInfo();
  146. void AddImplicitLinkInfo();
  147. void AddImplicitLinkInfo(std::string const& lang);
  148. std::set<std::string> ImplicitLinkDirs;
  149. std::set<std::string> ImplicitLinkLibs;
  150. // Additional paths configured by the runtime linker
  151. std::vector<std::string> RuntimeLinkDirs;
  152. // Linker search path compatibility mode.
  153. std::set<std::string> OldLinkDirMask;
  154. std::vector<std::string> OldLinkDirItems;
  155. std::vector<std::string> OldUserFlagItems;
  156. std::set<std::string> CMP0060WarnItems;
  157. // Dependent library path computation.
  158. cmOrderDirectories* OrderDependentRPath;
  159. // Runtime path computation.
  160. cmOrderDirectories* OrderRuntimeSearchPath;
  161. bool OldLinkDirMode;
  162. bool OpenBSD;
  163. bool LinkDependsNoShared;
  164. bool UseImportLibrary;
  165. bool RuntimeUseChrpath;
  166. bool NoSONameUsesPath;
  167. bool LinkWithRuntimePath;
  168. bool LinkTypeEnabled;
  169. bool ArchivesMayBeShared;
  170. bool CMP0060Warn;
  171. void AddLibraryRuntimeInfo(std::string const& fullPath,
  172. const cmGeneratorTarget* target);
  173. void AddLibraryRuntimeInfo(std::string const& fullPath);
  174. };
  175. #endif