cmComputeLinkInformation.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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);
  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. // System info.
  69. bool UseImportLibrary;
  70. const char* LoaderFlag;
  71. std::string LibLinkFlag;
  72. std::string LibLinkFileFlag;
  73. std::string LibLinkSuffix;
  74. std::string RuntimeFlag;
  75. std::string RuntimeSep;
  76. std::string RuntimeAlways;
  77. bool RuntimeUseChrpath;
  78. // Link type adjustment.
  79. void ComputeLinkTypeInfo();
  80. enum LinkType { LinkUnknown, LinkStatic, LinkShared };
  81. LinkType StartLinkType;
  82. LinkType CurrentLinkType;
  83. std::string StaticLinkTypeFlag;
  84. std::string SharedLinkTypeFlag;
  85. bool LinkTypeEnabled;
  86. void SetCurrentLinkType(LinkType lt);
  87. // Link item parsing.
  88. void ComputeItemParserInfo();
  89. std::vector<std::string> StaticLinkExtensions;
  90. std::vector<std::string> SharedLinkExtensions;
  91. std::vector<std::string> LinkExtensions;
  92. std::set<cmStdString> LinkPrefixes;
  93. cmsys::RegularExpression RemoveLibraryExtension;
  94. cmsys::RegularExpression ExtractStaticLibraryName;
  95. cmsys::RegularExpression ExtractSharedLibraryName;
  96. cmsys::RegularExpression ExtractAnyLibraryName;
  97. void AddLinkPrefix(const char* p);
  98. void AddLinkExtension(const char* e, LinkType type);
  99. std::string CreateExtensionRegex(std::vector<std::string> const& exts);
  100. std::string NoCaseExpression(const char* str);
  101. // Handling of link items that are not targets or full file paths.
  102. void AddTargetItem(std::string const& item, cmTarget* target);
  103. void AddFullItem(std::string const& item);
  104. bool CheckImplicitDirItem(std::string const& item);
  105. void AddUserItem(std::string const& item);
  106. void AddDirectoryItem(std::string const& item);
  107. void AddFrameworkItem(std::string const& item);
  108. void DropDirectoryItem(std::string const& item);
  109. // Framework info.
  110. void ComputeFrameworkInfo();
  111. void AddFrameworkPath(std::string const& p);
  112. std::set<cmStdString> FrameworkPathsEmmitted;
  113. cmsys::RegularExpression SplitFramework;
  114. // Linker search path computation.
  115. void ComputeLinkerSearchDirectories();
  116. void AddLinkerSearchDirectories(std::vector<std::string> const& dirs);
  117. std::set<cmStdString> DirectoriesEmmitted;
  118. std::set<cmStdString> ImplicitLinkDirs;
  119. // Linker search path compatibility mode.
  120. std::vector<std::string> OldLinkDirs;
  121. bool OldLinkDirMode;
  122. bool HaveUserFlagItem;
  123. // Runtime path computation.
  124. struct LibraryRuntimeEntry
  125. {
  126. // The file name of the library.
  127. std::string FileName;
  128. // The soname of the shared library if it is known.
  129. std::string SOName;
  130. // The directory in which the library is supposed to be found.
  131. std::string Directory;
  132. // The index assigned to the directory.
  133. int DirectoryIndex;
  134. };
  135. bool RuntimeSearchPathComputed;
  136. std::vector<LibraryRuntimeEntry> LibraryRuntimeInfo;
  137. std::set<cmStdString> LibraryRuntimeInfoEmmitted;
  138. std::vector<std::string> RuntimeDirectories;
  139. std::map<cmStdString, int> RuntimeDirectoryIndex;
  140. std::vector<int> RuntimeDirectoryVisited;
  141. void AddLibraryRuntimeInfo(std::string const& fullPath, cmTarget* target);
  142. void AddLibraryRuntimeInfo(std::string const& fullPath,
  143. const char* soname = 0);
  144. void CollectRuntimeDirectories();
  145. int AddRuntimeDirectory(std::string const& dir);
  146. void FindConflictingLibraries();
  147. void FindDirectoriesForLib(unsigned int lri);
  148. void OrderRuntimeSearchPath();
  149. void VisitRuntimeDirectory(unsigned int i);
  150. void DiagnoseCycle();
  151. bool CycleDiagnosed;
  152. int WalkId;
  153. // Adjacency-list representation of runtime path ordering graph.
  154. // This maps from directory to those that must come *before* it.
  155. // Each entry that must come before is a pair. The first element is
  156. // the index of the directory that must come first. The second
  157. // element is the index of the runtime library that added the
  158. // constraint.
  159. typedef std::pair<int, int> RuntimeConflictPair;
  160. struct RuntimeConflictList: public std::vector<RuntimeConflictPair> {};
  161. std::vector<RuntimeConflictList> RuntimeConflictGraph;
  162. };
  163. #endif