Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmComputeTargetDepends.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #ifndef cmComputeTargetDepends_h
13 #define cmComputeTargetDepends_h
14
15 #include "cmStandardIncludes.h"
16
17 #include "cmGraphAdjacencyList.h"
18
19 #include <stack>
20
21 class cmComputeComponentGraph;
22 class cmGlobalGenerator;
23 class cmTarget;
24 class cmTargetDependSet;
25
26 /** \class cmComputeTargetDepends
27  * \brief Compute global interdependencies among targets.
28  *
29  * Static libraries may form cycles in the target dependency graph.
30  * This class evaluates target dependencies globally and adjusts them
31  * to remove cycles while preserving a safe build order.
32  */
33 class cmComputeTargetDepends
34 {
35 public:
36   cmComputeTargetDepends(cmGlobalGenerator* gg);
37   ~cmComputeTargetDepends();
38
39   bool Compute();
40
41   std::vector<cmTarget*> const& GetTargets() const { return this->Targets; }
42   void GetTargetDirectDepends(cmTarget* t, cmTargetDependSet& deps);
43 private:
44   void CollectTargets();
45   void CollectDepends();
46   void CollectTargetDepends(int depender_index);
47   void AddTargetDepend(int depender_index, const char* dependee_name,
48                        bool linking);
49   void AddTargetDepend(int depender_index, cmTarget* dependee, bool linking);
50   bool ComputeFinalDepends(cmComputeComponentGraph const& ccg);
51
52   cmGlobalGenerator* GlobalGenerator;
53   bool DebugMode;
54   bool NoCycles;
55
56   // Collect all targets.
57   std::vector<cmTarget*> Targets;
58   std::map<cmTarget*, int> TargetIndex;
59
60   // Represent the target dependency graph.  The entry at each
61   // top-level index corresponds to a depender whose dependencies are
62   // listed.
63   typedef cmGraphNodeList NodeList;
64   typedef cmGraphEdgeList EdgeList;
65   typedef cmGraphAdjacencyList Graph;
66   Graph InitialGraph;
67   Graph FinalGraph;
68   void DisplayGraph(Graph const& graph, const char* name);
69
70   // Deal with connected components.
71   void DisplayComponents(cmComputeComponentGraph const& ccg);
72   bool CheckComponents(cmComputeComponentGraph const& ccg);
73   void ComplainAboutBadComponent(cmComputeComponentGraph const& ccg, int c,
74                                  bool strong = false);
75
76   std::vector<int> ComponentHead;
77   std::vector<int> ComponentTail;
78   bool IntraComponent(std::vector<int> const& cmap, int c, int i, int* head,
79                       std::set<int>& emitted, std::set<int>& visited);
80 };
81
82 #endif