cmake/Source/cmComputeLinkDepends.h

207 lines
6.0 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>
2020-02-01 23:06:01 +01:00
#include <memory>
2020-08-30 11:54:41 +02:00
#include <queue>
2016-10-30 18:24:19 +01:00
#include <set>
#include <string>
2022-08-04 22:12:04 +02:00
#include <utility>
2016-10-30 18:24:19 +01:00
#include <vector>
2023-05-23 16:38:00 +02:00
#include "cmComputeComponentGraph.h"
2020-02-01 23:06:01 +01:00
#include "cmGraphAdjacencyList.h"
#include "cmLinkItem.h"
2020-08-30 11:54:41 +02:00
#include "cmListFileCache.h"
2020-02-01 23:06:01 +01:00
#include "cmTargetLinkLibraryType.h"
2016-10-30 18:24:19 +01:00
class cmGeneratorTarget;
class cmGlobalGenerator;
class cmMakefile;
class cmake;
/** \class cmComputeLinkDepends
* \brief Compute link dependencies for targets.
*/
class cmComputeLinkDepends
{
public:
2015-11-17 17:22:37 +01:00
cmComputeLinkDepends(cmGeneratorTarget const* target,
2022-08-04 22:12:04 +02:00
const std::string& config,
const std::string& linkLanguage);
~cmComputeLinkDepends();
2019-11-11 23:01:05 +01:00
cmComputeLinkDepends(const cmComputeLinkDepends&) = delete;
cmComputeLinkDepends& operator=(const cmComputeLinkDepends&) = delete;
// Basic information about each link item.
struct LinkEntry
{
2022-08-04 22:12:04 +02:00
LinkEntry() = default;
LinkEntry(BT<std::string> item, cmGeneratorTarget const* target = nullptr)
: Item(std::move(item))
, Target(target)
{
}
static const std::string DEFAULT;
enum EntryKind
{
Library,
Object,
SharedDep,
Flag,
// The following member is for the management of items specified
// through genex $<LINK_GROUP:...>
Group
};
2020-08-30 11:54:41 +02:00
BT<std::string> Item;
2019-11-11 23:01:05 +01:00
cmGeneratorTarget const* Target = nullptr;
2022-08-04 22:12:04 +02:00
EntryKind Kind = Library;
// The following member is for the management of items specified
// through genex $<LINK_LIBRARY:...>
std::string Feature = std::string(DEFAULT);
};
2020-02-01 23:06:01 +01:00
using EntryVector = std::vector<LinkEntry>;
EntryVector const& Compute();
void SetOldLinkDirMode(bool b);
2016-03-13 13:35:51 +01:00
std::set<cmGeneratorTarget const*> const& GetOldWrongConfigItems() const
2016-07-09 11:21:54 +02:00
{
return this->OldWrongConfigItems;
}
private:
// Context information.
2015-11-17 17:22:37 +01:00
cmGeneratorTarget const* Target;
cmMakefile* Makefile;
2014-08-03 19:52:23 +02:00
cmGlobalGenerator const* GlobalGenerator;
cmake* CMakeInstance;
2022-08-04 22:12:04 +02:00
std::string LinkLanguage;
2015-04-27 22:25:09 +02:00
std::string Config;
EntryVector FinalLinkEntries;
2022-08-04 22:12:04 +02:00
std::map<std::string, std::string> LinkLibraryOverride;
std::string const& GetCurrentFeature(
std::string const& item, std::string const& defaultFeature) const;
2023-05-23 16:38:00 +02:00
std::pair<std::map<cmLinkItem, size_t>::iterator, bool> AllocateLinkEntry(
2018-10-28 12:09:07 +01:00
cmLinkItem const& item);
2023-05-23 16:38:00 +02:00
std::pair<size_t, bool> AddLinkEntry(
cmLinkItem const& item,
size_t groupIndex = cmComputeComponentGraph::INVALID_COMPONENT);
2021-09-14 00:13:48 +02:00
void AddLinkObject(cmLinkItem const& item);
2023-05-23 16:38:00 +02:00
void AddVarLinkEntries(size_t depender_index, const char* value);
2009-10-04 10:30:41 +03:00
void AddDirectLinkEntries();
2015-04-27 22:25:09 +02:00
template <typename T>
2023-05-23 16:38:00 +02:00
void AddLinkEntries(size_t depender_index, std::vector<T> const& libs);
2021-09-14 00:13:48 +02:00
void AddLinkObjects(std::vector<cmLinkItem> const& objs);
2023-05-23 16:38:00 +02:00
cmLinkItem ResolveLinkItem(size_t depender_index, const std::string& name);
// One entry for each unique item.
std::vector<LinkEntry> EntryList;
2023-05-23 16:38:00 +02:00
std::map<cmLinkItem, size_t> LinkEntryIndex;
2022-08-04 22:12:04 +02:00
// map storing, for each group, the list of items
2023-05-23 16:38:00 +02:00
std::map<size_t, std::vector<size_t>> GroupItems;
2022-08-04 22:12:04 +02:00
// BFS of initial dependencies.
struct BFSEntry
{
2023-05-23 16:38:00 +02:00
size_t Index;
size_t GroupIndex;
const char* LibDepends;
};
std::queue<BFSEntry> BFSQueue;
2017-07-20 19:35:53 +02:00
void FollowLinkEntry(BFSEntry qe);
// Shared libraries that are included only because they are
// dependencies of other shared libraries, not because they are part
// of the interface.
struct SharedDepEntry
{
2015-04-27 22:25:09 +02:00
cmLinkItem Item;
2023-05-23 16:38:00 +02:00
size_t DependerIndex;
};
std::queue<SharedDepEntry> SharedDepQueue;
2023-05-23 16:38:00 +02:00
std::set<size_t> SharedDepFollowed;
void FollowSharedDeps(size_t depender_index, cmLinkInterface const* iface,
2012-04-19 19:04:21 +03:00
bool follow_interface = false);
2023-05-23 16:38:00 +02:00
void QueueSharedDependencies(size_t depender_index,
2015-04-27 22:25:09 +02:00
std::vector<cmLinkItem> const& deps);
void HandleSharedDependency(SharedDepEntry const& dep);
// Dependency inferral for each link item.
2023-05-23 16:38:00 +02:00
struct DependSet : public std::set<size_t>
2016-07-09 11:21:54 +02:00
{
};
struct DependSetList : public std::vector<DependSet>
{
2020-02-01 23:06:01 +01:00
bool Initialized = false;
2016-07-09 11:21:54 +02:00
};
2020-02-01 23:06:01 +01:00
std::vector<DependSetList> InferredDependSets;
void InferDependencies();
2022-08-04 22:12:04 +02:00
// To finalize dependencies over groups in place of raw items
void UpdateGroupDependencies();
// Ordering constraint graph adjacency list.
2020-02-01 23:06:01 +01:00
using NodeList = cmGraphNodeList;
using EdgeList = cmGraphEdgeList;
using Graph = cmGraphAdjacencyList;
Graph EntryConstraintGraph;
void CleanConstraintGraph();
2022-08-04 22:12:04 +02:00
bool CheckCircularDependencies() const;
void DisplayConstraintGraph();
// Ordering algorithm.
2022-08-04 22:12:04 +02:00
void OrderLinkEntries();
std::vector<char> ComponentVisited;
2023-05-23 16:38:00 +02:00
std::vector<size_t> ComponentOrder;
2015-11-17 17:22:37 +01:00
struct PendingComponent
{
// The real component id. Needed because the map is indexed by
// component topological index.
2023-05-23 16:38:00 +02:00
size_t Id;
// The number of times the component needs to be seen. This is
// always 1 for trivial components and is initially 2 for
// non-trivial components.
2023-05-23 16:38:00 +02:00
size_t Count;
// The entries yet to be seen to complete the component.
2023-05-23 16:38:00 +02:00
std::set<size_t> Entries;
};
2023-05-23 16:38:00 +02:00
std::map<size_t, PendingComponent> PendingComponents;
2020-02-01 23:06:01 +01:00
std::unique_ptr<cmComputeComponentGraph> CCG;
2023-05-23 16:38:00 +02:00
std::vector<size_t> FinalLinkOrder;
void DisplayComponents();
2023-05-23 16:38:00 +02:00
void VisitComponent(size_t c);
void VisitEntry(size_t index);
PendingComponent& MakePendingComponent(size_t component);
size_t ComputeComponentCount(NodeList const& nl);
void DisplayFinalEntries();
// Record of the original link line.
2023-05-23 16:38:00 +02:00
std::vector<size_t> OriginalEntries;
2016-03-13 13:35:51 +01:00
std::set<cmGeneratorTarget const*> OldWrongConfigItems;
2015-11-17 17:22:37 +01:00
void CheckWrongConfigItem(cmLinkItem const& item);
2021-09-14 00:13:48 +02:00
// Record of explicitly linked object files.
2023-05-23 16:38:00 +02:00
std::vector<size_t> ObjectEntries;
2021-09-14 00:13:48 +02:00
2023-05-23 16:38:00 +02:00
size_t ComponentOrderId;
2016-03-13 13:35:51 +01:00
cmTargetLinkLibraryType LinkType;
2015-11-17 17:22:37 +01:00
bool HasConfig;
bool DebugMode;
bool OldLinkDirMode;
};