cmComputeLinkDepends.h 5.0 KB

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