cmComputeLinkDepends.h 4.5 KB

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