Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmComputeTargetDepends.h
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#pragma once
4
5
#include "cmConfigure.h" // IWYU pragma: keep
6
7
#include <cstddef>
8
#include <map>
9
#include <set>
10
#include <string>
11
#include <vector>
12
13
#include "cmGraphAdjacencyList.h"
14
15
class cmComputeComponentGraph;
16
class cmGeneratorTarget;
17
class cmGlobalGenerator;
18
class cmLinkItem;
19
class cmListFileBacktrace;
20
class cmSourceFile;
21
class cmTargetDependSet;
22
23
/** \class cmComputeTargetDepends
24
 * \brief Compute global interdependencies among targets.
25
 *
26
 * Static libraries may form cycles in the target dependency graph.
27
 * This class evaluates target dependencies globally and adjusts them
28
 * to remove cycles while preserving a safe build order.
29
 */
30
class cmComputeTargetDepends
31
{
32
public:
33
  cmComputeTargetDepends(cmGlobalGenerator* gg);
34
  ~cmComputeTargetDepends();
35
36
  bool Compute();
37
38
  std::vector<cmGeneratorTarget const*> const& GetTargets() const
39
0
  {
40
0
    return this->Targets;
41
0
  }
42
  void GetTargetDirectDepends(cmGeneratorTarget const* t,
43
                              cmTargetDependSet& deps);
44
45
private:
46
  struct TargetSideEffects
47
  {
48
    std::set<cmGeneratorTarget const*> CustomCommandSideEffects;
49
    std::map<std::string, std::set<cmGeneratorTarget const*>>
50
      LanguageSideEffects;
51
  };
52
53
  void CollectTargets();
54
  void CollectDepends();
55
  void CollectTargetDepends(size_t depender_index);
56
  void AddTargetDepend(size_t depender_index, cmLinkItem const& dependee_name,
57
                       bool linking, bool cross,
58
                       std::set<cmLinkItem>& emitted);
59
  void AddTargetDepend(size_t depender_index,
60
                       cmGeneratorTarget const* dependee,
61
                       cmListFileBacktrace const& dependee_backtrace,
62
                       bool linking, bool cross,
63
                       std::set<cmLinkItem>& emitted);
64
  void CollectSideEffects();
65
  void CollectSideEffectsForTarget(std::set<size_t>& visited,
66
                                   size_t depender_index);
67
  void ComputeIntermediateGraph();
68
  void OptimizeLinkDependencies(cmGeneratorTarget const* gt,
69
                                cmGraphEdgeList& outputEdges,
70
                                cmGraphEdgeList const& inputEdges);
71
  bool ComputeFinalDepends(cmComputeComponentGraph const& ccg);
72
  void AddInterfaceDepends(size_t depender_index,
73
                           cmLinkItem const& dependee_name,
74
                           std::string const& config,
75
                           std::set<cmLinkItem>& emitted);
76
  void AddInterfaceDepends(size_t depender_index,
77
                           cmGeneratorTarget const* dependee,
78
                           cmListFileBacktrace const& dependee_backtrace,
79
                           std::string const& config,
80
                           std::set<cmLinkItem>& emitted);
81
  void AddObjectDepends(size_t depender_index, cmSourceFile const* o,
82
                        std::set<cmLinkItem>& emitted);
83
  cmGlobalGenerator* GlobalGenerator;
84
  bool DebugMode;
85
  bool NoCycles;
86
87
  // Collect all targets.
88
  std::vector<cmGeneratorTarget const*> Targets;
89
  std::map<cmGeneratorTarget const*, size_t> TargetIndex;
90
91
  // Represent the target dependency graph.  The entry at each
92
  // top-level index corresponds to a depender whose dependencies are
93
  // listed.
94
  using NodeList = cmGraphNodeList;
95
  using EdgeList = cmGraphEdgeList;
96
  using Graph = cmGraphAdjacencyList;
97
  Graph InitialGraph;
98
  Graph IntermediateGraph;
99
  Graph FinalGraph;
100
  std::vector<TargetSideEffects> SideEffects;
101
  void DisplayGraph(Graph const& graph, std::string const& name);
102
  void DisplaySideEffects();
103
104
  // Deal with connected components.
105
  void DisplayComponents(cmComputeComponentGraph const& ccg,
106
                         std::string const& name);
107
  bool CheckComponents(cmComputeComponentGraph const& ccg);
108
  void ComplainAboutBadComponent(cmComputeComponentGraph const& ccg, size_t c,
109
                                 bool strong = false);
110
111
  std::vector<size_t> ComponentHead;
112
  std::vector<size_t> ComponentTail;
113
  bool IntraComponent(std::vector<size_t> const& cmap, size_t c, size_t i,
114
                      size_t* head, std::set<size_t>& emitted,
115
                      std::set<size_t>& visited);
116
};