cmComputeLinkDepends.h 5.0 KB

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