cmGeneratorTarget: Move ComputeLinkInterface from cmTarget.

This commit is contained in:
Stephen Kelly 2015-08-26 19:36:13 +02:00
parent d67584ccc4
commit f8ca51a054
2 changed files with 57 additions and 61 deletions

View File

@ -91,16 +91,6 @@ public:
// The backtrace when the target was created. // The backtrace when the target was created.
cmListFileBacktrace Backtrace; cmListFileBacktrace Backtrace;
void ComputeLinkInterface(cmTarget const* thisTarget,
const std::string& config,
cmOptionalLinkInterface& iface,
cmTarget const* head) const;
void ComputeLinkInterfaceLibraries(cmTarget const* thisTarget,
const std::string& config,
cmOptionalLinkInterface &iface,
cmTarget const* head,
bool usage_requirements_only);
struct HeadToLinkInterfaceMap: struct HeadToLinkInterfaceMap:
public std::map<cmTarget const*, cmOptionalLinkInterface> {}; public std::map<cmTarget const*, cmOptionalLinkInterface> {};
typedef std::map<std::string, HeadToLinkInterfaceMap> typedef std::map<std::string, HeadToLinkInterfaceMap>
@ -4153,15 +4143,15 @@ cmLinkInterface const* cmTarget::GetLinkInterface(const std::string& config,
if(!iface.LibrariesDone) if(!iface.LibrariesDone)
{ {
iface.LibrariesDone = true; iface.LibrariesDone = true;
this->Internal->ComputeLinkInterfaceLibraries( this->ComputeLinkInterfaceLibraries(
this, config, iface, head, false); config, iface, head, false);
} }
if(!iface.AllDone) if(!iface.AllDone)
{ {
iface.AllDone = true; iface.AllDone = true;
if(iface.Exists) if(iface.Exists)
{ {
this->Internal->ComputeLinkInterface(this, config, iface, head); this->ComputeLinkInterface(config, iface, head);
} }
} }
@ -4206,8 +4196,8 @@ cmTarget::GetLinkInterfaceLibraries(const std::string& config,
if(!iface.LibrariesDone) if(!iface.LibrariesDone)
{ {
iface.LibrariesDone = true; iface.LibrariesDone = true;
this->Internal->ComputeLinkInterfaceLibraries( this->ComputeLinkInterfaceLibraries(
this, config, iface, head, usage_requirements_only); config, iface, head, usage_requirements_only);
} }
return iface.Exists? &iface : 0; return iface.Exists? &iface : 0;
@ -4258,12 +4248,11 @@ cmTarget::GetImportLinkInterface(const std::string& config,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void void
cmTargetInternals::ComputeLinkInterfaceLibraries( cmTarget::ComputeLinkInterfaceLibraries(
cmTarget const* thisTarget,
const std::string& config, const std::string& config,
cmOptionalLinkInterface& iface, cmOptionalLinkInterface& iface,
cmTarget const* headTarget, cmTarget const* headTarget,
bool usage_requirements_only) bool usage_requirements_only) const
{ {
// Construct the property name suffix for this configuration. // Construct the property name suffix for this configuration.
std::string suffix = "_"; std::string suffix = "_";
@ -4280,15 +4269,15 @@ cmTargetInternals::ComputeLinkInterfaceLibraries(
// libraries and executables that export symbols. // libraries and executables that export symbols.
const char* explicitLibraries = 0; const char* explicitLibraries = 0;
std::string linkIfaceProp; std::string linkIfaceProp;
if(thisTarget->GetPolicyStatusCMP0022() != cmPolicies::OLD && if(this->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
thisTarget->GetPolicyStatusCMP0022() != cmPolicies::WARN) this->GetPolicyStatusCMP0022() != cmPolicies::WARN)
{ {
// CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
linkIfaceProp = "INTERFACE_LINK_LIBRARIES"; linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
explicitLibraries = thisTarget->GetProperty(linkIfaceProp); explicitLibraries = this->GetProperty(linkIfaceProp);
} }
else if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY || else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
thisTarget->IsExecutableWithExports()) this->IsExecutableWithExports())
{ {
// CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
// shared lib or executable. // shared lib or executable.
@ -4296,30 +4285,30 @@ cmTargetInternals::ComputeLinkInterfaceLibraries(
// Lookup the per-configuration property. // Lookup the per-configuration property.
linkIfaceProp = "LINK_INTERFACE_LIBRARIES"; linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
linkIfaceProp += suffix; linkIfaceProp += suffix;
explicitLibraries = thisTarget->GetProperty(linkIfaceProp); explicitLibraries = this->GetProperty(linkIfaceProp);
// If not set, try the generic property. // If not set, try the generic property.
if(!explicitLibraries) if(!explicitLibraries)
{ {
linkIfaceProp = "LINK_INTERFACE_LIBRARIES"; linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
explicitLibraries = thisTarget->GetProperty(linkIfaceProp); explicitLibraries = this->GetProperty(linkIfaceProp);
} }
} }
if(explicitLibraries && if(explicitLibraries &&
thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN && this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
!this->PolicyWarnedCMP0022) !this->Internal->PolicyWarnedCMP0022)
{ {
// Compare the explicitly set old link interface properties to the // Compare the explicitly set old link interface properties to the
// preferred new link interface property one and warn if different. // preferred new link interface property one and warn if different.
const char* newExplicitLibraries = const char* newExplicitLibraries =
thisTarget->GetProperty("INTERFACE_LINK_LIBRARIES"); this->GetProperty("INTERFACE_LINK_LIBRARIES");
if (newExplicitLibraries if (newExplicitLibraries
&& strcmp(newExplicitLibraries, explicitLibraries) != 0) && strcmp(newExplicitLibraries, explicitLibraries) != 0)
{ {
std::ostringstream w; std::ostringstream w;
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n" w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
"Target \"" << thisTarget->GetName() << "\" has an " "Target \"" << this->GetName() << "\" has an "
"INTERFACE_LINK_LIBRARIES property which differs from its " << "INTERFACE_LINK_LIBRARIES property which differs from its " <<
linkIfaceProp << " properties." linkIfaceProp << " properties."
"\n" "\n"
@ -4327,16 +4316,16 @@ cmTargetInternals::ComputeLinkInterfaceLibraries(
" " << newExplicitLibraries << "\n" << " " << newExplicitLibraries << "\n" <<
linkIfaceProp << ":\n" linkIfaceProp << ":\n"
" " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n"; " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
this->PolicyWarnedCMP0022 = true; this->Internal->PolicyWarnedCMP0022 = true;
} }
} }
// There is no implicit link interface for executables or modules // There is no implicit link interface for executables or modules
// so if none was explicitly set then there is no link interface. // so if none was explicitly set then there is no link interface.
if(!explicitLibraries && if(!explicitLibraries &&
(thisTarget->GetType() == cmTarget::EXECUTABLE || (this->GetType() == cmTarget::EXECUTABLE ||
(thisTarget->GetType() == cmTarget::MODULE_LIBRARY))) (this->GetType() == cmTarget::MODULE_LIBRARY)))
{ {
return; return;
} }
@ -4346,13 +4335,13 @@ cmTargetInternals::ComputeLinkInterfaceLibraries(
if(explicitLibraries) if(explicitLibraries)
{ {
// The interface libraries have been explicitly set. // The interface libraries have been explicitly set.
thisTarget->ExpandLinkItems(linkIfaceProp, explicitLibraries, config, this->ExpandLinkItems(linkIfaceProp, explicitLibraries, config,
headTarget, usage_requirements_only, headTarget, usage_requirements_only,
iface.Libraries, iface.Libraries,
iface.HadHeadSensitiveCondition); iface.HadHeadSensitiveCondition);
} }
else if (thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN
|| thisTarget->GetPolicyStatusCMP0022() == cmPolicies::OLD) || this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
// If CMP0022 is NEW then the plain tll signature sets the // If CMP0022 is NEW then the plain tll signature sets the
// INTERFACE_LINK_LIBRARIES, so if we get here then the project // INTERFACE_LINK_LIBRARIES, so if we get here then the project
// cleared the property explicitly and we should not fall back // cleared the property explicitly and we should not fall back
@ -4360,20 +4349,20 @@ cmTargetInternals::ComputeLinkInterfaceLibraries(
{ {
// The link implementation is the default link interface. // The link implementation is the default link interface.
cmLinkImplementationLibraries const* impl = cmLinkImplementationLibraries const* impl =
thisTarget->GetLinkImplementationLibrariesInternal(config, headTarget); this->GetLinkImplementationLibrariesInternal(config, headTarget);
iface.Libraries.insert(iface.Libraries.end(), iface.Libraries.insert(iface.Libraries.end(),
impl->Libraries.begin(), impl->Libraries.end()); impl->Libraries.begin(), impl->Libraries.end());
if(thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN && if(this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
!this->PolicyWarnedCMP0022 && !usage_requirements_only) !this->Internal->PolicyWarnedCMP0022 && !usage_requirements_only)
{ {
// 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.
std::vector<cmLinkItem> ifaceLibs; std::vector<cmLinkItem> ifaceLibs;
static const std::string newProp = "INTERFACE_LINK_LIBRARIES"; static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
if(const char* newExplicitLibraries = thisTarget->GetProperty(newProp)) if(const char* newExplicitLibraries = this->GetProperty(newProp))
{ {
bool hadHeadSensitiveConditionDummy = false; bool hadHeadSensitiveConditionDummy = false;
thisTarget->ExpandLinkItems(newProp, newExplicitLibraries, config, this->ExpandLinkItems(newProp, newExplicitLibraries, config,
headTarget, usage_requirements_only, headTarget, usage_requirements_only,
ifaceLibs, hadHeadSensitiveConditionDummy); ifaceLibs, hadHeadSensitiveConditionDummy);
} }
@ -4388,7 +4377,7 @@ cmTargetInternals::ComputeLinkInterfaceLibraries(
std::ostringstream w; std::ostringstream w;
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n" w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
"Target \"" << thisTarget->GetName() << "\" has an " "Target \"" << this->GetName() << "\" has an "
"INTERFACE_LINK_LIBRARIES property. " "INTERFACE_LINK_LIBRARIES property. "
"This should be preferred as the source of the link interface " "This should be preferred as the source of the link interface "
"for this library but because CMP0022 is not set CMake is " "for this library but because CMP0022 is not set CMake is "
@ -4399,24 +4388,23 @@ cmTargetInternals::ComputeLinkInterfaceLibraries(
" " << newLibraries << "\n" " " << newLibraries << "\n"
"Link implementation:\n" "Link implementation:\n"
" " << oldLibraries << "\n"; " " << oldLibraries << "\n";
thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
this->PolicyWarnedCMP0022 = true; this->Internal->PolicyWarnedCMP0022 = true;
} }
} }
} }
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget, void cmTarget::ComputeLinkInterface(const std::string& config,
const std::string& config,
cmOptionalLinkInterface &iface, cmOptionalLinkInterface &iface,
cmTarget const* headTarget) const cmTarget const* headTarget) const
{ {
if(iface.ExplicitLibraries) if(iface.ExplicitLibraries)
{ {
if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY if(this->GetType() == cmTarget::SHARED_LIBRARY
|| thisTarget->GetType() == cmTarget::STATIC_LIBRARY || this->GetType() == cmTarget::STATIC_LIBRARY
|| thisTarget->GetType() == cmTarget::INTERFACE_LIBRARY) || this->GetType() == cmTarget::INTERFACE_LIBRARY)
{ {
// Shared libraries may have runtime implementation dependencies // Shared libraries may have runtime implementation dependencies
// on other shared libraries that are not in the interface. // on other shared libraries that are not in the interface.
@ -4426,10 +4414,10 @@ void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget,
{ {
emitted.insert(*li); emitted.insert(*li);
} }
if (thisTarget->GetType() != cmTarget::INTERFACE_LIBRARY) if (this->GetType() != cmTarget::INTERFACE_LIBRARY)
{ {
cmTarget::LinkImplementation const* impl = cmTarget::LinkImplementation const* impl =
thisTarget->GetLinkImplementation(config); this->GetLinkImplementation(config);
for(std::vector<cmLinkImplItem>::const_iterator for(std::vector<cmLinkImplItem>::const_iterator
li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li) li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
{ {
@ -4455,28 +4443,28 @@ void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget,
} }
} }
} }
else if (thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN
|| thisTarget->GetPolicyStatusCMP0022() == cmPolicies::OLD) || this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
{ {
// The link implementation is the default link interface. // The link implementation is the default link interface.
cmLinkImplementationLibraries const* cmLinkImplementationLibraries const*
impl = thisTarget->GetLinkImplementationLibrariesInternal(config, impl = this->GetLinkImplementationLibrariesInternal(config,
headTarget); headTarget);
iface.ImplementationIsInterface = true; iface.ImplementationIsInterface = true;
iface.WrongConfigLibraries = impl->WrongConfigLibraries; iface.WrongConfigLibraries = impl->WrongConfigLibraries;
} }
if(thisTarget->LinkLanguagePropagatesToDependents()) if(this->LinkLanguagePropagatesToDependents())
{ {
// Targets using this archive need its language runtime libraries. // Targets using this archive need its language runtime libraries.
if(cmTarget::LinkImplementation const* impl = if(cmTarget::LinkImplementation const* impl =
thisTarget->GetLinkImplementation(config)) this->GetLinkImplementation(config))
{ {
iface.Languages = impl->Languages; iface.Languages = impl->Languages;
} }
} }
if(thisTarget->GetType() == cmTarget::STATIC_LIBRARY) if(this->GetType() == cmTarget::STATIC_LIBRARY)
{ {
// Construct the property name suffix for this configuration. // Construct the property name suffix for this configuration.
std::string suffix = "_"; std::string suffix = "_";
@ -4493,12 +4481,12 @@ void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget,
// dependencies? // dependencies?
std::string propName = "LINK_INTERFACE_MULTIPLICITY"; std::string propName = "LINK_INTERFACE_MULTIPLICITY";
propName += suffix; propName += suffix;
if(const char* config_reps = thisTarget->GetProperty(propName)) if(const char* config_reps = this->GetProperty(propName))
{ {
sscanf(config_reps, "%u", &iface.Multiplicity); sscanf(config_reps, "%u", &iface.Multiplicity);
} }
else if(const char* reps = else if(const char* reps =
thisTarget->GetProperty("LINK_INTERFACE_MULTIPLICITY")) this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
{ {
sscanf(reps, "%u", &iface.Multiplicity); sscanf(reps, "%u", &iface.Multiplicity);
} }

View File

@ -233,6 +233,14 @@ public:
void GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const; void GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const;
void ComputeLinkInterface(const std::string& config,
cmOptionalLinkInterface& iface,
cmTarget const* head) const;
void ComputeLinkInterfaceLibraries(const std::string& config,
cmOptionalLinkInterface &iface,
cmTarget const* head,
bool usage_requirements_only) const;
/** Get the link interface for the given configuration. Returns 0 /** Get the link interface for the given configuration. Returns 0
if the target cannot be linked. */ if the target cannot be linked. */
cmLinkInterface const* GetLinkInterface(const std::string& config, cmLinkInterface const* GetLinkInterface(const std::string& config,