cmComputeLinkDepends.h 4.5 KB

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