cmComputeLinkDepends.h 5.1 KB

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