cmComputeLinkDepends.h 4.9 KB

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