cmComputeLinkDepends.h 5.0 KB

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