cmComputeLinkInformation.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmComputeLinkInformation_h
  14. #define cmComputeLinkInformation_h
  15. #include "cmStandardIncludes.h"
  16. #include <cmsys/RegularExpression.hxx>
  17. class cmGlobalGenerator;
  18. class cmLocalGenerator;
  19. class cmMakefile;
  20. class cmTarget;
  21. /** \class cmComputeLinkInformation
  22. * \brief Compute link information for a target in one configuration.
  23. */
  24. class cmComputeLinkInformation
  25. {
  26. public:
  27. cmComputeLinkInformation(cmTarget* target, const char* config);
  28. bool Compute();
  29. struct Item
  30. {
  31. Item(): Value(), IsPath(true) {}
  32. Item(Item const& item): Value(item.Value), IsPath(item.IsPath) {}
  33. Item(std::string const& v, bool p): Value(v), IsPath(p) {}
  34. std::string Value;
  35. bool IsPath;
  36. };
  37. typedef std::vector<Item> ItemVector;
  38. ItemVector const& GetItems();
  39. std::vector<std::string> const& GetDirectories();
  40. std::vector<std::string> const& GetDepends();
  41. std::vector<std::string> const& GetFrameworkPaths();
  42. const char* GetLinkLanguage() const { return this->LinkLanguage; }
  43. std::vector<std::string> const& GetRuntimeSearchPath();
  44. std::string const& GetRuntimeFlag() const { return this->RuntimeFlag; }
  45. std::string const& GetRuntimeSep() const { return this->RuntimeSep; }
  46. void GetRPath(std::vector<std::string>& runtimeDirs, bool for_install);
  47. std::string GetRPathString(bool for_install);
  48. std::string GetChrpathString();
  49. std::string GetChrpathTool();
  50. std::set<cmTarget*> const& GetSharedLibrariesLinked();
  51. private:
  52. void AddItem(std::string const& item, cmTarget* tgt, bool isSharedDep);
  53. // Output information.
  54. ItemVector Items;
  55. std::vector<std::string> Directories;
  56. std::vector<std::string> Depends;
  57. std::vector<std::string> FrameworkPaths;
  58. std::vector<std::string> RuntimeSearchPath;
  59. std::set<cmTarget*> SharedLibrariesLinked;
  60. // Context information.
  61. cmTarget* Target;
  62. cmMakefile* Makefile;
  63. cmLocalGenerator* LocalGenerator;
  64. cmGlobalGenerator* GlobalGenerator;
  65. // Configuration information.
  66. const char* Config;
  67. const char* LinkLanguage;
  68. // Modes for dealing with dependent shared libraries.
  69. enum SharedDepMode
  70. {
  71. SharedDepModeNone, // Drop
  72. SharedDepModeDir, // Use in runtime information
  73. SharedDepModeLink // List file on link line
  74. };
  75. // System info.
  76. bool UseImportLibrary;
  77. const char* LoaderFlag;
  78. std::string LibLinkFlag;
  79. std::string LibLinkFileFlag;
  80. std::string LibLinkSuffix;
  81. std::string RuntimeFlag;
  82. std::string RuntimeSep;
  83. std::string RuntimeAlways;
  84. bool RuntimeUseChrpath;
  85. SharedDepMode SharedDependencyMode;
  86. // Link type adjustment.
  87. void ComputeLinkTypeInfo();
  88. enum LinkType { LinkUnknown, LinkStatic, LinkShared };
  89. LinkType StartLinkType;
  90. LinkType CurrentLinkType;
  91. std::string StaticLinkTypeFlag;
  92. std::string SharedLinkTypeFlag;
  93. bool LinkTypeEnabled;
  94. void SetCurrentLinkType(LinkType lt);
  95. // Link item parsing.
  96. void ComputeItemParserInfo();
  97. std::vector<std::string> StaticLinkExtensions;
  98. std::vector<std::string> SharedLinkExtensions;
  99. std::vector<std::string> LinkExtensions;
  100. std::set<cmStdString> LinkPrefixes;
  101. cmsys::RegularExpression RemoveLibraryExtension;
  102. cmsys::RegularExpression ExtractStaticLibraryName;
  103. cmsys::RegularExpression ExtractSharedLibraryName;
  104. cmsys::RegularExpression ExtractAnyLibraryName;
  105. void AddLinkPrefix(const char* p);
  106. void AddLinkExtension(const char* e, LinkType type);
  107. std::string CreateExtensionRegex(std::vector<std::string> const& exts);
  108. std::string NoCaseExpression(const char* str);
  109. // Handling of link items that are not targets or full file paths.
  110. void AddTargetItem(std::string const& item, cmTarget* target);
  111. void AddFullItem(std::string const& item);
  112. bool CheckImplicitDirItem(std::string const& item);
  113. void AddUserItem(std::string const& item);
  114. void AddDirectoryItem(std::string const& item);
  115. void AddFrameworkItem(std::string const& item);
  116. void DropDirectoryItem(std::string const& item);
  117. // Framework info.
  118. void ComputeFrameworkInfo();
  119. void AddFrameworkPath(std::string const& p);
  120. std::set<cmStdString> FrameworkPathsEmmitted;
  121. cmsys::RegularExpression SplitFramework;
  122. // Linker search path computation.
  123. void ComputeLinkerSearchDirectories();
  124. void AddLinkerSearchDirectories(std::vector<std::string> const& dirs);
  125. std::set<cmStdString> DirectoriesEmmitted;
  126. std::set<cmStdString> ImplicitLinkDirs;
  127. std::vector<std::string> SharedDependencyDirectories;
  128. // Linker search path compatibility mode.
  129. std::vector<std::string> OldLinkDirs;
  130. bool OldLinkDirMode;
  131. bool HaveUserFlagItem;
  132. // Runtime path computation.
  133. struct LibraryRuntimeEntry
  134. {
  135. // The file name of the library.
  136. std::string FileName;
  137. // The soname of the shared library if it is known.
  138. std::string SOName;
  139. // The directory in which the library is supposed to be found.
  140. std::string Directory;
  141. // The index assigned to the directory.
  142. int DirectoryIndex;
  143. };
  144. bool RuntimeSearchPathComputed;
  145. std::vector<LibraryRuntimeEntry> LibraryRuntimeInfo;
  146. std::set<cmStdString> LibraryRuntimeInfoEmmitted;
  147. std::vector<std::string> RuntimeDirectories;
  148. std::map<cmStdString, int> RuntimeDirectoryIndex;
  149. std::vector<int> RuntimeDirectoryVisited;
  150. void AddLibraryRuntimeInfo(std::string const& fullPath, cmTarget* target);
  151. void AddLibraryRuntimeInfo(std::string const& fullPath,
  152. const char* soname = 0);
  153. void CollectRuntimeDirectories();
  154. int AddRuntimeDirectory(std::string const& dir);
  155. void FindConflictingLibraries();
  156. void FindDirectoriesForLib(unsigned int lri);
  157. void OrderRuntimeSearchPath();
  158. void VisitRuntimeDirectory(unsigned int i);
  159. void DiagnoseCycle();
  160. bool CycleDiagnosed;
  161. int WalkId;
  162. // Adjacency-list representation of runtime path ordering graph.
  163. // This maps from directory to those that must come *before* it.
  164. // Each entry that must come before is a pair. The first element is
  165. // the index of the directory that must come first. The second
  166. // element is the index of the runtime library that added the
  167. // constraint.
  168. typedef std::pair<int, int> RuntimeConflictPair;
  169. struct RuntimeConflictList: public std::vector<RuntimeConflictPair> {};
  170. std::vector<RuntimeConflictList> RuntimeConflictGraph;
  171. };
  172. #endif