1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
10 #include "cmLinkItem.h"
12 class cmGeneratorTarget
;
14 /** \class cmLinkItemGraphVisitor
15 * \brief Visits a graph of linked items.
17 * Allows to visit items and dependency links (direct and indirect) between
19 * This abstract class takes care of the graph traversal, making sure that:
20 * - it terminates even in the presence of cycles;
21 * - it visits every object once (and only once);
22 * - it visits the objects in the same order every time.
24 * Children classes only have to implement OnItem() etc. to handle whatever
25 * logic they care about.
27 class cmLinkItemGraphVisitor
30 virtual ~cmLinkItemGraphVisitor() = default;
32 virtual void VisitGraph(std::string
const& name
) = 0;
34 void VisitItem(cmLinkItem
const& item
);
37 enum class DependencyType
46 virtual void OnItem(cmLinkItem
const& item
) = 0;
48 virtual void OnDirectLink(cmLinkItem
const& depender
,
49 cmLinkItem
const& dependee
, DependencyType dt
) = 0;
51 virtual void OnIndirectLink(cmLinkItem
const& depender
,
52 cmLinkItem
const& dependee
) = 0;
55 std::set
<std::string
> VisitedItems
;
57 std::set
<std::pair
<std::string
, std::string
>> VisitedLinks
;
59 void VisitLinks(cmLinkItem
const& item
, cmLinkItem
const& rootItem
);
60 void VisitLinks(cmLinkItem
const& item
, cmLinkItem
const& rootItem
,
61 std::string
const& config
);
63 using Dependency
= std::pair
<DependencyType
, cmLinkItem
>;
64 using DependencyMap
= std::map
<std::string
, Dependency
>;
66 bool ItemVisited(cmLinkItem
const& item
);
67 bool LinkVisited(cmLinkItem
const& depender
, cmLinkItem
const& dependee
);
69 static void GetDependencies(cmGeneratorTarget
const& target
,
70 std::string
const& config
,
71 DependencyMap
& dependencies
);