diff options
Diffstat (limited to 'Source/cmTarget.cxx')
-rw-r--r-- | Source/cmTarget.cxx | 217 |
1 files changed, 155 insertions, 62 deletions
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index ac655da..1c04e4e 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -47,6 +47,8 @@ const char* cmTarget::GetTargetTypeName(TargetType targetType) return "UTILITY"; case cmTarget::GLOBAL_TARGET: return "GLOBAL_TARGET"; + case cmTarget::INTERFACE_LIBRARY: + return "INTERFACE_LIBRARY"; case cmTarget::UNKNOWN_LIBRARY: return "UNKNOWN_LIBRARY"; } @@ -924,10 +926,24 @@ void cmTarget::DefineProperties(cmake *cm) "The first configuration in the list found to be provided by the " "imported target is selected. If this property is set and no matching " "configurations are available, then the imported target is considered " - "to be not found. This property is ignored for non-imported targets.", + "to be not found. This property is ignored for non-imported targets.\n" + "This property is initialized by the value of the variable " + "CMAKE_MAP_IMPORTED_CONFIG_<CONFIG> if it is set when a target is " + "created.", false /* TODO: make this chained */ ); cm->DefineProperty + ("NO_SYSTEM_FROM_IMPORTED", cmProperty::TARGET, + "Do not treat includes from IMPORTED target interfaces as SYSTEM.", + "The contents of the INTERFACE_INCLUDE_DIRECTORIES of IMPORTED targets " + "are treated as SYSTEM includes by default. If this property is " + "enabled, the contents of the INTERFACE_INCLUDE_DIRECTORIES of IMPORTED " + "targets are not treated as system includes. " + "This property is initialized by the value of the variable " + "CMAKE_NO_SYSTEM_FROM_IMPORTED if it is set when a target is " + "created."); + + cm->DefineProperty ("OSX_ARCHITECTURES", cmProperty::TARGET, "Target specific architectures for OS X.", "The OSX_ARCHITECTURES property sets the target binary architecture " @@ -1637,6 +1653,7 @@ void cmTarget::SetMakefile(cmMakefile* mf) this->SetPropertyDefault("WIN32_EXECUTABLE", 0); this->SetPropertyDefault("MACOSX_BUNDLE", 0); this->SetPropertyDefault("MACOSX_RPATH", 0); + this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0); // Collect the set of configuration types. @@ -1649,6 +1666,7 @@ void cmTarget::SetMakefile(cmMakefile* mf) "LIBRARY_OUTPUT_DIRECTORY_", "RUNTIME_OUTPUT_DIRECTORY_", "PDB_OUTPUT_DIRECTORY_", + "MAP_IMPORTED_CONFIG_", 0}; for(std::vector<std::string>::iterator ci = configNames.begin(); ci != configNames.end(); ++ci) @@ -1727,6 +1745,14 @@ void cmTarget::SetMakefile(cmMakefile* mf) CM_FOR_EACH_TARGET_POLICY(CAPTURE_TARGET_POLICY) #undef CAPTURE_TARGET_POLICY + + if (this->TargetTypeValue == INTERFACE_LIBRARY) + { + // This policy is checked in a few conditions. The properties relevant + // to the policy are always ignored for INTERFACE_LIBRARY targets, + // so ensure that the conditions don't lead to nonsense. + this->PolicyStatusCMP0022 = cmPolicies::NEW; + } } //---------------------------------------------------------------------------- @@ -1792,6 +1818,7 @@ bool cmTarget::IsLinkable() this->GetType() == cmTarget::SHARED_LIBRARY || this->GetType() == cmTarget::MODULE_LIBRARY || this->GetType() == cmTarget::UNKNOWN_LIBRARY || + this->GetType() == cmTarget::INTERFACE_LIBRARY || this->IsExecutableWithExports()); } @@ -2563,8 +2590,8 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, return; } - { cmTarget *tgt = this->Makefile->FindTargetToUse(lib); + { const bool isNonImportedTarget = tgt && !tgt->IsImported(); const std::string libName = (isNonImportedTarget && llt != GENERAL) @@ -2575,7 +2602,8 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, llt).c_str()); } - if (cmGeneratorExpression::Find(lib) != std::string::npos) + if (cmGeneratorExpression::Find(lib) != std::string::npos + || (tgt && tgt->GetType() == INTERFACE_LIBRARY)) { return; } @@ -2657,6 +2685,11 @@ void cmTarget::FinalizeSystemIncludeDirectories() end = this->Internal->LinkInterfacePropertyEntries.end(); it != end; ++it) { + if (!cmGeneratorExpression::IsValidTargetName(it->Value) + && cmGeneratorExpression::Find(it->Value) == std::string::npos) + { + continue; + } { cmListFileBacktrace lfbt; cmGeneratorExpression ge(lfbt); @@ -2664,10 +2697,28 @@ void cmTarget::FinalizeSystemIncludeDirectories() ge.Parse(it->Value); std::string targetName = cge->Evaluate(this->Makefile, 0, false, this, 0, 0); - if (!this->Makefile->FindTargetToUse(targetName.c_str())) + cmTarget *tgt = this->Makefile->FindTargetToUse(targetName.c_str()); + if (!tgt) { continue; } + if (tgt->IsImported() + && tgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES") + && !this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED")) + { + std::string includeGenex = "$<TARGET_PROPERTY:" + + it->Value + ",INTERFACE_INCLUDE_DIRECTORIES>"; + if (cmGeneratorExpression::Find(it->Value) != std::string::npos) + { + // Because it->Value is a generator expression, ensure that it + // evaluates to the non-empty string before being used in the + // TARGET_PROPERTY expression. + includeGenex = "$<$<BOOL:" + it->Value + ">:" + includeGenex + ">"; + } + this->SystemIncludeDirectories.insert(includeGenex); + return; // The INTERFACE_SYSTEM_INCLUDE_DIRECTORIES are a subset + // of the INTERFACE_INCLUDE_DIRECTORIES + } } std::string includeGenex = "$<TARGET_PROPERTY:" + it->Value + ",INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>"; @@ -3033,15 +3084,11 @@ void cmTarget::SetProperty(const char* prop, const char* value) if (strcmp(prop, "LINK_LIBRARIES") == 0) { this->Internal->LinkInterfacePropertyEntries.clear(); - if (cmGeneratorExpression::IsValidTargetName(value) - || cmGeneratorExpression::Find(value) != std::string::npos) - { - cmListFileBacktrace lfbt; - this->Makefile->GetBacktrace(lfbt); - cmValueWithOrigin entry(value, lfbt); - this->Internal->LinkInterfacePropertyEntries.push_back(entry); - } - // Fall through + cmListFileBacktrace lfbt; + this->Makefile->GetBacktrace(lfbt); + cmValueWithOrigin entry(value, lfbt); + this->Internal->LinkInterfacePropertyEntries.push_back(entry); + return; } this->Properties.SetProperty(prop, value, cmProperty::TARGET); this->MaybeInvalidatePropertyCache(prop); @@ -3099,15 +3146,11 @@ void cmTarget::AppendProperty(const char* prop, const char* value, } if (strcmp(prop, "LINK_LIBRARIES") == 0) { - if (cmGeneratorExpression::IsValidTargetName(value) - || cmGeneratorExpression::Find(value) != std::string::npos) - { - cmListFileBacktrace lfbt; - this->Makefile->GetBacktrace(lfbt); - cmValueWithOrigin entry(value, lfbt); - this->Internal->LinkInterfacePropertyEntries.push_back(entry); - } - // Fall through + cmListFileBacktrace lfbt; + this->Makefile->GetBacktrace(lfbt); + cmValueWithOrigin entry(value, lfbt); + this->Internal->LinkInterfacePropertyEntries.push_back(entry); + return; } this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString); this->MaybeInvalidatePropertyCache(prop); @@ -3387,6 +3430,11 @@ std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config) end = this->Internal->LinkInterfacePropertyEntries.end(); it != end; ++it) { + if (!cmGeneratorExpression::IsValidTargetName(it->Value) + && cmGeneratorExpression::Find(it->Value) == std::string::npos) + { + continue; + } { cmGeneratorExpression ge(lfbt); cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = @@ -3585,6 +3633,11 @@ void cmTarget::GetCompileOptions(std::vector<std::string> &result, end = this->Internal->LinkInterfacePropertyEntries.end(); it != end; ++it) { + if (!cmGeneratorExpression::IsValidTargetName(it->Value) + && cmGeneratorExpression::Find(it->Value) == std::string::npos) + { + continue; + } { cmGeneratorExpression ge(lfbt); cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = @@ -3693,6 +3746,11 @@ void cmTarget::GetCompileDefinitions(std::vector<std::string> &list, end = this->Internal->LinkInterfacePropertyEntries.end(); it != end; ++it) { + if (!cmGeneratorExpression::IsValidTargetName(it->Value) + && cmGeneratorExpression::Find(it->Value) == std::string::npos) + { + continue; + } { cmGeneratorExpression ge(lfbt); cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = @@ -4091,6 +4149,7 @@ const char *cmTarget::GetProperty(const char* prop, this->GetType() == cmTarget::STATIC_LIBRARY || this->GetType() == cmTarget::SHARED_LIBRARY || this->GetType() == cmTarget::MODULE_LIBRARY || + this->GetType() == cmTarget::INTERFACE_LIBRARY || this->GetType() == cmTarget::UNKNOWN_LIBRARY) { if(strcmp(prop,"LOCATION") == 0) @@ -4115,7 +4174,7 @@ const char *cmTarget::GetProperty(const char* prop, } else { - // Support "<CONFIG>_LOCATION" for compatiblity. + // Support "<CONFIG>_LOCATION" for compatibility. int len = static_cast<int>(strlen(prop)); if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0) { @@ -4181,6 +4240,22 @@ const char *cmTarget::GetProperty(const char* prop, } return output.c_str(); } + if(strcmp(prop,"LINK_LIBRARIES") == 0) + { + static std::string output; + output = ""; + std::string sep; + for (std::vector<cmValueWithOrigin>::const_iterator + it = this->Internal->LinkInterfacePropertyEntries.begin(), + end = this->Internal->LinkInterfacePropertyEntries.end(); + it != end; ++it) + { + output += sep; + output += it->Value; + sep = ";"; + } + return output.c_str(); + } if (strcmp(prop,"IMPORTED") == 0) { @@ -5999,6 +6074,10 @@ cmTarget::GetImportInfo(const char* config, cmTarget *headTarget) i = this->Internal->ImportInfoMap.insert(entry).first; } + if(this->GetType() == INTERFACE_LIBRARY) + { + return &i->second; + } // If the location is empty then the target is not available for // this configuration. if(i->second.Location.empty() && i->second.ImportLibrary.empty()) @@ -6147,7 +6226,51 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config, const char* loc = 0; const char* imp = 0; std::string suffix; - if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix)) + if (this->GetType() != INTERFACE_LIBRARY && + !this->GetMappedConfig(desired_config, &loc, &imp, suffix)) + { + return; + } + + // Get the link interface. + { + std::string linkProp = "INTERFACE_LINK_LIBRARIES"; + const char *propertyLibs = this->GetProperty(linkProp.c_str()); + + if (this->GetType() != INTERFACE_LIBRARY) + { + if(!propertyLibs) + { + linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES"; + linkProp += suffix; + propertyLibs = this->GetProperty(linkProp.c_str()); + } + + if(!propertyLibs) + { + linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES"; + propertyLibs = this->GetProperty(linkProp.c_str()); + } + } + if(propertyLibs) + { + cmListFileBacktrace lfbt; + cmGeneratorExpression ge(lfbt); + + cmGeneratorExpressionDAGChecker dagChecker(lfbt, + this->GetName(), + linkProp, 0, 0); + cmSystemTools::ExpandListArgument(ge.Parse(propertyLibs) + ->Evaluate(this->Makefile, + desired_config.c_str(), + false, + headTarget, + this, + &dagChecker), + info.LinkInterface.Libraries); + } + } + if(this->GetType() == INTERFACE_LIBRARY) { return; } @@ -6224,42 +6347,6 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config, } } - // Get the link interface. - { - std::string linkProp = "INTERFACE_LINK_LIBRARIES"; - const char *propertyLibs = this->GetProperty(linkProp.c_str()); - - if (!propertyLibs) - { - linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES"; - linkProp += suffix; - propertyLibs = this->GetProperty(linkProp.c_str()); - } - - if(!propertyLibs) - { - linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES"; - propertyLibs = this->GetProperty(linkProp.c_str()); - } - if(propertyLibs) - { - cmListFileBacktrace lfbt; - cmGeneratorExpression ge(lfbt); - - cmGeneratorExpressionDAGChecker dagChecker(lfbt, - this->GetName(), - linkProp, 0, 0); - cmSystemTools::ExpandListArgument(ge.Parse(propertyLibs) - ->Evaluate(this->Makefile, - desired_config.c_str(), - false, - headTarget, - this, - &dagChecker), - info.LinkInterface.Libraries); - } - } - // Get the link dependencies. { std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES"; @@ -6520,6 +6607,11 @@ bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface, } } } + else if (this->GetType() == cmTarget::INTERFACE_LIBRARY) + { + explicitLibraries = newExplicitLibraries; + linkIfaceProp = "INTERFACE_LINK_LIBRARIES"; + } // There is no implicit link interface for executables or modules // so if none was explicitly set then there is no link interface. @@ -6547,7 +6639,8 @@ bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface, this, &dagChecker), iface.Libraries); if(this->GetType() == cmTarget::SHARED_LIBRARY - || this->GetType() == cmTarget::STATIC_LIBRARY) + || this->GetType() == cmTarget::STATIC_LIBRARY + || this->GetType() == cmTarget::INTERFACE_LIBRARY) { // Shared libraries may have runtime implementation dependencies // on other shared libraries that are not in the interface. @@ -6823,7 +6916,7 @@ void checkPropertyConsistency(cmTarget *depender, cmTarget *dependee, pi != props.end(); ++pi) { if (depender->GetMakefile()->GetCMakeInstance() - ->GetIsPropertyDefined(pi->c_str(), + ->IsPropertyDefined(pi->c_str(), cmProperty::TARGET)) { cmOStringStream e; |