cmComputeLinkDepends.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 cmComputeLinkDepends_h
  4. #define cmComputeLinkDepends_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include "cmGraphAdjacencyList.h"
  7. #include "cmLinkItem.h"
  8. #include "cmTargetLinkLibraryType.h"
  9. #include <map>
  10. #include <queue>
  11. #include <set>
  12. #include <string>
  13. #include <vector>
  14. class cmComputeComponentGraph;
  15. class cmGeneratorTarget;
  16. class cmGlobalGenerator;
  17. class cmMakefile;
  18. class cmake;
  19. /** \class cmComputeLinkDepends
  20. * \brief Compute link dependencies for targets.
  21. */
  22. class cmComputeLinkDepends
  23. {
  24. public:
  25. cmComputeLinkDepends(cmGeneratorTarget const* target,
  26. const std::string& config);
  27. ~cmComputeLinkDepends();
  28. // Basic information about each link item.
  29. struct LinkEntry
  30. {
  31. std::string Item;
  32. cmGeneratorTarget const* Target;
  33. bool IsSharedDep;
  34. bool IsFlag;
  35. LinkEntry()
  36. : Item()
  37. , Target(nullptr)
  38. , IsSharedDep(false)
  39. , IsFlag(false)
  40. {
  41. }
  42. LinkEntry(LinkEntry const& r)
  43. : Item(r.Item)
  44. , Target(r.Target)
  45. , IsSharedDep(r.IsSharedDep)
  46. , IsFlag(r.IsFlag)
  47. {
  48. }
  49. };
  50. typedef std::vector<LinkEntry> EntryVector;
  51. EntryVector const& Compute();
  52. void SetOldLinkDirMode(bool b);
  53. std::set<cmGeneratorTarget const*> const& GetOldWrongConfigItems() const
  54. {
  55. return this->OldWrongConfigItems;
  56. }
  57. private:
  58. // Context information.
  59. cmGeneratorTarget const* Target;
  60. cmMakefile* Makefile;
  61. cmGlobalGenerator const* GlobalGenerator;
  62. cmake* CMakeInstance;
  63. std::string Config;
  64. EntryVector FinalLinkEntries;
  65. std::map<std::string, int>::iterator AllocateLinkEntry(
  66. std::string const& item);
  67. int AddLinkEntry(cmLinkItem const& item);
  68. void AddVarLinkEntries(int depender_index, const char* value);
  69. void AddDirectLinkEntries();
  70. template <typename T>
  71. void AddLinkEntries(int depender_index, std::vector<T> const& libs);
  72. cmGeneratorTarget const* FindTargetToLink(int depender_index,
  73. const std::string& name);
  74. // One entry for each unique item.
  75. std::vector<LinkEntry> EntryList;
  76. std::map<std::string, int> LinkEntryIndex;
  77. // BFS of initial dependencies.
  78. struct BFSEntry
  79. {
  80. int Index;
  81. const char* LibDepends;
  82. };
  83. std::queue<BFSEntry> BFSQueue;
  84. void FollowLinkEntry(BFSEntry qe);
  85. // Shared libraries that are included only because they are
  86. // dependencies of other shared libraries, not because they are part
  87. // of the interface.
  88. struct SharedDepEntry
  89. {
  90. cmLinkItem Item;
  91. int DependerIndex;
  92. };
  93. std::queue<SharedDepEntry> SharedDepQueue;
  94. std::set<int> SharedDepFollowed;
  95. void FollowSharedDeps(int depender_index, cmLinkInterface const* iface,
  96. bool follow_interface = false);
  97. void QueueSharedDependencies(int depender_index,
  98. std::vector<cmLinkItem> const& deps);
  99. void HandleSharedDependency(SharedDepEntry const& dep);
  100. // Dependency inferral for each link item.
  101. struct DependSet : public std::set<int>
  102. {
  103. };
  104. struct DependSetList : public std::vector<DependSet>
  105. {
  106. };
  107. std::vector<DependSetList*> InferredDependSets;
  108. void InferDependencies();
  109. // Ordering constraint graph adjacency list.
  110. typedef cmGraphNodeList NodeList;
  111. typedef cmGraphEdgeList EdgeList;
  112. typedef cmGraphAdjacencyList Graph;
  113. Graph EntryConstraintGraph;
  114. void CleanConstraintGraph();
  115. void DisplayConstraintGraph();
  116. // Ordering algorithm.
  117. void OrderLinkEntires();
  118. std::vector<char> ComponentVisited;
  119. std::vector<int> ComponentOrder;
  120. struct PendingComponent
  121. {
  122. // The real component id. Needed because the map is indexed by
  123. // component topological index.
  124. int Id;
  125. // The number of times the component needs to be seen. This is
  126. // always 1 for trivial components and is initially 2 for
  127. // non-trivial components.
  128. int Count;
  129. // The entries yet to be seen to complete the component.
  130. std::set<int> Entries;
  131. };
  132. std::map<int, PendingComponent> PendingComponents;
  133. cmComputeComponentGraph* CCG;
  134. std::vector<int> FinalLinkOrder;
  135. void DisplayComponents();
  136. void VisitComponent(unsigned int c);
  137. void VisitEntry(int index);
  138. PendingComponent& MakePendingComponent(unsigned int component);
  139. int ComputeComponentCount(NodeList const& nl);
  140. void DisplayFinalEntries();
  141. // Record of the original link line.
  142. std::vector<int> OriginalEntries;
  143. std::set<cmGeneratorTarget const*> OldWrongConfigItems;
  144. void CheckWrongConfigItem(cmLinkItem const& item);
  145. int ComponentOrderId;
  146. cmTargetLinkLibraryType LinkType;
  147. bool HasConfig;
  148. bool DebugMode;
  149. bool OldLinkDirMode;
  150. };
  151. #endif