cmake/Source/cmComputeTargetDepends.h

115 lines
4.1 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h" // IWYU pragma: keep
2023-05-23 16:38:00 +02:00
#include <cstddef>
2016-10-30 18:24:19 +01:00
#include <map>
#include <set>
#include <string>
#include <vector>
2020-02-01 23:06:01 +01:00
#include "cmGraphAdjacencyList.h"
class cmComputeComponentGraph;
2016-10-30 18:24:19 +01:00
class cmGeneratorTarget;
class cmGlobalGenerator;
2015-04-27 22:25:09 +02:00
class cmLinkItem;
2022-08-04 22:12:04 +02:00
class cmListFileBacktrace;
2021-09-14 00:13:48 +02:00
class cmSourceFile;
2011-01-16 11:35:12 +01:00
class cmTargetDependSet;
/** \class cmComputeTargetDepends
* \brief Compute global interdependencies among targets.
*
* Static libraries may form cycles in the target dependency graph.
* This class evaluates target dependencies globally and adjusts them
* to remove cycles while preserving a safe build order.
*/
class cmComputeTargetDepends
{
public:
cmComputeTargetDepends(cmGlobalGenerator* gg);
~cmComputeTargetDepends();
bool Compute();
2016-07-09 11:21:54 +02:00
std::vector<cmGeneratorTarget const*> const& GetTargets() const
{
return this->Targets;
}
2015-11-17 17:22:37 +01:00
void GetTargetDirectDepends(cmGeneratorTarget const* t,
cmTargetDependSet& deps);
2016-07-09 11:21:54 +02:00
private:
2021-09-14 00:13:48 +02:00
struct TargetSideEffects
{
std::set<cmGeneratorTarget const*> CustomCommandSideEffects;
std::map<std::string, std::set<cmGeneratorTarget const*>>
LanguageSideEffects;
};
void CollectTargets();
void CollectDepends();
2023-05-23 16:38:00 +02:00
void CollectTargetDepends(size_t depender_index);
void AddTargetDepend(size_t depender_index, cmLinkItem const& dependee_name,
2020-08-30 11:54:41 +02:00
bool linking, bool cross);
2023-05-23 16:38:00 +02:00
void AddTargetDepend(size_t depender_index,
cmGeneratorTarget const* dependee,
2019-11-11 23:01:05 +01:00
cmListFileBacktrace const& dependee_backtrace,
2020-08-30 11:54:41 +02:00
bool linking, bool cross);
2021-09-14 00:13:48 +02:00
void CollectSideEffects();
2023-05-23 16:38:00 +02:00
void CollectSideEffectsForTarget(std::set<size_t>& visited,
size_t depender_index);
2021-09-14 00:13:48 +02:00
void ComputeIntermediateGraph();
void OptimizeLinkDependencies(cmGeneratorTarget const* gt,
cmGraphEdgeList& outputEdges,
cmGraphEdgeList const& inputEdges);
2010-11-13 01:00:53 +02:00
bool ComputeFinalDepends(cmComputeComponentGraph const& ccg);
2023-05-23 16:38:00 +02:00
void AddInterfaceDepends(size_t depender_index,
cmLinkItem const& dependee_name,
2017-07-20 19:35:53 +02:00
const std::string& config,
2018-10-28 12:09:07 +01:00
std::set<cmLinkItem>& emitted);
2023-05-23 16:38:00 +02:00
void AddInterfaceDepends(size_t depender_index,
2015-11-17 17:22:37 +01:00
cmGeneratorTarget const* dependee,
2019-11-11 23:01:05 +01:00
cmListFileBacktrace const& dependee_backtrace,
2015-04-27 22:25:09 +02:00
const std::string& config,
2018-10-28 12:09:07 +01:00
std::set<cmLinkItem>& emitted);
2023-05-23 16:38:00 +02:00
void AddObjectDepends(size_t depender_index, cmSourceFile const* o,
2021-09-14 00:13:48 +02:00
std::set<cmLinkItem>& emitted);
cmGlobalGenerator* GlobalGenerator;
bool DebugMode;
2009-10-04 10:30:41 +03:00
bool NoCycles;
// Collect all targets.
2015-11-17 17:22:37 +01:00
std::vector<cmGeneratorTarget const*> Targets;
2023-05-23 16:38:00 +02:00
std::map<cmGeneratorTarget const*, size_t> TargetIndex;
// Represent the target dependency graph. The entry at each
// top-level index corresponds to a depender whose dependencies are
// listed.
2020-02-01 23:06:01 +01:00
using NodeList = cmGraphNodeList;
using EdgeList = cmGraphEdgeList;
using Graph = cmGraphAdjacencyList;
Graph InitialGraph;
2021-09-14 00:13:48 +02:00
Graph IntermediateGraph;
Graph FinalGraph;
2021-09-14 00:13:48 +02:00
std::vector<TargetSideEffects> SideEffects;
2015-04-27 22:25:09 +02:00
void DisplayGraph(Graph const& graph, const std::string& name);
2021-09-14 00:13:48 +02:00
void DisplaySideEffects();
// Deal with connected components.
2021-09-14 00:13:48 +02:00
void DisplayComponents(cmComputeComponentGraph const& ccg,
const std::string& name);
bool CheckComponents(cmComputeComponentGraph const& ccg);
2023-05-23 16:38:00 +02:00
void ComplainAboutBadComponent(cmComputeComponentGraph const& ccg, size_t c,
2010-11-13 01:00:53 +02:00
bool strong = false);
2023-05-23 16:38:00 +02:00
std::vector<size_t> ComponentHead;
std::vector<size_t> ComponentTail;
bool IntraComponent(std::vector<size_t> const& cmap, size_t c, size_t i,
size_t* head, std::set<size_t>& emitted,
std::set<size_t>& visited);
};