cmake/Source/cmLinkItem.h

173 lines
5.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
2015-11-17 17:22:37 +01:00
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2017-04-14 19:02:05 +02:00
#include <map>
2018-10-28 12:09:07 +01:00
#include <ostream>
2017-04-14 19:02:05 +02:00
#include <string>
2021-09-14 00:13:48 +02:00
#include <unordered_map>
2017-04-14 19:02:05 +02:00
#include <vector>
2024-04-14 22:45:38 +02:00
#include <cm/optional>
2020-08-30 11:54:41 +02:00
#include <cmext/algorithm>
2015-11-17 17:22:37 +01:00
#include "cmListFileCache.h"
2016-03-13 13:35:51 +01:00
#include "cmSystemTools.h"
2017-04-14 19:02:05 +02:00
#include "cmTargetLinkLibraryType.h"
2015-11-17 17:22:37 +01:00
2016-03-13 13:35:51 +01:00
class cmGeneratorTarget;
2023-12-07 09:12:54 +01:00
class cmSourceFile;
2015-11-17 17:22:37 +01:00
// Basic information about each link item.
2018-10-28 12:09:07 +01:00
class cmLinkItem
2015-11-17 17:22:37 +01:00
{
2018-10-28 12:09:07 +01:00
std::string String;
2016-07-09 11:21:54 +02:00
2015-11-17 17:22:37 +01:00
public:
2024-04-14 22:45:38 +02:00
// default feature: link library without decoration
static const std::string DEFAULT;
2018-10-28 12:09:07 +01:00
cmLinkItem();
2024-04-14 22:45:38 +02:00
cmLinkItem(std::string s, bool c, cmListFileBacktrace bt,
std::string feature = DEFAULT);
cmLinkItem(cmGeneratorTarget const* t, bool c, cmListFileBacktrace bt,
std::string feature = DEFAULT);
2018-10-28 12:09:07 +01:00
std::string const& AsStr() const;
2019-11-11 23:01:05 +01:00
cmGeneratorTarget const* Target = nullptr;
2023-12-07 09:12:54 +01:00
// The source file representing the external object (used when linking
// `$<TARGET_OBJECTS>`)
cmSourceFile const* ObjectSource = nullptr;
2024-04-14 22:45:38 +02:00
std::string Feature;
2020-08-30 11:54:41 +02:00
bool Cross = false;
2019-11-11 23:01:05 +01:00
cmListFileBacktrace Backtrace;
2018-10-28 12:09:07 +01:00
friend bool operator<(cmLinkItem const& l, cmLinkItem const& r);
friend bool operator==(cmLinkItem const& l, cmLinkItem const& r);
friend std::ostream& operator<<(std::ostream& os, cmLinkItem const& item);
2015-11-17 17:22:37 +01:00
};
2016-07-09 11:21:54 +02:00
class cmLinkImplItem : public cmLinkItem
2015-11-17 17:22:37 +01:00
{
public:
2018-10-28 12:09:07 +01:00
cmLinkImplItem();
2022-03-29 21:10:50 +02:00
cmLinkImplItem(cmLinkItem item, bool checkCMP0027);
bool CheckCMP0027 = false;
2015-11-17 17:22:37 +01:00
};
/** The link implementation specifies the direct library
dependencies needed by the object files of the target. */
struct cmLinkImplementationLibraries
{
// Libraries linked directly in this configuration.
std::vector<cmLinkImplItem> Libraries;
2021-09-14 00:13:48 +02:00
// Object files linked directly in this configuration.
std::vector<cmLinkItem> Objects;
2015-11-17 17:22:37 +01:00
// Libraries linked directly in other configurations.
// Needed only for OLD behavior of CMP0003.
std::vector<cmLinkItem> WrongConfigLibraries;
2020-08-30 11:54:41 +02:00
// Whether the list depends on a genex referencing the configuration.
bool HadContextSensitiveCondition = false;
2015-11-17 17:22:37 +01:00
};
struct cmLinkInterfaceLibraries
{
// Libraries listed in the interface.
std::vector<cmLinkItem> Libraries;
2020-02-01 23:06:01 +01:00
2021-09-14 00:13:48 +02:00
// Object files listed in the interface.
std::vector<cmLinkItem> Objects;
2022-08-04 22:12:04 +02:00
// Items to be included as if directly linked by the head target.
std::vector<cmLinkItem> HeadInclude;
// Items to be excluded from direct linking by the head target.
std::vector<cmLinkItem> HeadExclude;
2020-02-01 23:06:01 +01:00
// Whether the list depends on a genex referencing the head target.
bool HadHeadSensitiveCondition = false;
2020-08-30 11:54:41 +02:00
// Whether the list depends on a genex referencing the configuration.
bool HadContextSensitiveCondition = false;
2015-11-17 17:22:37 +01:00
};
2016-07-09 11:21:54 +02:00
struct cmLinkInterface : public cmLinkInterfaceLibraries
2015-11-17 17:22:37 +01:00
{
// Languages whose runtime libraries must be linked.
std::vector<std::string> Languages;
2021-09-14 00:13:48 +02:00
std::unordered_map<std::string, std::vector<cmLinkItem>>
LanguageRuntimeLibraries;
2015-11-17 17:22:37 +01:00
// Shared library dependencies needed for linking on some platforms.
std::vector<cmLinkItem> SharedDeps;
// Number of repetitions of a strongly connected component of two
// or more static libraries.
2019-11-11 23:01:05 +01:00
unsigned int Multiplicity = 0;
2015-11-17 17:22:37 +01:00
// Libraries listed for other configurations.
// Needed only for OLD behavior of CMP0003.
std::vector<cmLinkItem> WrongConfigLibraries;
2019-11-11 23:01:05 +01:00
bool ImplementationIsInterface = false;
2020-08-30 11:54:41 +02:00
// Whether the list depends on a link language genex.
bool HadLinkLanguageSensitiveCondition = false;
2015-11-17 17:22:37 +01:00
};
2016-07-09 11:21:54 +02:00
struct cmOptionalLinkInterface : public cmLinkInterface
2015-11-17 17:22:37 +01:00
{
2019-11-11 23:01:05 +01:00
bool LibrariesDone = false;
bool AllDone = false;
bool Exists = false;
2020-02-01 23:06:01 +01:00
bool Explicit = false;
2015-11-17 17:22:37 +01:00
};
2016-07-09 11:21:54 +02:00
struct cmHeadToLinkInterfaceMap
: public std::map<cmGeneratorTarget const*, cmOptionalLinkInterface>
2015-11-17 17:22:37 +01:00
{
};
2016-07-09 11:21:54 +02:00
struct cmLinkImplementation : public cmLinkImplementationLibraries
2015-11-17 17:22:37 +01:00
{
// Languages whose runtime libraries must be linked.
std::vector<std::string> Languages;
2021-09-14 00:13:48 +02:00
std::unordered_map<std::string, std::vector<cmLinkImplItem>>
LanguageRuntimeLibraries;
2020-08-30 11:54:41 +02:00
// Whether the list depends on a link language genex.
bool HadLinkLanguageSensitiveCondition = false;
2015-11-17 17:22:37 +01:00
};
// Cache link implementation computation from each configuration.
2016-07-09 11:21:54 +02:00
struct cmOptionalLinkImplementation : public cmLinkImplementation
2015-11-17 17:22:37 +01:00
{
2019-11-11 23:01:05 +01:00
bool LibrariesDone = false;
bool LanguagesDone = false;
bool HadHeadSensitiveCondition = false;
2015-11-17 17:22:37 +01:00
};
2016-03-13 13:35:51 +01:00
/** Compute the link type to use for the given configuration. */
2016-07-09 11:21:54 +02:00
inline cmTargetLinkLibraryType CMP0003_ComputeLinkType(
const std::string& config, std::vector<std::string> const& debugConfigs)
2016-03-13 13:35:51 +01:00
{
// No configuration is always optimized.
2016-07-09 11:21:54 +02:00
if (config.empty()) {
2016-03-13 13:35:51 +01:00
return OPTIMIZED_LibraryType;
2016-07-09 11:21:54 +02:00
}
2016-03-13 13:35:51 +01:00
// Check if any entry in the list matches this configuration.
std::string configUpper = cmSystemTools::UpperCase(config);
2020-08-30 11:54:41 +02:00
if (cm::contains(debugConfigs, configUpper)) {
2016-03-13 13:35:51 +01:00
return DEBUG_LibraryType;
2016-07-09 11:21:54 +02:00
}
2016-03-13 13:35:51 +01:00
// The current configuration is not a debug configuration.
return OPTIMIZED_LibraryType;
}
2024-04-14 22:45:38 +02:00
// Parse LINK_LIBRARY genex markers.
cm::optional<std::string> ParseLinkFeature(std::string const& item);