1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-17 07:11:52 +08:00

cmGeneratorTarget: Avoid boolean trap in usage requirement lookup

Replace `bool usage_requirements_only` arguments with a proper
enumeration to clarify meaning at call sites.
This commit is contained in:
Brad King
2021-12-08 16:39:31 -05:00
parent 642238b302
commit 1e49880472
4 changed files with 69 additions and 53 deletions

View File

@@ -106,7 +106,8 @@ void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties(
std::string sharedLibs; std::string sharedLibs;
std::string ldlibs; std::string ldlibs;
cmLinkInterfaceLibraries const* linkIFace = cmLinkInterfaceLibraries const* linkIFace =
target->GetLinkInterfaceLibraries(config, target, false); target->GetLinkInterfaceLibraries(
config, target, cmGeneratorTarget::LinkInterfaceFor::Link);
for (cmLinkItem const& item : linkIFace->Libraries) { for (cmLinkItem const& item : linkIFace->Libraries) {
cmGeneratorTarget const* gt = item.Target; cmGeneratorTarget const* gt = item.Target;
std::string const& lib = item.AsStr(); std::string const& lib = item.AsStr();

View File

@@ -55,6 +55,8 @@
class cmMessenger; class cmMessenger;
namespace { namespace {
using LinkInterfaceFor = cmGeneratorTarget::LinkInterfaceFor;
const cmsys::RegularExpression FrameworkRegularExpression( const cmsys::RegularExpression FrameworkRegularExpression(
"^(.*/)?([^/]*)\\.framework/(.*)$"); "^(.*/)?([^/]*)\\.framework/(.*)$");
} }
@@ -1324,7 +1326,7 @@ bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
bool cmGeneratorTarget::MaybeHaveInterfaceProperty( bool cmGeneratorTarget::MaybeHaveInterfaceProperty(
std::string const& prop, cmGeneratorExpressionContext* context, std::string const& prop, cmGeneratorExpressionContext* context,
bool usage_requirements_only) const LinkInterfaceFor interfaceFor) const
{ {
std::string const key = prop + '@' + context->Config; std::string const key = prop + '@' + context->Config;
auto i = this->MaybeInterfacePropertyExists.find(key); auto i = this->MaybeInterfacePropertyExists.find(key);
@@ -1342,7 +1344,7 @@ bool cmGeneratorTarget::MaybeHaveInterfaceProperty(
context->HeadTarget ? context->HeadTarget : this; context->HeadTarget ? context->HeadTarget : this;
if (cmLinkInterfaceLibraries const* iface = if (cmLinkInterfaceLibraries const* iface =
this->GetLinkInterfaceLibraries(context->Config, headTarget, this->GetLinkInterfaceLibraries(context->Config, headTarget,
usage_requirements_only)) { interfaceFor)) {
if (iface->HadHeadSensitiveCondition) { if (iface->HadHeadSensitiveCondition) {
// With a different head target we may get to a library with // With a different head target we may get to a library with
// this interface property. // this interface property.
@@ -1352,8 +1354,8 @@ bool cmGeneratorTarget::MaybeHaveInterfaceProperty(
// head target, so we can follow them. // head target, so we can follow them.
for (cmLinkItem const& lib : iface->Libraries) { for (cmLinkItem const& lib : iface->Libraries) {
if (lib.Target && if (lib.Target &&
lib.Target->MaybeHaveInterfaceProperty( lib.Target->MaybeHaveInterfaceProperty(prop, context,
prop, context, usage_requirements_only)) { interfaceFor)) {
maybeInterfaceProp = true; maybeInterfaceProp = true;
break; break;
} }
@@ -1368,13 +1370,12 @@ bool cmGeneratorTarget::MaybeHaveInterfaceProperty(
std::string cmGeneratorTarget::EvaluateInterfaceProperty( std::string cmGeneratorTarget::EvaluateInterfaceProperty(
std::string const& prop, cmGeneratorExpressionContext* context, std::string const& prop, cmGeneratorExpressionContext* context,
cmGeneratorExpressionDAGChecker* dagCheckerParent, cmGeneratorExpressionDAGChecker* dagCheckerParent,
bool usage_requirements_only) const LinkInterfaceFor interfaceFor) const
{ {
std::string result; std::string result;
// If the property does not appear transitively at all, we are done. // If the property does not appear transitively at all, we are done.
if (!this->MaybeHaveInterfaceProperty(prop, context, if (!this->MaybeHaveInterfaceProperty(prop, context, interfaceFor)) {
usage_requirements_only)) {
return result; return result;
} }
@@ -1406,7 +1407,7 @@ std::string cmGeneratorTarget::EvaluateInterfaceProperty(
} }
if (cmLinkInterfaceLibraries const* iface = this->GetLinkInterfaceLibraries( if (cmLinkInterfaceLibraries const* iface = this->GetLinkInterfaceLibraries(
context->Config, headTarget, usage_requirements_only)) { context->Config, headTarget, interfaceFor)) {
context->HadContextSensitiveCondition = context->HadContextSensitiveCondition =
context->HadContextSensitiveCondition || context->HadContextSensitiveCondition ||
iface->HadContextSensitiveCondition; iface->HadContextSensitiveCondition;
@@ -1424,7 +1425,7 @@ std::string cmGeneratorTarget::EvaluateInterfaceProperty(
context->Language); context->Language);
std::string libResult = cmGeneratorExpression::StripEmptyListElements( std::string libResult = cmGeneratorExpression::StripEmptyListElements(
lib.Target->EvaluateInterfaceProperty(prop, &libContext, &dagChecker, lib.Target->EvaluateInterfaceProperty(prop, &libContext, &dagChecker,
usage_requirements_only)); interfaceFor));
if (!libResult.empty()) { if (!libResult.empty()) {
if (result.empty()) { if (result.empty()) {
result = std::move(libResult); result = std::move(libResult);
@@ -1478,8 +1479,8 @@ std::string AddLangSpecificInterfaceIncludeDirectories(
} }
std::string directories; std::string directories;
if (const auto* interface = if (const auto* interface = target->GetLinkInterfaceLibraries(
target->GetLinkInterfaceLibraries(config, root, true)) { config, root, LinkInterfaceFor::Usage)) {
for (const cmLinkItem& library : interface->Libraries) { for (const cmLinkItem& library : interface->Libraries) {
if (const cmGeneratorTarget* dependency = library.Target) { if (const cmGeneratorTarget* dependency = library.Target) {
if (cm::contains(dependency->GetAllConfigCompileLanguages(), lang)) { if (cm::contains(dependency->GetAllConfigCompileLanguages(), lang)) {
@@ -1550,7 +1551,7 @@ void addInterfaceEntry(cmGeneratorTarget const* headTarget,
std::string const& lang, std::string const& lang,
cmGeneratorExpressionDAGChecker* dagChecker, cmGeneratorExpressionDAGChecker* dagChecker,
EvaluatedTargetPropertyEntries& entries, EvaluatedTargetPropertyEntries& entries,
bool usage_requirements_only, LinkInterfaceFor interfaceFor,
std::vector<cmLinkImplItem> const& libraries) std::vector<cmLinkImplItem> const& libraries)
{ {
for (cmLinkImplItem const& lib : libraries) { for (cmLinkImplItem const& lib : libraries) {
@@ -1563,7 +1564,7 @@ void addInterfaceEntry(cmGeneratorTarget const* headTarget,
headTarget->GetLocalGenerator(), config, false, headTarget, headTarget, headTarget->GetLocalGenerator(), config, false, headTarget, headTarget,
true, lib.Backtrace, lang); true, lib.Backtrace, lang);
cmExpandList(lib.Target->EvaluateInterfaceProperty( cmExpandList(lib.Target->EvaluateInterfaceProperty(
prop, &context, dagChecker, usage_requirements_only), prop, &context, dagChecker, interfaceFor),
ee.Values); ee.Values);
ee.ContextDependent = context.HadContextSensitiveCondition; ee.ContextDependent = context.HadContextSensitiveCondition;
entries.Entries.emplace_back(std::move(ee)); entries.Entries.emplace_back(std::move(ee));
@@ -1590,13 +1591,13 @@ enum class IncludeRuntimeInterface
Yes, Yes,
No No
}; };
void AddInterfaceEntries(cmGeneratorTarget const* headTarget, void AddInterfaceEntries(
std::string const& config, std::string const& prop, cmGeneratorTarget const* headTarget, std::string const& config,
std::string const& lang, std::string const& prop, std::string const& lang,
cmGeneratorExpressionDAGChecker* dagChecker, cmGeneratorExpressionDAGChecker* dagChecker,
EvaluatedTargetPropertyEntries& entries, EvaluatedTargetPropertyEntries& entries,
IncludeRuntimeInterface searchRuntime, IncludeRuntimeInterface searchRuntime,
bool usage_requirements_only = true) LinkInterfaceFor interfaceFor = LinkInterfaceFor::Usage)
{ {
if (searchRuntime == IncludeRuntimeInterface::Yes) { if (searchRuntime == IncludeRuntimeInterface::Yes) {
if (cmLinkImplementation const* impl = if (cmLinkImplementation const* impl =
@@ -1607,10 +1608,10 @@ void AddInterfaceEntries(cmGeneratorTarget const* headTarget,
auto runtimeLibIt = impl->LanguageRuntimeLibraries.find(lang); auto runtimeLibIt = impl->LanguageRuntimeLibraries.find(lang);
if (runtimeLibIt != impl->LanguageRuntimeLibraries.end()) { if (runtimeLibIt != impl->LanguageRuntimeLibraries.end()) {
addInterfaceEntry(headTarget, config, prop, lang, dagChecker, entries, addInterfaceEntry(headTarget, config, prop, lang, dagChecker, entries,
usage_requirements_only, runtimeLibIt->second); interfaceFor, runtimeLibIt->second);
} }
addInterfaceEntry(headTarget, config, prop, lang, dagChecker, entries, addInterfaceEntry(headTarget, config, prop, lang, dagChecker, entries,
usage_requirements_only, impl->Libraries); interfaceFor, impl->Libraries);
} }
} else { } else {
if (cmLinkImplementationLibraries const* impl = if (cmLinkImplementationLibraries const* impl =
@@ -1618,7 +1619,7 @@ void AddInterfaceEntries(cmGeneratorTarget const* headTarget,
entries.HadContextSensitiveCondition = entries.HadContextSensitiveCondition =
impl->HadContextSensitiveCondition; impl->HadContextSensitiveCondition;
addInterfaceEntry(headTarget, config, prop, lang, dagChecker, entries, addInterfaceEntry(headTarget, config, prop, lang, dagChecker, entries,
usage_requirements_only, impl->Libraries); interfaceFor, impl->Libraries);
} }
} }
} }
@@ -1851,7 +1852,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
EvaluatedTargetPropertyEntries linkInterfaceSourcesEntries; EvaluatedTargetPropertyEntries linkInterfaceSourcesEntries;
AddInterfaceEntries(this, config, "INTERFACE_SOURCES", std::string(), AddInterfaceEntries(this, config, "INTERFACE_SOURCES", std::string(),
&dagChecker, linkInterfaceSourcesEntries, &dagChecker, linkInterfaceSourcesEntries,
IncludeRuntimeInterface::No, true); IncludeRuntimeInterface::No, LinkInterfaceFor::Usage);
std::vector<std::string>::size_type numFilesBefore = files.size(); std::vector<std::string>::size_type numFilesBefore = files.size();
bool contextDependentInterfaceSources = processSources( bool contextDependentInterfaceSources = processSources(
this, linkInterfaceSourcesEntries, files, uniqueSrcs, debugSources); this, linkInterfaceSourcesEntries, files, uniqueSrcs, debugSources);
@@ -3083,7 +3084,8 @@ static void processILibs(const std::string& config,
if (item.Target && emitted.insert(item.Target).second) { if (item.Target && emitted.insert(item.Target).second) {
tgts.push_back(item.Target); tgts.push_back(item.Target);
if (cmLinkInterfaceLibraries const* iface = if (cmLinkInterfaceLibraries const* iface =
item.Target->GetLinkInterfaceLibraries(config, headTarget, true)) { item.Target->GetLinkInterfaceLibraries(config, headTarget,
LinkInterfaceFor::Usage)) {
for (cmLinkItem const& lib : iface->Libraries) { for (cmLinkItem const& lib : iface->Libraries) {
processILibs(config, headTarget, lib, gg, tgts, emitted); processILibs(config, headTarget, lib, gg, tgts, emitted);
} }
@@ -4580,7 +4582,9 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
AddInterfaceEntries(this, config, "INTERFACE_LINK_OPTIONS", language, AddInterfaceEntries(this, config, "INTERFACE_LINK_OPTIONS", language,
&dagChecker, entries, IncludeRuntimeInterface::Yes, &dagChecker, entries, IncludeRuntimeInterface::Yes,
this->GetPolicyStatusCMP0099() != cmPolicies::NEW); this->GetPolicyStatusCMP0099() == cmPolicies::NEW
? LinkInterfaceFor::Link
: LinkInterfaceFor::Usage);
processOptions(this, entries, result, uniqueOptions, debugOptions, processOptions(this, entries, result, uniqueOptions, debugOptions,
"link options", OptionsParse::Shell, this->IsDeviceLink()); "link options", OptionsParse::Shell, this->IsDeviceLink());
@@ -4846,7 +4850,9 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
AddInterfaceEntries(this, config, "INTERFACE_LINK_DIRECTORIES", language, AddInterfaceEntries(this, config, "INTERFACE_LINK_DIRECTORIES", language,
&dagChecker, entries, IncludeRuntimeInterface::Yes, &dagChecker, entries, IncludeRuntimeInterface::Yes,
this->GetPolicyStatusCMP0099() != cmPolicies::NEW); this->GetPolicyStatusCMP0099() == cmPolicies::NEW
? LinkInterfaceFor::Link
: LinkInterfaceFor::Usage);
processLinkDirectories(this, entries, result, uniqueDirectories, processLinkDirectories(this, entries, result, uniqueDirectories,
debugDirectories); debugDirectories);
@@ -4885,7 +4891,9 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
} }
AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS", language, AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS", language,
&dagChecker, entries, IncludeRuntimeInterface::Yes, &dagChecker, entries, IncludeRuntimeInterface::Yes,
this->GetPolicyStatusCMP0099() != cmPolicies::NEW); this->GetPolicyStatusCMP0099() == cmPolicies::NEW
? LinkInterfaceFor::Link
: LinkInterfaceFor::Usage);
processOptions(this, entries, result, uniqueOptions, false, "link depends", processOptions(this, entries, result, uniqueOptions, false, "link depends",
OptionsParse::None); OptionsParse::None);
@@ -6551,7 +6559,7 @@ void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
std::string const& value, std::string const& value,
std::string const& config, std::string const& config,
cmGeneratorTarget const* headTarget, cmGeneratorTarget const* headTarget,
bool usage_requirements_only, LinkInterfaceFor interfaceFor,
cmLinkInterface& iface) const cmLinkInterface& iface) const
{ {
// Keep this logic in sync with ComputeLinkImplementationLibraries. // Keep this logic in sync with ComputeLinkImplementationLibraries.
@@ -6560,7 +6568,7 @@ void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
// The $<LINK_ONLY> expression may be in a link interface to specify // The $<LINK_ONLY> expression may be in a link interface to specify
// private link dependencies that are otherwise excluded from usage // private link dependencies that are otherwise excluded from usage
// requirements. // requirements.
if (usage_requirements_only) { if (interfaceFor == LinkInterfaceFor::Usage) {
dagChecker.SetTransitivePropertiesOnly(); dagChecker.SetTransitivePropertiesOnly();
} }
std::vector<std::string> libs; std::vector<std::string> libs;
@@ -6610,7 +6618,8 @@ cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
{ {
// Imported targets have their own link interface. // Imported targets have their own link interface.
if (this->IsImported()) { if (this->IsImported()) {
return this->GetImportLinkInterface(config, head, false, secondPass); return this->GetImportLinkInterface(config, head, LinkInterfaceFor::Link,
secondPass);
} }
// Link interfaces are not supported for executables that do not // Link interfaces are not supported for executables that do not
@@ -6636,7 +6645,8 @@ cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
cmOptionalLinkInterface& iface = hm[head]; cmOptionalLinkInterface& iface = hm[head];
if (!iface.LibrariesDone) { if (!iface.LibrariesDone) {
iface.LibrariesDone = true; iface.LibrariesDone = true;
this->ComputeLinkInterfaceLibraries(config, iface, head, false); this->ComputeLinkInterfaceLibraries(config, iface, head,
LinkInterfaceFor::Link);
} }
if (!iface.AllDone) { if (!iface.AllDone) {
iface.AllDone = true; iface.AllDone = true;
@@ -6730,11 +6740,11 @@ void cmGeneratorTarget::ComputeLinkInterface(
const cmLinkInterfaceLibraries* cmGeneratorTarget::GetLinkInterfaceLibraries( const cmLinkInterfaceLibraries* cmGeneratorTarget::GetLinkInterfaceLibraries(
const std::string& config, cmGeneratorTarget const* head, const std::string& config, cmGeneratorTarget const* head,
bool usage_requirements_only) const LinkInterfaceFor interfaceFor) const
{ {
// Imported targets have their own link interface. // Imported targets have their own link interface.
if (this->IsImported()) { if (this->IsImported()) {
return this->GetImportLinkInterface(config, head, usage_requirements_only); return this->GetImportLinkInterface(config, head, interfaceFor);
} }
// Link interfaces are not supported for executables that do not // Link interfaces are not supported for executables that do not
@@ -6746,7 +6756,7 @@ const cmLinkInterfaceLibraries* cmGeneratorTarget::GetLinkInterfaceLibraries(
// Lookup any existing link interface for this configuration. // Lookup any existing link interface for this configuration.
cmHeadToLinkInterfaceMap& hm = cmHeadToLinkInterfaceMap& hm =
(usage_requirements_only (interfaceFor == LinkInterfaceFor::Usage
? this->GetHeadToLinkInterfaceUsageRequirementsMap(config) ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
: this->GetHeadToLinkInterfaceMap(config)); : this->GetHeadToLinkInterfaceMap(config));
@@ -6759,8 +6769,7 @@ const cmLinkInterfaceLibraries* cmGeneratorTarget::GetLinkInterfaceLibraries(
cmOptionalLinkInterface& iface = hm[head]; cmOptionalLinkInterface& iface = hm[head];
if (!iface.LibrariesDone) { if (!iface.LibrariesDone) {
iface.LibrariesDone = true; iface.LibrariesDone = true;
this->ComputeLinkInterfaceLibraries(config, iface, head, this->ComputeLinkInterfaceLibraries(config, iface, head, interfaceFor);
usage_requirements_only);
} }
return iface.Exists ? &iface : nullptr; return iface.Exists ? &iface : nullptr;
@@ -7021,7 +7030,7 @@ bool cmGeneratorTarget::GetRPATH(const std::string& config,
void cmGeneratorTarget::ComputeLinkInterfaceLibraries( void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
const std::string& config, cmOptionalLinkInterface& iface, const std::string& config, cmOptionalLinkInterface& iface,
cmGeneratorTarget const* headTarget, bool usage_requirements_only) const cmGeneratorTarget const* headTarget, LinkInterfaceFor interfaceFor) const
{ {
// Construct the property name suffix for this configuration. // Construct the property name suffix for this configuration.
std::string suffix = "_"; std::string suffix = "_";
@@ -7100,7 +7109,7 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
if (explicitLibraries) { if (explicitLibraries) {
// The interface libraries have been explicitly set. // The interface libraries have been explicitly set.
this->ExpandLinkItems(linkIfaceProp, *explicitLibraries, config, this->ExpandLinkItems(linkIfaceProp, *explicitLibraries, config,
headTarget, usage_requirements_only, iface); headTarget, interfaceFor, iface);
} }
// If the link interface is explicit, do not fall back to the link impl. // If the link interface is explicit, do not fall back to the link impl.
@@ -7114,14 +7123,14 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
iface.Libraries.insert(iface.Libraries.end(), impl->Libraries.begin(), iface.Libraries.insert(iface.Libraries.end(), impl->Libraries.begin(),
impl->Libraries.end()); impl->Libraries.end());
if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN && if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
!this->PolicyWarnedCMP0022 && !usage_requirements_only) { !this->PolicyWarnedCMP0022 && interfaceFor == LinkInterfaceFor::Link) {
// Compare the link implementation fallback link interface to the // Compare the link implementation fallback link interface to the
// preferred new link interface property and warn if different. // preferred new link interface property and warn if different.
cmLinkInterface ifaceNew; cmLinkInterface ifaceNew;
static const std::string newProp = "INTERFACE_LINK_LIBRARIES"; static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
if (cmValue newExplicitLibraries = this->GetProperty(newProp)) { if (cmValue newExplicitLibraries = this->GetProperty(newProp)) {
this->ExpandLinkItems(newProp, *newExplicitLibraries, config, this->ExpandLinkItems(newProp, *newExplicitLibraries, config,
headTarget, usage_requirements_only, ifaceNew); headTarget, interfaceFor, ifaceNew);
} }
if (ifaceNew.Libraries != iface.Libraries) { if (ifaceNew.Libraries != iface.Libraries) {
std::string oldLibraries = cmJoin(impl->Libraries, ";"); std::string oldLibraries = cmJoin(impl->Libraries, ";");
@@ -7235,7 +7244,7 @@ void cmGeneratorTarget::ComputeLinkImplementationRuntimeLibraries(
const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface( const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
const std::string& config, cmGeneratorTarget const* headTarget, const std::string& config, cmGeneratorTarget const* headTarget,
bool usage_requirements_only, bool secondPass) const LinkInterfaceFor interfaceFor, bool secondPass) const
{ {
cmGeneratorTarget::ImportInfo const* info = this->GetImportInfo(config); cmGeneratorTarget::ImportInfo const* info = this->GetImportInfo(config);
if (!info) { if (!info) {
@@ -7243,7 +7252,7 @@ const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
} }
cmHeadToLinkInterfaceMap& hm = cmHeadToLinkInterfaceMap& hm =
(usage_requirements_only (interfaceFor == LinkInterfaceFor::Usage
? this->GetHeadToLinkInterfaceUsageRequirementsMap(config) ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
: this->GetHeadToLinkInterfaceMap(config)); : this->GetHeadToLinkInterfaceMap(config));
@@ -7263,7 +7272,7 @@ const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
iface.Multiplicity = info->Multiplicity; iface.Multiplicity = info->Multiplicity;
cmExpandList(info->Languages, iface.Languages); cmExpandList(info->Languages, iface.Languages);
this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config, this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
headTarget, usage_requirements_only, iface); headTarget, interfaceFor, iface);
std::vector<std::string> deps = cmExpandedList(info->SharedDeps); std::vector<std::string> deps = cmExpandedList(info->SharedDeps);
LookupLinkItemScope scope{ this->LocalGenerator }; LookupLinkItemScope scope{ this->LocalGenerator };
for (std::string const& dep : deps) { for (std::string const& dep : deps) {

View File

@@ -237,14 +237,20 @@ public:
cmOptionalLinkInterface& iface, cmOptionalLinkInterface& iface,
const cmGeneratorTarget* head) const; const cmGeneratorTarget* head) const;
enum class LinkInterfaceFor
{
Usage, // Interface for usage requirements excludes $<LINK_ONLY>.
Link, // Interface for linking includes $<LINK_ONLY>.
};
cmLinkInterfaceLibraries const* GetLinkInterfaceLibraries( cmLinkInterfaceLibraries const* GetLinkInterfaceLibraries(
const std::string& config, const cmGeneratorTarget* headTarget, const std::string& config, const cmGeneratorTarget* headTarget,
bool usage_requirements_only) const; LinkInterfaceFor interfaceFor) const;
void ComputeLinkInterfaceLibraries(const std::string& config, void ComputeLinkInterfaceLibraries(const std::string& config,
cmOptionalLinkInterface& iface, cmOptionalLinkInterface& iface,
const cmGeneratorTarget* head, const cmGeneratorTarget* head,
bool usage_requirements_only) const; LinkInterfaceFor interfaceFor) const;
/** Get the library name for an imported interface library. */ /** Get the library name for an imported interface library. */
std::string GetImportedLibName(std::string const& config) const; std::string GetImportedLibName(std::string const& config) const;
@@ -781,7 +787,7 @@ public:
std::string EvaluateInterfaceProperty( std::string EvaluateInterfaceProperty(
std::string const& prop, cmGeneratorExpressionContext* context, std::string const& prop, cmGeneratorExpressionContext* context,
cmGeneratorExpressionDAGChecker* dagCheckerParent, cmGeneratorExpressionDAGChecker* dagCheckerParent,
bool usage_requirements_only = true) const; LinkInterfaceFor interfaceFor = LinkInterfaceFor::Usage) const;
bool HaveInstallTreeRPATH(const std::string& config) const; bool HaveInstallTreeRPATH(const std::string& config) const;
@@ -994,7 +1000,7 @@ private:
cmLinkInterface const* GetImportLinkInterface(const std::string& config, cmLinkInterface const* GetImportLinkInterface(const std::string& config,
const cmGeneratorTarget* head, const cmGeneratorTarget* head,
bool usage_requirements_only, LinkInterfaceFor interfaceFor,
bool secondPass = false) const; bool secondPass = false) const;
using KindedSourcesMapType = std::map<std::string, KindedSources>; using KindedSourcesMapType = std::map<std::string, KindedSources>;
@@ -1008,7 +1014,7 @@ private:
mutable std::unordered_map<std::string, bool> MaybeInterfacePropertyExists; mutable std::unordered_map<std::string, bool> MaybeInterfacePropertyExists;
bool MaybeHaveInterfaceProperty(std::string const& prop, bool MaybeHaveInterfaceProperty(std::string const& prop,
cmGeneratorExpressionContext* context, cmGeneratorExpressionContext* context,
bool usage_requirements_only) const; LinkInterfaceFor interfaceFor) const;
using TargetPropertyEntryVector = using TargetPropertyEntryVector =
std::vector<std::unique_ptr<TargetPropertyEntry>>; std::vector<std::unique_ptr<TargetPropertyEntry>>;
@@ -1042,7 +1048,7 @@ private:
void ExpandLinkItems(std::string const& prop, std::string const& value, void ExpandLinkItems(std::string const& prop, std::string const& value,
std::string const& config, std::string const& config,
const cmGeneratorTarget* headTarget, const cmGeneratorTarget* headTarget,
bool usage_requirements_only, LinkInterfaceFor interfaceFor,
cmLinkInterface& iface) const; cmLinkInterface& iface) const;
struct LookupLinkItemScope struct LookupLinkItemScope

View File

@@ -107,8 +107,8 @@ void cmLinkItemGraphVisitor::GetDependencies(cmGeneratorTarget const& target,
} }
} }
const auto* interfaceLibraries = const auto* interfaceLibraries = target.GetLinkInterfaceLibraries(
target.GetLinkInterfaceLibraries(config, &target, true); config, &target, cmGeneratorTarget::LinkInterfaceFor::Usage);
if (interfaceLibraries != nullptr) { if (interfaceLibraries != nullptr) {
for (auto const& lib : interfaceLibraries->Libraries) { for (auto const& lib : interfaceLibraries->Libraries) {
auto const& name = lib.AsStr(); auto const& name = lib.AsStr();