1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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
15 #include "cmStandardIncludes.h"
17 #include "cmGraphAdjacencyList.h"
21 class cmComputeComponentGraph;
22 class cmGlobalGenerator;
24 class cmTargetDependSet;
26 /** \class cmComputeTargetDepends
27 * \brief Compute global interdependencies among targets.
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.
33 class cmComputeTargetDepends
36 cmComputeTargetDepends(cmGlobalGenerator* gg);
37 ~cmComputeTargetDepends();
41 std::vector<cmTarget*> const& GetTargets() const { return this->Targets; }
42 void GetTargetDirectDepends(cmTarget* t, cmTargetDependSet& deps);
44 void CollectTargets();
45 void CollectDepends();
46 void CollectTargetDepends(int depender_index);
47 void AddTargetDepend(int depender_index, const char* dependee_name,
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,
55 std::set<cmStdString> &emitted);
56 cmGlobalGenerator* GlobalGenerator;
60 // Collect all targets.
61 std::vector<cmTarget*> Targets;
62 std::map<cmTarget*, int> TargetIndex;
64 // Represent the target dependency graph. The entry at each
65 // top-level index corresponds to a depender whose dependencies are
67 typedef cmGraphNodeList NodeList;
68 typedef cmGraphEdgeList EdgeList;
69 typedef cmGraphAdjacencyList Graph;
72 void DisplayGraph(Graph const& graph, const char* name);
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,
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);