cmComputeLinkDepends.h 4.8 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 "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);
  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. cmMakefile* Makefile;
  51. cmLocalGenerator* LocalGenerator;
  52. cmGlobalGenerator* GlobalGenerator;
  53. cmake* CMakeInstance;
  54. bool DebugMode;
  55. // Configuration information.
  56. const char* Config;
  57. cmTarget::LinkLibraryType LinkType;
  58. // Output information.
  59. EntryVector FinalLinkEntries;
  60. typedef cmTarget::LinkLibraryVectorType LinkLibraryVectorType;
  61. std::map<cmStdString, int>::iterator
  62. AllocateLinkEntry(std::string const& item);
  63. int AddLinkEntry(int depender_index, std::string const& item);
  64. void AddVarLinkEntries(int depender_index, const char* value);
  65. void AddDirectLinkEntries();
  66. void AddLinkEntries(int depender_index,
  67. std::vector<std::string> const& libs);
  68. cmTarget* FindTargetToLink(int depender_index, const char* name);
  69. // One entry for each unique item.
  70. std::vector<LinkEntry> EntryList;
  71. std::map<cmStdString, int> LinkEntryIndex;
  72. // BFS of initial dependencies.
  73. struct BFSEntry
  74. {
  75. int Index;
  76. const char* LibDepends;
  77. };
  78. std::queue<BFSEntry> BFSQueue;
  79. void FollowLinkEntry(BFSEntry const&);
  80. // Shared libraries that are included only because they are
  81. // dependencies of other shared libraries, not because they are part
  82. // of the interface.
  83. struct SharedDepEntry
  84. {
  85. std::string Item;
  86. int DependerIndex;
  87. };
  88. std::queue<SharedDepEntry> SharedDepQueue;
  89. void QueueSharedDependencies(int depender_index,
  90. std::vector<std::string> 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 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. int ComponentOrderId;
  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. // Compatibility help.
  132. bool OldLinkDirMode;
  133. void CheckWrongConfigItem(int depender_index, std::string const& item);
  134. std::set<cmTarget*> OldWrongConfigItems;
  135. };
  136. #endif