cmComputeLinkDepends.h 4.5 KB

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