Imported Upstream version 2.8.11.2
[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   void AddInterfaceDepends(int depender_index, const char* dependee_name,
52                            bool linking, std::set<cmStdString> &emitted);
53   void AddInterfaceDepends(int depender_index, cmTarget* dependee,
54                            const char *config,
55                            std::set<cmStdString> &emitted);
56   cmGlobalGenerator* GlobalGenerator;
57   bool DebugMode;
58   bool NoCycles;
59
60   // Collect all targets.
61   std::vector<cmTarget*> Targets;
62   std::map<cmTarget*, int> TargetIndex;
63
64   // Represent the target dependency graph.  The entry at each
65   // top-level index corresponds to a depender whose dependencies are
66   // listed.
67   typedef cmGraphNodeList NodeList;
68   typedef cmGraphEdgeList EdgeList;
69   typedef cmGraphAdjacencyList Graph;
70   Graph InitialGraph;
71   Graph FinalGraph;
72   void DisplayGraph(Graph const& graph, const char* name);
73
74   // Deal with connected components.
75   void DisplayComponents(cmComputeComponentGraph const& ccg);
76   bool CheckComponents(cmComputeComponentGraph const& ccg);
77   void ComplainAboutBadComponent(cmComputeComponentGraph const& ccg, int c,
78                                  bool strong = false);
79
80   std::vector<int> ComponentHead;
81   std::vector<int> ComponentTail;
82   bool IntraComponent(std::vector<int> const& cmap, int c, int i, int* head,
83                       std::set<int>& emitted, std::set<int>& visited);
84 };
85
86 #endif