cmComputeLinkDepends.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmComputeLinkDepends_h
  14. #define cmComputeLinkDepends_h
  15. #include "cmStandardIncludes.h"
  16. #include "cmTarget.h"
  17. #include "cmGraphAdjacencyList.h"
  18. #include <queue>
  19. class cmComputeComponentGraph;
  20. class cmGlobalGenerator;
  21. class cmLocalGenerator;
  22. class cmMakefile;
  23. class cmTarget;
  24. class cmake;
  25. /** \class cmComputeLinkDepends
  26. * \brief Compute link dependencies for targets.
  27. */
  28. class cmComputeLinkDepends
  29. {
  30. public:
  31. cmComputeLinkDepends(cmTarget* target, const char* config);
  32. ~cmComputeLinkDepends();
  33. // Basic information about each link item.
  34. struct LinkEntry
  35. {
  36. std::string Item;
  37. cmTarget* Target;
  38. bool IsSharedDep;
  39. bool IsFlag;
  40. LinkEntry(): Item(), Target(0), IsSharedDep(false), IsFlag(false) {}
  41. LinkEntry(LinkEntry const& r):
  42. Item(r.Item), Target(r.Target), IsSharedDep(r.IsSharedDep),
  43. IsFlag(r.IsFlag) {}
  44. };
  45. typedef std::vector<LinkEntry> EntryVector;
  46. EntryVector const& Compute();
  47. void SetOldLinkDirMode(bool b);
  48. std::set<cmTarget*> const& GetOldWrongConfigItems() const
  49. { return this->OldWrongConfigItems; }
  50. private:
  51. // Context information.
  52. cmTarget* Target;
  53. cmMakefile* Makefile;
  54. cmLocalGenerator* LocalGenerator;
  55. cmGlobalGenerator* GlobalGenerator;
  56. cmake* CMakeInstance;
  57. bool DebugMode;
  58. // Configuration information.
  59. const char* Config;
  60. cmTarget::LinkLibraryType LinkType;
  61. // Output information.
  62. EntryVector FinalLinkEntries;
  63. typedef cmTarget::LinkLibraryVectorType LinkLibraryVectorType;
  64. std::map<cmStdString, int>::iterator
  65. AllocateLinkEntry(std::string const& item);
  66. int AddLinkEntry(std::string const& item);
  67. void AddVarLinkEntries(int depender_index, const char* value);
  68. void AddTargetLinkEntries(int depender_index,
  69. LinkLibraryVectorType const& libs);
  70. void AddLinkEntries(int depender_index,
  71. std::vector<std::string> const& libs);
  72. std::string CleanItemName(std::string const& item);
  73. cmTarget* FindTargetToLink(const char* name);
  74. // One entry for each unique item.
  75. std::vector<LinkEntry> EntryList;
  76. std::map<cmStdString, int> LinkEntryIndex;
  77. // BFS of initial dependencies.
  78. struct BFSEntry
  79. {
  80. int Index;
  81. const char* LibDepends;
  82. };
  83. std::queue<BFSEntry> BFSQueue;
  84. void FollowLinkEntry(BFSEntry const&);
  85. // Shared libraries that are included only because they are
  86. // dependencies of other shared libraries, not because they are part
  87. // of the interface.
  88. struct SharedDepEntry
  89. {
  90. std::string Item;
  91. int DependerIndex;
  92. };
  93. std::queue<SharedDepEntry> SharedDepQueue;
  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 cmGraphAdjacencyList Graph;
  105. Graph EntryConstraintGraph;
  106. void CleanConstraintGraph();
  107. void DisplayConstraintGraph();
  108. // Ordering algorithm.
  109. void OrderLinkEntires();
  110. std::vector<char> ComponentVisited;
  111. std::vector<int> ComponentOrder;
  112. int ComponentOrderId;
  113. struct PendingComponent
  114. {
  115. // The real component id. Needed because the map is indexed by
  116. // component topological index.
  117. int Id;
  118. // The number of times the component needs to be seen. This is
  119. // always 1 for trivial components and is initially 2 for
  120. // non-trivial components.
  121. int Count;
  122. // The entries yet to be seen to complete the component.
  123. std::set<int> Entries;
  124. };
  125. std::map<int, PendingComponent> PendingComponents;
  126. cmComputeComponentGraph* CCG;
  127. std::vector<int> FinalLinkOrder;
  128. void DisplayComponents();
  129. void VisitComponent(unsigned int c);
  130. void VisitEntry(int index);
  131. PendingComponent& MakePendingComponent(unsigned int component);
  132. void DisplayFinalEntries();
  133. // Record of the original link line.
  134. std::vector<int> OriginalEntries;
  135. // Compatibility help.
  136. bool OldLinkDirMode;
  137. void CheckWrongConfigItem(std::string const& item);
  138. std::set<cmTarget*> OldWrongConfigItems;
  139. };
  140. #endif