cmComputeLinkDepends.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 "cmTarget.h"
  14. #include "cmGraphAdjacencyList.h"
  15. #include <queue>
  16. class cmComputeComponentGraph;
  17. class cmGlobalGenerator;
  18. class cmMakefile;
  19. class cmTarget;
  20. class cmake;
  21. /** \class cmComputeLinkDepends
  22. * \brief Compute link dependencies for targets.
  23. */
  24. class cmComputeLinkDepends
  25. {
  26. public:
  27. cmComputeLinkDepends(cmTarget const* target, const std::string& config);
  28. ~cmComputeLinkDepends();
  29. // Basic information about each link item.
  30. struct LinkEntry
  31. {
  32. std::string Item;
  33. cmTarget const* Target;
  34. bool IsSharedDep;
  35. bool IsFlag;
  36. LinkEntry(): Item(), Target(0), IsSharedDep(false), IsFlag(false) {}
  37. LinkEntry(LinkEntry const& r):
  38. Item(r.Item), Target(r.Target), IsSharedDep(r.IsSharedDep),
  39. IsFlag(r.IsFlag) {}
  40. };
  41. typedef std::vector<LinkEntry> EntryVector;
  42. EntryVector const& Compute();
  43. void SetOldLinkDirMode(bool b);
  44. std::set<cmTarget const*> const& GetOldWrongConfigItems() const
  45. { return this->OldWrongConfigItems; }
  46. private:
  47. // Context information.
  48. cmTarget const* Target;
  49. cmMakefile* Makefile;
  50. cmGlobalGenerator const* GlobalGenerator;
  51. cmake* CMakeInstance;
  52. bool DebugMode;
  53. // Configuration information.
  54. bool HasConfig;
  55. std::string Config;
  56. cmTarget::LinkLibraryType LinkType;
  57. // Output information.
  58. EntryVector FinalLinkEntries;
  59. typedef cmTarget::LinkLibraryVectorType LinkLibraryVectorType;
  60. std::map<std::string, int>::iterator
  61. AllocateLinkEntry(std::string const& item);
  62. int AddLinkEntry(cmLinkItem const& item);
  63. void AddVarLinkEntries(int depender_index, const char* value);
  64. void AddDirectLinkEntries();
  65. template <typename T>
  66. void AddLinkEntries(int depender_index, std::vector<T> const& libs);
  67. cmTarget const* FindTargetToLink(int depender_index,
  68. const std::string& name);
  69. // One entry for each unique item.
  70. std::vector<LinkEntry> EntryList;
  71. std::map<std::string, int> LinkEntryIndex;
  72. // BFS of initial dependencies.
  73. struct BFSEntry
  74. {
  75. int Index;
  76. const char* LibDepends;
  77. };
  78. std::queue<BFSEntry> BFSQueue;
  79. void FollowLinkEntry(BFSEntry const&);
  80. // Shared libraries that are included only because they are
  81. // dependencies of other shared libraries, not because they are part
  82. // of the interface.
  83. struct SharedDepEntry
  84. {
  85. cmLinkItem Item;
  86. int DependerIndex;
  87. };
  88. std::queue<SharedDepEntry> SharedDepQueue;
  89. std::set<int> SharedDepFollowed;
  90. void FollowSharedDeps(int depender_index,
  91. cmTarget::LinkInterface const* iface,
  92. bool follow_interface = false);
  93. void QueueSharedDependencies(int depender_index,
  94. std::vector<cmLinkItem> const& deps);
  95. void HandleSharedDependency(SharedDepEntry const& dep);
  96. // Dependency inferral for each link item.
  97. struct DependSet: public std::set<int> {};
  98. struct DependSetList: public std::vector<DependSet> {};
  99. std::vector<DependSetList*> InferredDependSets;
  100. void InferDependencies();
  101. // Ordering constraint graph adjacency list.
  102. typedef cmGraphNodeList NodeList;
  103. typedef cmGraphEdgeList EdgeList;
  104. typedef cmGraphAdjacencyList Graph;
  105. Graph EntryConstraintGraph;
  106. void CleanConstraintGraph();
  107. void DisplayConstraintGraph();
  108. // Ordering algorithm.
  109. void OrderLinkEntires();
  110. std::vector<char> ComponentVisited;
  111. std::vector<int> ComponentOrder;
  112. int ComponentOrderId;
  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. // Compatibility help.
  137. bool OldLinkDirMode;
  138. void CheckWrongConfigItem(cmLinkItem const& item);
  139. std::set<cmTarget const*> OldWrongConfigItems;
  140. };
  141. #endif