cmTarget: Make GetLink*Libraries methods safer to use
Split the library lists out of LinkImplementation and LinkInterface into LinkImplementationLibraries and LinkInterfaceLibraries parent classes, respectively. Return these from GetLinkImplementationLibraries and GetLinkInterfaceLibraries, respectively, so that callers cannot access parts of the structures that have not been populated.
This commit is contained in:
parent
6e7e881c57
commit
535fd6ce6d
|
@ -1114,7 +1114,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
|
|||
else if (std::find_if(transBegin, transEnd,
|
||||
cmStrCmp(interfacePropertyName)) != transEnd)
|
||||
{
|
||||
const cmTarget::LinkImplementation *impl
|
||||
const cmTarget::LinkImplementationLibraries *impl
|
||||
= target->GetLinkImplementationLibraries(context->Config);
|
||||
if(impl)
|
||||
{
|
||||
|
|
|
@ -4379,7 +4379,7 @@ bool cmTarget::HaveBuildTreeRPATH(const std::string& config) const
|
|||
{
|
||||
return false;
|
||||
}
|
||||
if(LinkImplementation const* impl =
|
||||
if(LinkImplementationLibraries const* impl =
|
||||
this->GetLinkImplementationLibraries(config))
|
||||
{
|
||||
return !impl->Libraries.empty();
|
||||
|
@ -5935,7 +5935,7 @@ cmTarget::LinkInterface const* cmTarget::GetLinkInterface(
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
cmTarget::LinkInterface const*
|
||||
cmTarget::LinkInterfaceLibraries const*
|
||||
cmTarget::GetLinkInterfaceLibraries(const std::string& config,
|
||||
cmTarget const* head,
|
||||
bool usage_requirements_only) const
|
||||
|
@ -6017,7 +6017,7 @@ void processILibs(const std::string& config,
|
|||
if (item.Target && emitted.insert(item.Target).second)
|
||||
{
|
||||
tgts.push_back(item.Target);
|
||||
if(cmTarget::LinkInterface const* iface =
|
||||
if(cmTarget::LinkInterfaceLibraries const* iface =
|
||||
item.Target->GetLinkInterfaceLibraries(config, headTarget, true))
|
||||
{
|
||||
for(std::vector<cmLinkItem>::const_iterator
|
||||
|
@ -6041,7 +6041,7 @@ cmTarget::GetLinkImplementationClosure(const std::string& config) const
|
|||
this->Internal->CacheLinkImplementationClosureDone[config] = true;
|
||||
std::set<cmTarget const*> emitted;
|
||||
|
||||
cmTarget::LinkImplementation const* impl
|
||||
cmTarget::LinkImplementationLibraries const* impl
|
||||
= this->GetLinkImplementationLibraries(config);
|
||||
|
||||
for(std::vector<cmLinkImplItem>::const_iterator
|
||||
|
@ -6059,7 +6059,7 @@ void cmTarget::GetTransitivePropertyTargets(const std::string& config,
|
|||
cmTarget const* headTarget,
|
||||
std::vector<cmTarget const*> &tgts) const
|
||||
{
|
||||
if(cmTarget::LinkInterface const* iface =
|
||||
if(cmTarget::LinkInterfaceLibraries const* iface =
|
||||
this->GetLinkInterfaceLibraries(config, headTarget, true))
|
||||
{
|
||||
for(std::vector<cmLinkItem>::const_iterator it = iface->Libraries.begin();
|
||||
|
@ -6177,7 +6177,7 @@ cmTargetInternals::ComputeLinkInterfaceLibraries(
|
|||
// to the link implementation.
|
||||
{
|
||||
// The link implementation is the default link interface.
|
||||
cmTarget::LinkImplementation const* impl =
|
||||
cmTarget::LinkImplementationLibraries const* impl =
|
||||
thisTarget->GetLinkImplementationLibrariesInternal(config, headTarget);
|
||||
std::copy(impl->Libraries.begin(), impl->Libraries.end(),
|
||||
std::back_inserter(iface.Libraries));
|
||||
|
@ -6294,7 +6294,7 @@ void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget,
|
|||
|| thisTarget->PolicyStatusCMP0022 == cmPolicies::OLD)
|
||||
{
|
||||
// The link implementation is the default link interface.
|
||||
cmTarget::LinkImplementation const*
|
||||
cmTarget::LinkImplementationLibraries const*
|
||||
impl = thisTarget->GetLinkImplementationLibrariesInternal(config,
|
||||
headTarget);
|
||||
iface.ImplementationIsInterface = true;
|
||||
|
@ -6345,7 +6345,7 @@ void cmTargetInternals::AddInterfaceEntries(
|
|||
cmTarget const* thisTarget, std::string const& config,
|
||||
std::string const& prop, std::vector<TargetPropertyEntry*>& entries)
|
||||
{
|
||||
if(cmTarget::LinkImplementation const* impl =
|
||||
if(cmTarget::LinkImplementationLibraries const* impl =
|
||||
thisTarget->GetLinkImplementationLibraries(config))
|
||||
{
|
||||
for (std::vector<cmLinkImplItem>::const_iterator
|
||||
|
@ -6383,7 +6383,7 @@ cmTarget::GetLinkImplementation(const std::string& config) const
|
|||
if(!impl.LibrariesDone)
|
||||
{
|
||||
impl.LibrariesDone = true;
|
||||
this->ComputeLinkImplementation(config, impl, this);
|
||||
this->ComputeLinkImplementationLibraries(config, impl, this);
|
||||
}
|
||||
if(!impl.LanguagesDone)
|
||||
{
|
||||
|
@ -6394,14 +6394,14 @@ cmTarget::GetLinkImplementation(const std::string& config) const
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
cmTarget::LinkImplementation const*
|
||||
cmTarget::LinkImplementationLibraries const*
|
||||
cmTarget::GetLinkImplementationLibraries(const std::string& config) const
|
||||
{
|
||||
return this->GetLinkImplementationLibrariesInternal(config, this);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
cmTarget::LinkImplementation const*
|
||||
cmTarget::LinkImplementationLibraries const*
|
||||
cmTarget::GetLinkImplementationLibrariesInternal(const std::string& config,
|
||||
cmTarget const* head) const
|
||||
{
|
||||
|
@ -6418,13 +6418,14 @@ cmTarget::GetLinkImplementationLibrariesInternal(const std::string& config,
|
|||
if(!impl.LibrariesDone)
|
||||
{
|
||||
impl.LibrariesDone = true;
|
||||
this->ComputeLinkImplementation(config, impl, head);
|
||||
this->ComputeLinkImplementationLibraries(config, impl, head);
|
||||
}
|
||||
return &impl;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmTarget::ComputeLinkImplementation(const std::string& config,
|
||||
void
|
||||
cmTarget::ComputeLinkImplementationLibraries(const std::string& config,
|
||||
LinkImplementation& impl,
|
||||
cmTarget const* head) const
|
||||
{
|
||||
|
|
|
@ -262,14 +262,16 @@ public:
|
|||
|
||||
/** The link interface specifies transitive library dependencies and
|
||||
other information needed by targets that link to this target. */
|
||||
struct LinkInterface
|
||||
struct LinkInterfaceLibraries
|
||||
{
|
||||
// Libraries listed in the interface.
|
||||
std::vector<cmLinkItem> Libraries;
|
||||
};
|
||||
struct LinkInterface: public LinkInterfaceLibraries
|
||||
{
|
||||
// Languages whose runtime libraries must be linked.
|
||||
std::vector<std::string> Languages;
|
||||
|
||||
// Libraries listed in the interface.
|
||||
std::vector<cmLinkItem> Libraries;
|
||||
|
||||
// Shared library dependencies needed for linking on some platforms.
|
||||
std::vector<cmLinkItem> SharedDeps;
|
||||
|
||||
|
@ -290,22 +292,21 @@ public:
|
|||
if the target cannot be linked. */
|
||||
LinkInterface const* GetLinkInterface(const std::string& config,
|
||||
cmTarget const* headTarget) const;
|
||||
LinkInterface const* GetLinkInterfaceLibraries(const std::string& config,
|
||||
LinkInterfaceLibraries const*
|
||||
GetLinkInterfaceLibraries(const std::string& config,
|
||||
cmTarget const* headTarget,
|
||||
bool usage_requirements_only) const;
|
||||
void GetTransitivePropertyTargets(const std::string& config,
|
||||
cmTarget const* headTarget,
|
||||
std::vector<cmTarget const*> &libs) const;
|
||||
|
||||
std::vector<cmTarget const*> const&
|
||||
GetLinkImplementationClosure(const std::string& config) const;
|
||||
|
||||
/** The link implementation specifies the direct library
|
||||
dependencies needed by the object files of the target. */
|
||||
struct LinkImplementation
|
||||
struct LinkImplementationLibraries
|
||||
{
|
||||
// Languages whose runtime libraries must be linked.
|
||||
std::vector<std::string> Languages;
|
||||
|
||||
// Libraries linked directly in this configuration.
|
||||
std::vector<cmLinkImplItem> Libraries;
|
||||
|
||||
|
@ -313,10 +314,15 @@ public:
|
|||
// Needed only for OLD behavior of CMP0003.
|
||||
std::vector<cmLinkItem> WrongConfigLibraries;
|
||||
};
|
||||
struct LinkImplementation: public LinkImplementationLibraries
|
||||
{
|
||||
// Languages whose runtime libraries must be linked.
|
||||
std::vector<std::string> Languages;
|
||||
};
|
||||
LinkImplementation const*
|
||||
GetLinkImplementation(const std::string& config) const;
|
||||
|
||||
LinkImplementation const*
|
||||
LinkImplementationLibraries const*
|
||||
GetLinkImplementationLibraries(const std::string& config) const;
|
||||
|
||||
/** Link information from the transitive closure of the link
|
||||
|
@ -778,10 +784,10 @@ private:
|
|||
GetImportLinkInterface(const std::string& config, cmTarget const* head,
|
||||
bool usage_requirements_only) const;
|
||||
|
||||
LinkImplementation const*
|
||||
LinkImplementationLibraries const*
|
||||
GetLinkImplementationLibrariesInternal(const std::string& config,
|
||||
cmTarget const* head) const;
|
||||
void ComputeLinkImplementation(const std::string& config,
|
||||
void ComputeLinkImplementationLibraries(const std::string& config,
|
||||
LinkImplementation& impl,
|
||||
cmTarget const* head) const;
|
||||
void ComputeLinkImplementationLanguages(const std::string& config,
|
||||
|
|
Loading…
Reference in New Issue