cmake/Source/cmComputeLinkDepends.h

165 lines
4.6 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. */
#ifndef cmComputeLinkDepends_h
#define cmComputeLinkDepends_h
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h" // IWYU pragma: keep
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>
#include <vector>
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"
class cmComputeComponentGraph;
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,
const std::string& config);
~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
{
2020-08-30 11:54:41 +02:00
BT<std::string> Item;
2019-11-11 23:01:05 +01:00
cmGeneratorTarget const* Target = nullptr;
bool IsSharedDep = false;
bool IsFlag = false;
};
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;
2015-04-27 22:25:09 +02:00
std::string Config;
EntryVector FinalLinkEntries;
2018-10-28 12:09:07 +01:00
std::map<cmLinkItem, int>::iterator AllocateLinkEntry(
cmLinkItem const& item);
2015-04-27 22:25:09 +02:00
int AddLinkEntry(cmLinkItem const& item);
void AddVarLinkEntries(int 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>
2016-07-09 11:21:54 +02:00
void AddLinkEntries(int depender_index, std::vector<T> const& libs);
2018-10-28 12:09:07 +01:00
cmLinkItem ResolveLinkItem(int depender_index, const std::string& name);
// One entry for each unique item.
std::vector<LinkEntry> EntryList;
2018-10-28 12:09:07 +01:00
std::map<cmLinkItem, int> LinkEntryIndex;
// BFS of initial dependencies.
struct BFSEntry
{
int Index;
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;
int DependerIndex;
};
std::queue<SharedDepEntry> SharedDepQueue;
2012-04-19 19:04:21 +03:00
std::set<int> SharedDepFollowed;
2016-07-09 11:21:54 +02:00
void FollowSharedDeps(int depender_index, cmLinkInterface const* iface,
2012-04-19 19:04:21 +03:00
bool follow_interface = false);
void QueueSharedDependencies(int 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.
2016-07-09 11:21:54 +02:00
struct DependSet : public std::set<int>
{
};
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();
// 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();
void DisplayConstraintGraph();
// Ordering algorithm.
void OrderLinkEntires();
std::vector<char> ComponentVisited;
std::vector<int> 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.
int 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.
int Count;
// The entries yet to be seen to complete the component.
std::set<int> Entries;
};
std::map<int, PendingComponent> PendingComponents;
2020-02-01 23:06:01 +01:00
std::unique_ptr<cmComputeComponentGraph> CCG;
std::vector<int> FinalLinkOrder;
void DisplayComponents();
void VisitComponent(unsigned int c);
void VisitEntry(int index);
PendingComponent& MakePendingComponent(unsigned int component);
2009-10-04 10:30:41 +03:00
int ComputeComponentCount(NodeList const& nl);
void DisplayFinalEntries();
// Record of the original link line.
std::vector<int> 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);
2015-11-17 17:22:37 +01:00
int 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;
};
#endif