diff options
author | Brad King <brad.king@kitware.com> | 2013-02-05 19:54:02 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2013-02-07 16:09:01 (GMT) |
commit | c0debb1f89de47f13f7b9682ebd24b772a649e78 (patch) | |
tree | 15e09c0a61f81ef5e4e0fdb6533ca7987c031d17 /Source/cmTarget.cxx | |
parent | daae0d2f5b0f9f5e1db3615d85d39ee819d50175 (diff) | |
parent | ec85306025ae787e08d4ce097fde966f1809c74f (diff) | |
download | CMake-c0debb1f89de47f13f7b9682ebd24b772a649e78.zip CMake-c0debb1f89de47f13f7b9682ebd24b772a649e78.tar.gz CMake-c0debb1f89de47f13f7b9682ebd24b772a649e78.tar.bz2 |
Merge branch 'master' into generator-toolset
We need the latest Tests/CMakeLists.txt so we can refactor all tests.
Diffstat (limited to 'Source/cmTarget.cxx')
-rw-r--r-- | Source/cmTarget.cxx | 389 |
1 files changed, 320 insertions, 69 deletions
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 815da40..ca0e24b 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -134,6 +134,7 @@ public: : ge(cge) {} const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge; + std::vector<std::string> CachedIncludes; }; std::vector<IncludeDirectoriesEntry*> IncludeDirectoriesEntries; }; @@ -145,12 +146,14 @@ cmTarget::cmTarget() this->PolicyStatusCMP0003 = cmPolicies::WARN; this->PolicyStatusCMP0004 = cmPolicies::WARN; this->PolicyStatusCMP0008 = cmPolicies::WARN; + this->PolicyStatusCMP0020 = cmPolicies::WARN; this->LinkLibrariesAnalyzed = false; this->HaveInstallRule = false; this->DLLPlatform = false; this->IsApple = false; this->IsImportedTarget = false; this->BuildInterfaceIncludesAppended = false; + this->DebugIncludesDone = false; } //---------------------------------------------------------------------------- @@ -906,6 +909,17 @@ void cmTarget::DefineProperties(cmake *cm) "property is not set, then it is ignored."); cm->DefineProperty + ("COMPATIBLE_INTERFACE_STRING", cmProperty::TARGET, + "Properties which must be string-compatible with their link interface", + "The COMPATIBLE_INTERFACE_STRING property may contain a list of " + "properties for this target which must be the same when evaluated as " + "a string in the INTERFACE of all linked dependencies. For example, " + "if a property \"FOO\" appears in the list, then the \"INTERFACE_FOO\" " + "property content in all dependencies must be equal with each " + "other, and with the \"FOO\" property in this target. If the " + "property is not set, then it is ignored."); + + cm->DefineProperty ("POST_INSTALL_SCRIPT", cmProperty::TARGET, "Deprecated install support.", "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the " @@ -1499,6 +1513,8 @@ void cmTarget::SetMakefile(cmMakefile* mf) this->Makefile->GetPolicyStatus(cmPolicies::CMP0004); this->PolicyStatusCMP0008 = this->Makefile->GetPolicyStatus(cmPolicies::CMP0008); + this->PolicyStatusCMP0020 = + this->Makefile->GetPolicyStatus(cmPolicies::CMP0020); } //---------------------------------------------------------------------------- @@ -1520,6 +1536,13 @@ void cmTarget::ClearLinkMaps() this->Internal->LinkImplMap.clear(); this->Internal->LinkInterfaceMap.clear(); this->Internal->LinkClosureMap.clear(); + for (cmTargetLinkInformationMap::const_iterator it + = this->LinkInformation.begin(); + it != this->LinkInformation.end(); ++it) + { + delete it->second; + } + this->LinkInformation.clear(); } //---------------------------------------------------------------------------- @@ -2269,8 +2292,9 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, cmTarget *tgt = this->Makefile->FindTargetToUse(lib); const bool isNonImportedTarget = tgt && !tgt->IsImported(); - std::string libName = isNonImportedTarget ? targetNameGenex(lib) - : std::string(lib); + const std::string libName = (isNonImportedTarget && llt != GENERAL) + ? targetNameGenex(lib) + : std::string(lib); this->AppendProperty("LINK_LIBRARIES", this->GetDebugGeneratorExpressions(libName, llt).c_str()); @@ -2739,53 +2763,106 @@ std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config) cmSystemTools::ExpandListArgument(debugProp, debugProperties); } - bool debugIncludes = std::find(debugProperties.begin(), + bool debugIncludes = !this->DebugIncludesDone + && std::find(debugProperties.begin(), debugProperties.end(), "INCLUDE_DIRECTORIES") != debugProperties.end(); + if (this->Makefile->IsGeneratingBuildSystem()) + { + this->DebugIncludesDone = true; + } + for (std::vector<cmTargetInternals::IncludeDirectoriesEntry*>::const_iterator it = this->Internal->IncludeDirectoriesEntries.begin(), end = this->Internal->IncludeDirectoriesEntries.end(); it != end; ++it) { - std::vector<std::string> entryIncludes; - cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(this->Makefile, - config, - false, - this, - &dagChecker), - entryIncludes); + + bool testIsOff = true; + bool cacheIncludes = false; + std::vector<std::string> entryIncludes = (*it)->CachedIncludes; + if(!entryIncludes.empty()) + { + testIsOff = false; + } + else + { + cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(this->Makefile, + config, + false, + this, + &dagChecker), + entryIncludes); + if (!(*it)->ge->GetHadContextSensitiveCondition()) + { + cacheIncludes = true; + } + } std::string usedIncludes; - for(std::vector<std::string>::const_iterator + for(std::vector<std::string>::iterator li = entryIncludes.begin(); li != entryIncludes.end(); ++li) { - std::string inc = *li; - if (!cmSystemTools::IsOff(inc.c_str())) + if (testIsOff && !cmSystemTools::IsOff(li->c_str())) { - cmSystemTools::ConvertToUnixSlashes(inc); + cmSystemTools::ConvertToUnixSlashes(*li); } + std::string inc = *li; if(uniqueIncludes.insert(inc).second) { - includes.push_back(*li); + includes.push_back(inc); if (debugIncludes) { - usedIncludes += " * " + *li + "\n"; + usedIncludes += " * " + inc + "\n"; } } } + if (cacheIncludes) + { + (*it)->CachedIncludes = entryIncludes; + } if (!usedIncludes.empty()) { this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, - "Used includes:\n" + usedIncludes, - (*it)->ge->GetBacktrace()); + "Used includes for target " + this->Name + ":\n" + + usedIncludes, (*it)->ge->GetBacktrace()); } } return includes; } //---------------------------------------------------------------------------- +std::string cmTarget::GetCompileDefinitions(const char *config) +{ + std::string defPropName = "COMPILE_DEFINITIONS"; + if (config) + { + defPropName += "_" + cmSystemTools::UpperCase(config); + } + + const char *prop = this->GetProperty(defPropName.c_str()); + + if (!prop) + { + return ""; + } + + cmListFileBacktrace lfbt; + cmGeneratorExpression ge(lfbt); + + cmGeneratorExpressionDAGChecker dagChecker(lfbt, + this->GetName(), + defPropName, 0, 0); + return ge.Parse(prop)->Evaluate(this->Makefile, + config, + false, + this, + &dagChecker); +} + +//---------------------------------------------------------------------------- void cmTarget::MaybeInvalidatePropertyCache(const char* prop) { // Wipe out maps caching information affected by this property. @@ -4482,22 +4559,69 @@ void cmTarget::AddLinkDependentTargetsForProperties( } //---------------------------------------------------------------------------- -bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p, - const char *config) +template<typename PropertyType> +PropertyType getTypedProperty(cmTarget *tgt, const char *prop, + PropertyType *); + +//---------------------------------------------------------------------------- +template<> +bool getTypedProperty<bool>(cmTarget *tgt, const char *prop, bool *) +{ + return tgt->GetPropertyAsBool(prop); +} + +//---------------------------------------------------------------------------- +template<> +const char *getTypedProperty<const char *>(cmTarget *tgt, const char *prop, + const char **) { - bool propContent = this->GetPropertyAsBool(p.c_str()); - const bool explicitlySet = this->GetProperties() + return tgt->GetProperty(prop); +} + +//---------------------------------------------------------------------------- +template<typename PropertyType> +bool consistentProperty(PropertyType lhs, PropertyType rhs); + +//---------------------------------------------------------------------------- +template<> +bool consistentProperty(bool lhs, bool rhs) +{ + return lhs == rhs; +} + +//---------------------------------------------------------------------------- +template<> +bool consistentProperty(const char *lhs, const char *rhs) +{ + if (!lhs && !rhs) + return true; + if (!lhs || !rhs) + return false; + return strcmp(lhs, rhs) == 0; +} + +//---------------------------------------------------------------------------- +template<typename PropertyType> +PropertyType checkInterfacePropertyCompatibility(cmTarget *tgt, + const std::string &p, + const char *config, + const char *defaultValue, + PropertyType *) +{ + PropertyType propContent = getTypedProperty<PropertyType>(tgt, p.c_str(), + 0); + const bool explicitlySet = tgt->GetProperties() .find(p.c_str()) - != this->GetProperties().end(); + != tgt->GetProperties().end(); std::set<std::string> dependentTargets; - this->GetLinkDependentTargetsForProperty(p, + tgt->GetLinkDependentTargetsForProperty(p, dependentTargets); const bool impliedByUse = - this->IsNullImpliedByLinkLibraries(p); + tgt->IsNullImpliedByLinkLibraries(p); assert((impliedByUse ^ explicitlySet) || (!impliedByUse && !explicitlySet)); - cmComputeLinkInformation *info = this->GetLinkInformation(config); + cmComputeLinkInformation *info = tgt->GetLinkInformation(config); const cmComputeLinkInformation::ItemVector &deps = info->GetItems(); bool propInitialized = explicitlySet; @@ -4519,20 +4643,22 @@ bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p, const bool ifaceIsSet = li->Target->GetProperties() .find("INTERFACE_" + p) != li->Target->GetProperties().end(); - const bool ifacePropContent = li->Target->GetPropertyAsBool( - ("INTERFACE_" + p).c_str()); + PropertyType ifacePropContent = + getTypedProperty<PropertyType>(li->Target, + ("INTERFACE_" + p).c_str(), 0); if (explicitlySet) { if (ifaceIsSet) { - if (propContent != ifacePropContent) + if (!consistentProperty(propContent, ifacePropContent)) { cmOStringStream e; e << "Property " << p << " on target \"" - << this->GetName() << "\" does\nnot match the " + << tgt->GetName() << "\" does\nnot match the " "INTERFACE_" << p << " property requirement\nof " "dependency \"" << li->Target->GetName() << "\".\n"; cmSystemTools::Error(e.str().c_str()); + break; } else { @@ -4550,15 +4676,16 @@ bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p, { if (ifaceIsSet) { - if (propContent != ifacePropContent) + if (!consistentProperty(propContent, ifacePropContent)) { cmOStringStream e; e << "Property " << p << " on target \"" - << this->GetName() << "\" is\nimplied to be FALSE because it " - "was used to determine the link libraries\nalready. The " - "INTERFACE_" << p << " property on\ndependency \"" + << tgt->GetName() << "\" is\nimplied to be " << defaultValue + << " because it was used to determine the link libraries\n" + "already. The INTERFACE_" << p << " property on\ndependency \"" << li->Target->GetName() << "\" is in conflict.\n"; cmSystemTools::Error(e.str().c_str()); + break; } else { @@ -4578,14 +4705,15 @@ bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p, { if (propInitialized) { - if (propContent != ifacePropContent) + if (!consistentProperty(propContent, ifacePropContent)) { cmOStringStream e; e << "The INTERFACE_" << p << " property of \"" << li->Target->GetName() << "\" does\nnot agree with the value " "of " << p << " already determined\nfor \"" - << this->GetName() << "\".\n"; + << tgt->GetName() << "\".\n"; cmSystemTools::Error(e.str().c_str()); + break; } else { @@ -4610,6 +4738,80 @@ bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p, } //---------------------------------------------------------------------------- +bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p, + const char *config) +{ + return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE", + 0); +} + +//---------------------------------------------------------------------------- +const char * cmTarget::GetLinkInterfaceDependentStringProperty( + const std::string &p, + const char *config) +{ + return checkInterfacePropertyCompatibility<const char *>(this, + p, + config, + "empty", 0); +} + +//---------------------------------------------------------------------------- +bool isLinkDependentProperty(cmTarget *tgt, const std::string &p, + const char *interfaceProperty, + const char *config) +{ + cmComputeLinkInformation *info = tgt->GetLinkInformation(config); + + const cmComputeLinkInformation::ItemVector &deps = info->GetItems(); + + for(cmComputeLinkInformation::ItemVector::const_iterator li = + deps.begin(); + li != deps.end(); ++li) + { + if (!li->Target) + { + continue; + } + const char *prop = li->Target->GetProperty(interfaceProperty); + if (!prop) + { + continue; + } + + std::vector<std::string> props; + cmSystemTools::ExpandListArgument(prop, props); + + for(std::vector<std::string>::iterator pi = props.begin(); + pi != props.end(); ++pi) + { + if (*pi == p) + { + return true; + } + } + } + + return false; +} + +//---------------------------------------------------------------------------- +bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p, + const char *config) +{ + return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_BOOL", + config); +} + +//---------------------------------------------------------------------------- +bool cmTarget::IsLinkInterfaceDependentStringProperty(const std::string &p, + const char *config) +{ + return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_STRING", + config); +} + +//---------------------------------------------------------------------------- void cmTarget::GetLanguages(std::set<cmStdString>& languages) const { for(std::vector<cmSourceFile*>::const_iterator @@ -5349,6 +5551,73 @@ std::string cmTarget::CheckCMP0004(std::string const& item) return lib; } +template<typename PropertyType> +PropertyType getLinkInterfaceDependentProperty(cmTarget *tgt, + const std::string prop, + const char *config, + PropertyType *); + +template<> +bool getLinkInterfaceDependentProperty(cmTarget *tgt, + const std::string prop, + const char *config, bool *) +{ + return tgt->GetLinkInterfaceDependentBoolProperty(prop, config); +} + +template<> +const char * getLinkInterfaceDependentProperty(cmTarget *tgt, + const std::string prop, + const char *config, + const char **) +{ + return tgt->GetLinkInterfaceDependentStringProperty(prop, config); +} + +//---------------------------------------------------------------------------- +template<typename PropertyType> +void checkPropertyConsistency(cmTarget *depender, cmTarget *dependee, + const char *propName, + std::set<cmStdString> &emitted, + const char *config, + PropertyType *) +{ + const char *prop = dependee->GetProperty(propName); + if (!prop) + { + return; + } + + std::vector<std::string> props; + cmSystemTools::ExpandListArgument(prop, props); + + for(std::vector<std::string>::iterator pi = props.begin(); + pi != props.end(); ++pi) + { + if (depender->GetMakefile()->GetCMakeInstance() + ->GetIsPropertyDefined(pi->c_str(), + cmProperty::TARGET)) + { + cmOStringStream e; + e << "Target \"" << dependee->GetName() << "\" has property \"" + << *pi << "\" listed in its " << propName << " property. " + "This is not allowed. Only user-defined properties may appear " + "listed in the " << propName << " property."; + depender->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str()); + return; + } + if(emitted.insert(*pi).second) + { + getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config, + 0); + if (cmSystemTools::GetErrorOccuredFlag()) + { + return; + } + } + } +} + //---------------------------------------------------------------------------- void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info, const char* config) @@ -5365,38 +5634,20 @@ void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info, { continue; } - const char *prop = li->Target->GetProperty("COMPATIBLE_INTERFACE_BOOL"); - if (!prop) + + checkPropertyConsistency<bool>(this, li->Target, + "COMPATIBLE_INTERFACE_BOOL", + emitted, config, 0); + if (cmSystemTools::GetErrorOccuredFlag()) { - continue; + return; } - - std::vector<std::string> props; - cmSystemTools::ExpandListArgument(prop, props); - - for(std::vector<std::string>::iterator pi = props.begin(); - pi != props.end(); ++pi) + checkPropertyConsistency<const char *>(this, li->Target, + "COMPATIBLE_INTERFACE_STRING", + emitted, config, 0); + if (cmSystemTools::GetErrorOccuredFlag()) { - if (this->Makefile->GetCMakeInstance() - ->GetIsPropertyDefined(pi->c_str(), - cmProperty::TARGET)) - { - cmOStringStream e; - e << "Target \"" << li->Target->GetName() << "\" has property \"" - << *pi << "\" listed in its COMPATIBLE_INTERFACE_BOOL property. " - "This is not allowed. Only user-defined properties may appear " - "listed in the COMPATIBLE_INTERFACE_BOOL property."; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); - return; - } - if(emitted.insert(*pi).second) - { - this->GetLinkInterfaceDependentBoolProperty(*pi, config); - if (cmSystemTools::GetErrorOccuredFlag()) - { - return; - } - } + return; } } } @@ -5422,14 +5673,14 @@ cmTarget::GetLinkInformation(const char* config, cmTarget *head) info = 0; } + // Store the information for this configuration. + cmTargetLinkInformationMap::value_type entry(key, info); + i = this->LinkInformation.insert(entry).first; + if (info) { this->CheckPropertyCompatibility(info, config); } - - // Store the information for this configuration. - cmTargetLinkInformationMap::value_type entry(key, info); - i = this->LinkInformation.insert(entry).first; } return i->second; } |