INTERFACE_LIBRARY: Avoid codepaths which set unneeded properties.

As an INTERFACE_LIBRARY has no direct link dependencies, we can
short-circuit in cmGeneratorExpressionEvaluator and
in cmGlobalGenerator::CheckLocalGenerators.

As they do not generate any output directly, any generate- or install-
related code acn also be short-circuited. Many of the local generators
already do this.

Because only INTERFACE related properties make sense on INTERFACE_LIBRARY
targets, avoid setting other properties, for example via defaults.
This commit is contained in:
Stephen Kelly 2013-11-20 12:44:04 +01:00
parent 9f095b7416
commit 0bfcb450e6
14 changed files with 154 additions and 82 deletions

View File

@ -237,7 +237,15 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
it != configs.end(); ++it)
{
std::vector<std::string> tlibs;
if (depender->GetType() == cmTarget::INTERFACE_LIBRARY)
{
// For INTERFACE_LIBRARY depend on the interface instead.
depender->GetInterfaceLinkLibraries(it->c_str(), tlibs, depender);
}
else
{
depender->GetDirectLinkLibraries(it->c_str(), tlibs, depender);
}
// A target should not depend on itself.
emitted.insert(depender->GetName());
for(std::vector<std::string>::const_iterator lib = tlibs.begin();

View File

@ -387,15 +387,12 @@ void getCompatibleInterfaceProperties(cmTarget *target,
cmComputeLinkInformation *info = target->GetLinkInformation(config);
if (!info)
{
if (target->GetType() != cmTarget::INTERFACE_LIBRARY)
{
cmMakefile* mf = target->GetMakefile();
cmOStringStream e;
e << "Exporting the target \"" << target->GetName() << "\" is not "
"allowed since its linker language cannot be determined";
mf->IssueMessage(cmake::FATAL_ERROR, e.str());
}
return;
}
@ -447,6 +444,8 @@ void cmExportFileGenerator::PopulateCompatibleInterfaceProperties(
getPropertyContents(target, "COMPATIBLE_INTERFACE_NUMBER_MAX",
ifaceProperties);
if (target->GetType() != cmTarget::INTERFACE_LIBRARY)
{
getCompatibleInterfaceProperties(target, ifaceProperties, 0);
std::vector<std::string> configNames;
@ -457,6 +456,7 @@ void cmExportFileGenerator::PopulateCompatibleInterfaceProperties(
{
getCompatibleInterfaceProperties(target, ifaceProperties, ci->c_str());
}
}
for (std::set<std::string>::const_iterator it = ifaceProperties.begin();
it != ifaceProperties.end(); ++it)

View File

@ -954,7 +954,8 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
if (!prop)
{
if (target->IsImported())
if (target->IsImported()
|| target->GetType() == cmTarget::INTERFACE_LIBRARY)
{
return linkedTargetsContent;
}

View File

@ -1309,6 +1309,11 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo()
{
cmTarget* t = &ti->second;
if (t->GetType() == cmTarget::INTERFACE_LIBRARY)
{
continue;
}
t->AppendBuildInterfaceIncludes();
for (std::vector<cmValueWithOrigin>::const_iterator it
@ -1461,6 +1466,10 @@ void cmGlobalGenerator::CheckLocalGenerators()
for (cmTargets::iterator l = targets.begin();
l != targets.end(); l++)
{
if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
{
continue;
}
const cmTarget::LinkLibraryVectorType& libs =
l->second.GetOriginalLinkLibraries();
for(cmTarget::LinkLibraryVectorType::const_iterator lib = libs.begin();

View File

@ -327,6 +327,10 @@ void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
projectTargets.begin(); tt != projectTargets.end(); ++tt)
{
cmTarget* target = *tt;
if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
{
continue;
}
const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
if(expath)
{
@ -364,6 +368,10 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
projectTargets.begin(); tt != projectTargets.end(); ++tt)
{
cmTarget* target = *tt;
if(target->GetType() == cmTarget::INTERFACE_LIBRARY)
{
continue;
}
bool written = false;
// handle external vc project files

View File

@ -442,7 +442,8 @@ bool cmGlobalVisualStudio8Generator::NeedLinkLibraryDependencies(
{
if(cmTarget* depTarget = this->FindTarget(0, ui->c_str()))
{
if(depTarget->GetProperty("EXTERNAL_MSPROJECT"))
if(depTarget->GetType() != cmTarget::INTERFACE_LIBRARY
&& depTarget->GetProperty("EXTERNAL_MSPROJECT"))
{
// This utility dependency names an external .vcproj target.
// We use LinkLibraryDependencies="true" to link to it without

View File

@ -645,7 +645,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// generators for them.
bool createInstallGeneratorsForTargetFileSets = true;
if(target.IsFrameworkOnApple())
if(target.IsFrameworkOnApple()
|| target.GetType() == cmTarget::INTERFACE_LIBRARY)
{
createInstallGeneratorsForTargetFileSets = false;
}

View File

@ -541,6 +541,10 @@ void cmLocalGenerator::GenerateTargetManifest()
t != targets.end(); ++t)
{
cmGeneratorTarget& target = *t->second;
if (target.Target->GetType() == cmTarget::INTERFACE_LIBRARY)
{
continue;
}
if(configNames.empty())
{
target.GenerateTargetManifest(0);
@ -2829,6 +2833,11 @@ cmLocalGenerator
cmTargets& tgts = this->Makefile->GetTargets();
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l)
{
if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
{
continue;
}
// Include the user-specified pre-install script for this target.
if(const char* preinstall = l->second.GetProperty("PRE_INSTALL_SCRIPT"))
{

View File

@ -68,7 +68,8 @@ void cmLocalNinjaGenerator::Generate()
for(cmGeneratorTargetsType::iterator t = targets.begin();
t != targets.end(); ++t)
{
if (t->second->Target->IsImported())
if (t->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY
|| t->second->Target->IsImported())
{
continue;
}

View File

@ -151,7 +151,8 @@ void cmLocalUnixMakefileGenerator3::Generate()
for(cmGeneratorTargetsType::iterator t = targets.begin();
t != targets.end(); ++t)
{
if (t->second->Target->IsImported())
if (t->second->Target->GetType() == cmTarget::INTERFACE_LIBRARY
|| t->second->Target->IsImported())
{
continue;
}

View File

@ -868,6 +868,10 @@ void cmMakefile::ConfigureFinalPass()
for (cmTargets::iterator l = this->Targets.begin();
l != this->Targets.end(); l++)
{
if (l->second.GetType() == cmTarget::INTERFACE_LIBRARY)
{
continue;
}
l->second.FinishConfigure();
}
}
@ -2256,6 +2260,10 @@ void cmMakefile::ExpandVariablesCMP0019()
l != this->Targets.end(); ++l)
{
cmTarget &t = l->second;
if (t.GetType() == cmTarget::INTERFACE_LIBRARY)
{
continue;
}
includeDirs = t.GetProperty("INCLUDE_DIRECTORIES");
if(mightExpandVariablesCMP0019(includeDirs))
{

View File

@ -25,9 +25,12 @@ cmMakefileLibraryTargetGenerator
cmMakefileTargetGenerator(target->Target)
{
this->CustomCommandDriver = OnDepends;
if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
{
this->Target->GetLibraryNames(
this->TargetNameOut, this->TargetNameSO, this->TargetNameReal,
this->TargetNameImport, this->TargetNamePDB, this->ConfigName);
}
this->OSXBundleGenerator = new cmOSXBundleGenerator(target,
this->ConfigName);

View File

@ -255,6 +255,8 @@ void cmTarget::SetMakefile(cmMakefile* mf)
this->IsApple = this->Makefile->IsOn("APPLE");
// Setup default property values.
if (this->GetType() != INTERFACE_LIBRARY)
{
this->SetPropertyDefault("INSTALL_NAME_DIR", 0);
this->SetPropertyDefault("INSTALL_RPATH", "");
this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
@ -280,7 +282,7 @@ void cmTarget::SetMakefile(cmMakefile* mf)
this->SetPropertyDefault("MACOSX_BUNDLE", 0);
this->SetPropertyDefault("MACOSX_RPATH", 0);
this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0);
}
// Collect the set of configuration types.
std::vector<std::string> configNames;
@ -300,6 +302,11 @@ void cmTarget::SetMakefile(cmMakefile* mf)
std::string configUpper = cmSystemTools::UpperCase(*ci);
for(const char** p = configProps; *p; ++p)
{
if (this->TargetTypeValue == INTERFACE_LIBRARY
&& strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0)
{
continue;
}
std::string property = *p;
property += configUpper;
this->SetPropertyDefault(property.c_str(), 0);
@ -311,7 +318,8 @@ void cmTarget::SetMakefile(cmMakefile* mf)
// did not support this variable. Projects may still specify the
// property directly. TODO: Make this depend on backwards
// compatibility setting.
if(this->TargetTypeValue != cmTarget::EXECUTABLE)
if(this->TargetTypeValue != cmTarget::EXECUTABLE
&& this->TargetTypeValue != cmTarget::INTERFACE_LIBRARY)
{
std::string property = cmSystemTools::UpperCase(*ci);
property += "_POSTFIX";
@ -352,16 +360,22 @@ void cmTarget::SetMakefile(cmMakefile* mf)
this->InsertCompileOption(*it);
}
if (this->GetType() != INTERFACE_LIBRARY)
{
this->SetPropertyDefault("C_VISIBILITY_PRESET", 0);
this->SetPropertyDefault("CXX_VISIBILITY_PRESET", 0);
this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
}
if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
|| this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
{
this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
}
if (this->GetType() != INTERFACE_LIBRARY)
{
this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
}
// Record current policies for later use.
#define CAPTURE_TARGET_POLICY(POLICY) \
@ -4433,7 +4447,8 @@ bool isLinkDependentProperty(cmTarget const* tgt, const std::string &p,
bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p,
const char *config) const
{
if (this->TargetTypeValue == OBJECT_LIBRARY)
if (this->TargetTypeValue == OBJECT_LIBRARY
|| this->TargetTypeValue == INTERFACE_LIBRARY)
{
return false;
}
@ -4446,7 +4461,8 @@ bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p,
bool cmTarget::IsLinkInterfaceDependentStringProperty(const std::string &p,
const char *config) const
{
if (this->TargetTypeValue == OBJECT_LIBRARY)
if (this->TargetTypeValue == OBJECT_LIBRARY
|| this->TargetTypeValue == INTERFACE_LIBRARY)
{
return false;
}
@ -4458,7 +4474,8 @@ bool cmTarget::IsLinkInterfaceDependentStringProperty(const std::string &p,
bool cmTarget::IsLinkInterfaceDependentNumberMinProperty(const std::string &p,
const char *config) const
{
if (this->TargetTypeValue == OBJECT_LIBRARY)
if (this->TargetTypeValue == OBJECT_LIBRARY
|| this->TargetTypeValue == INTERFACE_LIBRARY)
{
return false;
}
@ -4470,7 +4487,8 @@ bool cmTarget::IsLinkInterfaceDependentNumberMinProperty(const std::string &p,
bool cmTarget::IsLinkInterfaceDependentNumberMaxProperty(const std::string &p,
const char *config) const
{
if (this->TargetTypeValue == OBJECT_LIBRARY)
if (this->TargetTypeValue == OBJECT_LIBRARY
|| this->TargetTypeValue == INTERFACE_LIBRARY)
{
return false;
}
@ -5105,6 +5123,8 @@ bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface,
{
emitted.insert(*li);
}
if (this->GetType() != cmTarget::INTERFACE_LIBRARY)
{
LinkImplementation const* impl = this->GetLinkImplementation(config,
headTarget);
for(std::vector<std::string>::const_iterator
@ -5136,6 +5156,7 @@ bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface,
}
}
}
}
else if (this->PolicyStatusCMP0022 == cmPolicies::WARN
|| this->PolicyStatusCMP0022 == cmPolicies::OLD)
// If CMP0022 is NEW then the plain tll signature sets the

View File

@ -184,7 +184,8 @@ void cmVisualStudio10TargetGenerator::WriteString(const char* line,
void cmVisualStudio10TargetGenerator::Generate()
{
// do not generate external ms projects
if(this->Target->GetProperty("EXTERNAL_MSPROJECT"))
if(this->Target->GetType() == cmTarget::INTERFACE_LIBRARY
|| this->Target->GetProperty("EXTERNAL_MSPROJECT"))
{
return;
}