cmTarget: Drop 'head' target from GetImportInfo

Move generator expression evaluation for imported library lists out of
GetImportInfo and into a new GetImportLinkInterface helper.  This avoids
duplicating the computation and storage of all imported target info just
because some of it is parameterized on the 'head' target.
This commit is contained in:
Brad King 2014-06-16 10:36:21 -04:00
parent 0dc9e88d76
commit 6f0951af01
2 changed files with 69 additions and 40 deletions

View File

@ -64,11 +64,16 @@ struct cmTarget::OutputInfo
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
struct cmTarget::ImportInfo struct cmTarget::ImportInfo
{ {
ImportInfo(): NoSOName(false), Multiplicity(0) {}
bool NoSOName; bool NoSOName;
int Multiplicity;
std::string Location; std::string Location;
std::string SOName; std::string SOName;
std::string ImportLibrary; std::string ImportLibrary;
cmTarget::LinkInterface LinkInterface; std::string Languages;
std::string Libraries;
std::string LibrariesProp;
std::string SharedDeps;
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -121,11 +126,14 @@ public:
LinkInterfaceMapType LinkInterfaceMap; LinkInterfaceMapType LinkInterfaceMap;
bool PolicyWarnedCMP0022; bool PolicyWarnedCMP0022;
typedef std::map<TargetConfigPair, cmTarget::LinkInterface>
ImportLinkInterfaceMapType;
ImportLinkInterfaceMapType ImportLinkInterfaceMap;
typedef std::map<std::string, cmTarget::OutputInfo> OutputInfoMapType; typedef std::map<std::string, cmTarget::OutputInfo> OutputInfoMapType;
OutputInfoMapType OutputInfoMap; OutputInfoMapType OutputInfoMap;
typedef std::map<TargetConfigPair, cmTarget::ImportInfo> typedef std::map<std::string, cmTarget::ImportInfo> ImportInfoMapType;
ImportInfoMapType;
ImportInfoMapType ImportInfoMap; ImportInfoMapType ImportInfoMap;
typedef std::map<std::string, cmTarget::CompileInfo> CompileInfoMapType; typedef std::map<std::string, cmTarget::CompileInfo> CompileInfoMapType;
@ -481,6 +489,7 @@ void cmTarget::ClearLinkMaps()
this->LinkImplementationLanguageIsContextDependent = true; this->LinkImplementationLanguageIsContextDependent = true;
this->Internal->LinkImplMap.clear(); this->Internal->LinkImplMap.clear();
this->Internal->LinkInterfaceMap.clear(); this->Internal->LinkInterfaceMap.clear();
this->Internal->ImportLinkInterfaceMap.clear();
this->Internal->LinkClosureMap.clear(); this->Internal->LinkClosureMap.clear();
for (cmTargetLinkInformationMap::const_iterator it for (cmTargetLinkInformationMap::const_iterator it
= this->LinkInformation.begin(); = this->LinkInformation.begin();
@ -3853,7 +3862,7 @@ std::string cmTarget::GetSOName(const std::string& config) const
if(this->IsImported()) if(this->IsImported())
{ {
// Lookup the imported soname. // Lookup the imported soname.
if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this)) if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
{ {
if(info->NoSOName) if(info->NoSOName)
{ {
@ -3921,7 +3930,7 @@ bool cmTarget::HasMacOSXRpathInstallNameDir(const std::string& config) const
else else
{ {
// Lookup the imported soname. // Lookup the imported soname.
if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this)) if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
{ {
if(!info->NoSOName && !info->SOName.empty()) if(!info->NoSOName && !info->SOName.empty())
{ {
@ -4007,7 +4016,7 @@ bool cmTarget::IsImportedSharedLibWithoutSOName(
{ {
if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY) if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
{ {
if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this)) if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
{ {
return info->NoSOName; return info->NoSOName;
} }
@ -4131,7 +4140,7 @@ std::string
cmTarget::ImportedGetFullPath(const std::string& config, bool implib) const cmTarget::ImportedGetFullPath(const std::string& config, bool implib) const
{ {
std::string result; std::string result;
if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this)) if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
{ {
result = implib? info->ImportLibrary : info->Location; result = implib? info->ImportLibrary : info->Location;
} }
@ -5670,8 +5679,7 @@ bool cmTarget::IsChrpathUsed(const std::string& config) const
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmTarget::ImportInfo const* cmTarget::ImportInfo const*
cmTarget::GetImportInfo(const std::string& config, cmTarget::GetImportInfo(const std::string& config) const
cmTarget const* headTarget) const
{ {
// There is no imported information for non-imported targets. // There is no imported information for non-imported targets.
if(!this->IsImported()) if(!this->IsImported())
@ -5690,16 +5698,15 @@ cmTarget::GetImportInfo(const std::string& config,
{ {
config_upper = "NOCONFIG"; config_upper = "NOCONFIG";
} }
TargetConfigPair key(headTarget, config_upper);
typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType; typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
ImportInfoMapType::const_iterator i = ImportInfoMapType::const_iterator i =
this->Internal->ImportInfoMap.find(key); this->Internal->ImportInfoMap.find(config_upper);
if(i == this->Internal->ImportInfoMap.end()) if(i == this->Internal->ImportInfoMap.end())
{ {
ImportInfo info; ImportInfo info;
this->ComputeImportInfo(config_upper, info, headTarget); this->ComputeImportInfo(config_upper, info);
ImportInfoMapType::value_type entry(key, info); ImportInfoMapType::value_type entry(config_upper, info);
i = this->Internal->ImportInfoMap.insert(entry).first; i = this->Internal->ImportInfoMap.insert(entry).first;
} }
@ -5851,8 +5858,7 @@ bool cmTarget::GetMappedConfig(std::string const& desired_config,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmTarget::ComputeImportInfo(std::string const& desired_config, void cmTarget::ComputeImportInfo(std::string const& desired_config,
ImportInfo& info, ImportInfo& info) const
cmTarget const* headTarget) const
{ {
// This method finds information about an imported target from its // This method finds information about an imported target from its
// properties. The "IMPORTED_" namespace is reserved for properties // properties. The "IMPORTED_" namespace is reserved for properties
@ -5891,8 +5897,8 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config,
} }
if(propertyLibs) if(propertyLibs)
{ {
this->ExpandLinkItems(linkProp, propertyLibs, desired_config, info.LibrariesProp = linkProp;
headTarget, info.LinkInterface.Libraries); info.Libraries = propertyLibs;
} }
} }
if(this->GetType() == INTERFACE_LIBRARY) if(this->GetType() == INTERFACE_LIBRARY)
@ -5978,13 +5984,12 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config,
linkProp += suffix; linkProp += suffix;
if(const char* config_libs = this->GetProperty(linkProp)) if(const char* config_libs = this->GetProperty(linkProp))
{ {
cmSystemTools::ExpandListArgument(config_libs, info.SharedDeps = config_libs;
info.LinkInterface.SharedDeps);
} }
else if(const char* libs = else if(const char* libs =
this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES")) this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
{ {
cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps); info.SharedDeps = libs;
} }
} }
@ -5995,14 +6000,12 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config,
linkProp += suffix; linkProp += suffix;
if(const char* config_libs = this->GetProperty(linkProp)) if(const char* config_libs = this->GetProperty(linkProp))
{ {
cmSystemTools::ExpandListArgument(config_libs, info.Languages = config_libs;
info.LinkInterface.Languages);
} }
else if(const char* libs = else if(const char* libs =
this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES")) this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
{ {
cmSystemTools::ExpandListArgument(libs, info.Languages = libs;
info.LinkInterface.Languages);
} }
} }
@ -6013,12 +6016,12 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config,
linkProp += suffix; linkProp += suffix;
if(const char* config_reps = this->GetProperty(linkProp)) if(const char* config_reps = this->GetProperty(linkProp))
{ {
sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity); sscanf(config_reps, "%u", &info.Multiplicity);
} }
else if(const char* reps = else if(const char* reps =
this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY")) this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
{ {
sscanf(reps, "%u", &info.LinkInterface.Multiplicity); sscanf(reps, "%u", &info.Multiplicity);
} }
} }
} }
@ -6031,11 +6034,7 @@ cmTarget::LinkInterface const* cmTarget::GetLinkInterface(
// Imported targets have their own link interface. // Imported targets have their own link interface.
if(this->IsImported()) if(this->IsImported())
{ {
if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, head)) return this->GetImportLinkInterface(config, head);
{
return &info->LinkInterface;
}
return 0;
} }
// Link interfaces are not supported for executables that do not // Link interfaces are not supported for executables that do not
@ -6084,11 +6083,7 @@ cmTarget::GetLinkInterfaceLibraries(const std::string& config,
// Imported targets have their own link interface. // Imported targets have their own link interface.
if(this->IsImported()) if(this->IsImported())
{ {
if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, head)) return this->GetImportLinkInterface(config, head);
{
return &info->LinkInterface;
}
return 0;
} }
// Link interfaces are not supported for executables that do not // Link interfaces are not supported for executables that do not
@ -6121,6 +6116,37 @@ cmTarget::GetLinkInterfaceLibraries(const std::string& config,
return i->second.Exists ? &i->second : 0; return i->second.Exists ? &i->second : 0;
} }
//----------------------------------------------------------------------------
cmTarget::LinkInterface const*
cmTarget::GetImportLinkInterface(const std::string& config,
cmTarget const* headTarget) const
{
cmTarget::ImportInfo const* info = this->GetImportInfo(config);
if(!info)
{
return 0;
}
TargetConfigPair key(headTarget, cmSystemTools::UpperCase(config));
cmTargetInternals::ImportLinkInterfaceMapType::iterator i =
this->Internal->ImportLinkInterfaceMap.find(key);
if(i == this->Internal->ImportLinkInterfaceMap.end())
{
LinkInterface iface;
iface.Multiplicity = info->Multiplicity;
cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
headTarget, iface.Libraries);
cmSystemTools::ExpandListArgument(info->SharedDeps, iface.SharedDeps);
cmTargetInternals::ImportLinkInterfaceMapType::value_type
entry(key, iface);
i = this->Internal->ImportLinkInterfaceMap.insert(entry).first;
}
return &i->second;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void processILibs(const std::string& config, void processILibs(const std::string& config,
cmTarget const* headTarget, cmTarget const* headTarget,

View File

@ -730,10 +730,9 @@ private:
// Cache import information from properties for each configuration. // Cache import information from properties for each configuration.
struct ImportInfo; struct ImportInfo;
ImportInfo const* GetImportInfo(const std::string& config, ImportInfo const* GetImportInfo(const std::string& config) const;
cmTarget const* workingTarget) const; void ComputeImportInfo(std::string const& desired_config,
void ComputeImportInfo(std::string const& desired_config, ImportInfo& info, ImportInfo& info) const;
cmTarget const* head) const;
// Cache target compile paths for each configuration. // Cache target compile paths for each configuration.
struct CompileInfo; struct CompileInfo;
@ -743,6 +742,10 @@ private:
void CheckPropertyCompatibility(cmComputeLinkInformation *info, void CheckPropertyCompatibility(cmComputeLinkInformation *info,
const std::string& config) const; const std::string& config) const;
LinkInterface const*
GetImportLinkInterface(const std::string& config,
cmTarget const* head) const;
const char* ComputeLinkInterfaceLibraries(const std::string& config, const char* ComputeLinkInterfaceLibraries(const std::string& config,
LinkInterface& iface, LinkInterface& iface,
cmTarget const* head, cmTarget const* head,