cmComputeLinkInformation.h 6.4 KB

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