1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmComputeLinkDepends.h,v $
6 Date: $Date: 2009-07-06 20:25:19 $
7 Version: $Revision: 1.18 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #ifndef cmComputeLinkDepends_h
18 #define cmComputeLinkDepends_h
20 #include "cmStandardIncludes.h"
23 #include "cmGraphAdjacencyList.h"
27 class cmComputeComponentGraph
;
28 class cmGlobalGenerator
;
29 class cmLocalGenerator
;
34 /** \class cmComputeLinkDepends
35 * \brief Compute link dependencies for targets.
37 class cmComputeLinkDepends
40 cmComputeLinkDepends(cmTarget
* target
, const char* config
);
41 ~cmComputeLinkDepends();
43 // Basic information about each link item.
50 LinkEntry(): Item(), Target(0), IsSharedDep(false), IsFlag(false) {}
51 LinkEntry(LinkEntry
const& r
):
52 Item(r
.Item
), Target(r
.Target
), IsSharedDep(r
.IsSharedDep
),
56 typedef std::vector
<LinkEntry
> EntryVector
;
57 EntryVector
const& Compute();
59 void SetOldLinkDirMode(bool b
);
60 std::set
<cmTarget
*> const& GetOldWrongConfigItems() const
61 { return this->OldWrongConfigItems
; }
65 // Context information.
68 cmLocalGenerator
* LocalGenerator
;
69 cmGlobalGenerator
* GlobalGenerator
;
73 // Configuration information.
75 cmTarget::LinkLibraryType LinkType
;
77 // Output information.
78 EntryVector FinalLinkEntries
;
80 typedef cmTarget::LinkLibraryVectorType LinkLibraryVectorType
;
82 std::map
<cmStdString
, int>::iterator
83 AllocateLinkEntry(std::string
const& item
);
84 int AddLinkEntry(int depender_index
, std::string
const& item
);
85 void AddVarLinkEntries(int depender_index
, const char* value
);
86 void AddDirectLinkEntries();
87 void AddLinkEntries(int depender_index
,
88 std::vector
<std::string
> const& libs
);
89 cmTarget
* FindTargetToLink(int depender_index
, const char* name
);
91 // One entry for each unique item.
92 std::vector
<LinkEntry
> EntryList
;
93 std::map
<cmStdString
, int> LinkEntryIndex
;
95 // BFS of initial dependencies.
99 const char* LibDepends
;
101 std::queue
<BFSEntry
> BFSQueue
;
102 void FollowLinkEntry(BFSEntry
const&);
104 // Shared libraries that are included only because they are
105 // dependencies of other shared libraries, not because they are part
107 struct SharedDepEntry
112 std::queue
<SharedDepEntry
> SharedDepQueue
;
113 void QueueSharedDependencies(int depender_index
,
114 std::vector
<std::string
> const& deps
);
115 void HandleSharedDependency(SharedDepEntry
const& dep
);
117 // Dependency inferral for each link item.
118 struct DependSet
: public std::set
<int> {};
119 struct DependSetList
: public std::vector
<DependSet
> {};
120 std::vector
<DependSetList
*> InferredDependSets
;
121 void InferDependencies();
123 // Ordering constraint graph adjacency list.
124 typedef cmGraphNodeList NodeList
;
125 typedef cmGraphAdjacencyList Graph
;
126 Graph EntryConstraintGraph
;
127 void CleanConstraintGraph();
128 void DisplayConstraintGraph();
130 // Ordering algorithm.
131 void OrderLinkEntires();
132 std::vector
<char> ComponentVisited
;
133 std::vector
<int> ComponentOrder
;
134 int ComponentOrderId
;
135 struct PendingComponent
137 // The real component id. Needed because the map is indexed by
138 // component topological index.
141 // The number of times the component needs to be seen. This is
142 // always 1 for trivial components and is initially 2 for
143 // non-trivial components.
146 // The entries yet to be seen to complete the component.
147 std::set
<int> Entries
;
149 std::map
<int, PendingComponent
> PendingComponents
;
150 cmComputeComponentGraph
* CCG
;
151 std::vector
<int> FinalLinkOrder
;
152 void DisplayComponents();
153 void VisitComponent(unsigned int c
);
154 void VisitEntry(int index
);
155 PendingComponent
& MakePendingComponent(unsigned int component
);
156 void DisplayFinalEntries();
158 // Record of the original link line.
159 std::vector
<int> OriginalEntries
;
161 // Compatibility help.
163 void CheckWrongConfigItem(int depender_index
, std::string
const& item
);
164 std::set
<cmTarget
*> OldWrongConfigItems
;