cmComputeLinkDepends.h 5.1 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 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* 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& 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* 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* FindTargetToLink(int depender_index, const char* name);
  71. // One entry for each unique item.
  72. std::vector<LinkEntry> EntryList;
  73. std::map<cmStdString, 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. std::string 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<std::string> 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(int depender_index, std::string const& item);
  141. std::set<cmTarget*> OldWrongConfigItems;
  142. };
  143. #endif