cmComputeLinkDepends.h 4.9 KB

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