diff options
author | Brad King <brad.king@kitware.com> | 2024-05-01 14:05:53 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-05-01 14:06:11 (GMT) |
commit | de9faaf0a318d05b694d0edebedfab84e820fe51 (patch) | |
tree | ddfdb25866c37ddbbee6a8b0a474c60fb1c73939 /Source/cmGeneratorTarget.cxx | |
parent | 30b61287adfac023820c2d6ca70d96216fe226b5 (diff) | |
parent | ddb9442f487808b74ed3429832a74385a1214582 (diff) | |
download | CMake-de9faaf0a318d05b694d0edebedfab84e820fe51.zip CMake-de9faaf0a318d05b694d0edebedfab84e820fe51.tar.gz CMake-de9faaf0a318d05b694d0edebedfab84e820fe51.tar.bz2 |
Merge topic 'genex-link-properties'
ddb9442f48 GenEx: Fix TARGET_PROPERTY evaluation of transitive link properties
862b8e28ad GenEx: Teach TARGET_PROPERTY evaluation to optionally pierce LINK_ONLY
8d1d6a1437 Tests: Cover TARGET_PROPERTY genex evaluation of transitive link properties
abf607c2ec Tests: Cover TARGET_PROPERTY genex evaluation of transitive build properties
7d3d728a72 Help: Clarify CMP0099 documentation and summary text
79a3ae9a0d cmGeneratorExpressionDAGChecker: Simplify transitive property table
e8010b67c7 cmGeneratorExpressionDAGChecker: Make local generator available in constructor
b36fb3f6f1 cmGeneratorExpressionNode: Remove outdated lint suppression
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !9473
Diffstat (limited to 'Source/cmGeneratorTarget.cxx')
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 117 |
1 files changed, 92 insertions, 25 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 319526a..c14ff3a 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -65,6 +65,7 @@ namespace { using LinkInterfaceFor = cmGeneratorTarget::LinkInterfaceFor; +using TransitiveProperty = cmGeneratorTarget::TransitiveProperty; const std::string kINTERFACE_LINK_LIBRARIES = "INTERFACE_LINK_LIBRARIES"; const std::string kINTERFACE_LINK_LIBRARIES_DIRECT = @@ -73,6 +74,33 @@ const std::string kINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE = "INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE"; } +const std::map<cm::string_view, TransitiveProperty> + cmGeneratorTarget::BuiltinTransitiveProperties = { + { "AUTOMOC_MACRO_NAMES"_s, + { "INTERFACE_AUTOMOC_MACRO_NAMES"_s, LinkInterfaceFor::Usage } }, + { "AUTOUIC_OPTIONS"_s, + { "INTERFACE_AUTOUIC_OPTIONS"_s, LinkInterfaceFor::Usage } }, + { "COMPILE_DEFINITIONS"_s, + { "INTERFACE_COMPILE_DEFINITIONS"_s, LinkInterfaceFor::Usage } }, + { "COMPILE_FEATURES"_s, + { "INTERFACE_COMPILE_FEATURES"_s, LinkInterfaceFor::Usage } }, + { "COMPILE_OPTIONS"_s, + { "INTERFACE_COMPILE_OPTIONS"_s, LinkInterfaceFor::Usage } }, + { "INCLUDE_DIRECTORIES"_s, + { "INTERFACE_INCLUDE_DIRECTORIES"_s, LinkInterfaceFor::Usage } }, + { "LINK_DEPENDS"_s, + { "INTERFACE_LINK_DEPENDS"_s, LinkInterfaceFor::Link } }, + { "LINK_DIRECTORIES"_s, + { "INTERFACE_LINK_DIRECTORIES"_s, LinkInterfaceFor::Link } }, + { "LINK_OPTIONS"_s, + { "INTERFACE_LINK_OPTIONS"_s, LinkInterfaceFor::Link } }, + { "PRECOMPILE_HEADERS"_s, + { "INTERFACE_PRECOMPILE_HEADERS"_s, LinkInterfaceFor::Usage } }, + { "SOURCES"_s, { "INTERFACE_SOURCES"_s, LinkInterfaceFor::Usage } }, + { "SYSTEM_INCLUDE_DIRECTORIES"_s, + { "INTERFACE_SYSTEM_INCLUDE_DIRECTORIES"_s, LinkInterfaceFor::Usage } }, + }; + template <> cmValue cmTargetPropertyComputer::GetSources<cmGeneratorTarget>( cmGeneratorTarget const* tgt, cmMakefile const& /* mf */) @@ -887,7 +915,7 @@ std::string cmGeneratorTarget::GetLinkerTypeProperty( auto linkerType = this->GetProperty(propName); if (!linkerType.IsEmpty()) { cmGeneratorExpressionDAGChecker dagChecker(this, propName, nullptr, - nullptr); + nullptr, this->LocalGenerator); auto ltype = cmGeneratorExpression::Evaluate(*linkerType, this->GetLocalGenerator(), config, this, &dagChecker, this, lang); @@ -1352,7 +1380,8 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory( if (iter == this->SystemIncludesCache.end()) { cmGeneratorExpressionDAGChecker dagChecker( - this, "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr); + this, "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr, + this->LocalGenerator); bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED"); @@ -1460,7 +1489,8 @@ std::string cmGeneratorTarget::EvaluateInterfaceProperty( // a subset of TargetPropertyNode::Evaluate without stringify/parse steps // but sufficient for transitive interface properties. cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace, this, prop, - nullptr, dagCheckerParent); + nullptr, dagCheckerParent, + this->LocalGenerator); switch (dagChecker.Check()) { case cmGeneratorExpressionDAGChecker::SELF_REFERENCE: dagChecker.ReportError( @@ -1525,6 +1555,38 @@ std::string cmGeneratorTarget::EvaluateInterfaceProperty( return result; } +cm::optional<cmGeneratorTarget::TransitiveProperty> +cmGeneratorTarget::IsTransitiveProperty(cm::string_view prop, + cmLocalGenerator const* lg) const +{ + cm::optional<TransitiveProperty> result; + static const cm::string_view kINTERFACE_ = "INTERFACE_"_s; + if (cmHasPrefix(prop, kINTERFACE_)) { + prop = prop.substr(kINTERFACE_.length()); + } + auto i = BuiltinTransitiveProperties.find(prop); + if (i != BuiltinTransitiveProperties.end()) { + result = i->second; + if (result->InterfaceFor != cmGeneratorTarget::LinkInterfaceFor::Usage) { + cmPolicies::PolicyStatus cmp0166 = + lg->GetPolicyStatus(cmPolicies::CMP0166); + if ((cmp0166 == cmPolicies::WARN || cmp0166 == cmPolicies::OLD) && + (prop == "LINK_DIRECTORIES"_s || prop == "LINK_DEPENDS"_s || + prop == "LINK_OPTIONS"_s)) { + result->InterfaceFor = cmGeneratorTarget::LinkInterfaceFor::Usage; + } + } + } else if (cmHasLiteralPrefix(prop, "COMPILE_DEFINITIONS_")) { + cmPolicies::PolicyStatus cmp0043 = + lg->GetPolicyStatus(cmPolicies::CMP0043); + if (cmp0043 == cmPolicies::WARN || cmp0043 == cmPolicies::OLD) { + result = TransitiveProperty{ "INTERFACE_COMPILE_DEFINITIONS"_s, + LinkInterfaceFor::Usage }; + } + } + return result; +} + namespace { enum class IncludeDirectoryFallBack @@ -1539,8 +1601,10 @@ std::string AddLangSpecificInterfaceIncludeDirectories( const std::string& propertyName, IncludeDirectoryFallBack mode, cmGeneratorExpressionDAGChecker* context) { - cmGeneratorExpressionDAGChecker dag{ target->GetBacktrace(), target, - propertyName, nullptr, context }; + cmGeneratorExpressionDAGChecker dag{ + target->GetBacktrace(), target, propertyName, nullptr, context, + target->GetLocalGenerator() + }; switch (dag.Check()) { case cmGeneratorExpressionDAGChecker::SELF_REFERENCE: dag.ReportError( @@ -1590,8 +1654,10 @@ void AddLangSpecificImplicitIncludeDirectories( { if (const auto* libraries = target->GetLinkImplementationLibraries( config, LinkInterfaceFor::Usage)) { - cmGeneratorExpressionDAGChecker dag{ target->GetBacktrace(), target, - propertyName, nullptr, nullptr }; + cmGeneratorExpressionDAGChecker dag{ + target->GetBacktrace(), target, propertyName, nullptr, nullptr, + target->GetLocalGenerator() + }; for (const cmLinkImplItem& library : libraries->Libraries) { if (const cmGeneratorTarget* dependency = library.Target) { @@ -1843,8 +1909,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths( this->DebugSourcesDone = true; } - cmGeneratorExpressionDAGChecker dagChecker(this, "SOURCES", nullptr, - nullptr); + cmGeneratorExpressionDAGChecker dagChecker(this, "SOURCES", nullptr, nullptr, + this->LocalGenerator); EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries( this, config, std::string(), &dagChecker, this->SourceEntries); @@ -3058,7 +3124,7 @@ void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string>& result, } cmGeneratorExpressionDAGChecker dagChecker(this, "AUTOUIC_OPTIONS", nullptr, - nullptr); + nullptr, this->LocalGenerator); cmExpandList(cmGeneratorExpression::Evaluate(prop, this->LocalGenerator, config, this, &dagChecker), result); @@ -3858,8 +3924,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories( std::vector<BT<std::string>> includes; std::unordered_set<std::string> uniqueIncludes; - cmGeneratorExpressionDAGChecker dagChecker(this, "INCLUDE_DIRECTORIES", - nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker( + this, "INCLUDE_DIRECTORIES", nullptr, nullptr, this->LocalGenerator); cmList debugProperties{ this->Makefile->GetDefinition( "CMAKE_DEBUG_TARGET_PROPERTIES") }; @@ -4123,7 +4189,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileOptions( std::unordered_set<std::string> uniqueOptions; cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_OPTIONS", nullptr, - nullptr); + nullptr, this->LocalGenerator); cmList debugProperties{ this->Makefile->GetDefinition( "CMAKE_DEBUG_TARGET_PROPERTIES") }; @@ -4164,7 +4230,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileFeatures( std::unordered_set<std::string> uniqueFeatures; cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_FEATURES", nullptr, - nullptr); + nullptr, this->LocalGenerator); cmList debugProperties{ this->Makefile->GetDefinition( "CMAKE_DEBUG_TARGET_PROPERTIES") }; @@ -4213,8 +4279,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions( std::vector<BT<std::string>> list; std::unordered_set<std::string> uniqueOptions; - cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_DEFINITIONS", - nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker( + this, "COMPILE_DEFINITIONS", nullptr, nullptr, this->LocalGenerator); cmList debugProperties{ this->Makefile->GetDefinition( "CMAKE_DEBUG_TARGET_PROPERTIES") }; @@ -4277,8 +4343,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetPrecompileHeaders( } std::unordered_set<std::string> uniqueOptions; - cmGeneratorExpressionDAGChecker dagChecker(this, "PRECOMPILE_HEADERS", - nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker( + this, "PRECOMPILE_HEADERS", nullptr, nullptr, this->LocalGenerator); cmList debugProperties{ this->Makefile->GetDefinition( "CMAKE_DEBUG_TARGET_PROPERTIES") }; @@ -4667,7 +4733,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions( std::unordered_set<std::string> uniqueOptions; cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_OPTIONS", nullptr, - nullptr); + nullptr, this->LocalGenerator); cmList debugProperties{ this->Makefile->GetDefinition( "CMAKE_DEBUG_TARGET_PROPERTIES") }; @@ -4835,8 +4901,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions( std::vector<BT<std::string>> result; std::unordered_set<std::string> uniqueOptions; - cmGeneratorExpressionDAGChecker dagChecker(this, "STATIC_LIBRARY_OPTIONS", - nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker( + this, "STATIC_LIBRARY_OPTIONS", nullptr, nullptr, this->LocalGenerator); EvaluatedTargetPropertyEntries entries; if (cmValue linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) { @@ -4949,7 +5015,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories( std::unordered_set<std::string> uniqueDirectories; cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DIRECTORIES", nullptr, - nullptr); + nullptr, this->LocalGenerator); cmList debugProperties{ this->Makefile->GetDefinition( "CMAKE_DEBUG_TARGET_PROPERTIES") }; @@ -4993,7 +5059,7 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends( std::vector<BT<std::string>> result; std::unordered_set<std::string> uniqueOptions; cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DEPENDS", nullptr, - nullptr); + nullptr, this->LocalGenerator); EvaluatedTargetPropertyEntries entries; if (cmValue linkDepends = this->GetProperty("LINK_DEPENDS")) { @@ -6979,7 +7045,8 @@ void cmGeneratorTarget::ExpandLinkItems( return; } // Keep this logic in sync with ComputeLinkImplementationLibraries. - cmGeneratorExpressionDAGChecker dagChecker(this, prop, nullptr, nullptr); + cmGeneratorExpressionDAGChecker dagChecker(this, prop, nullptr, nullptr, + this->LocalGenerator); // The $<LINK_ONLY> expression may be in a link interface to specify // private link dependencies that are otherwise excluded from usage // requirements. @@ -8654,7 +8721,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries( for (auto const& entry : entryRange) { // Keep this logic in sync with ExpandLinkItems. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_LIBRARIES", nullptr, - nullptr); + nullptr, this->LocalGenerator); // The $<LINK_ONLY> expression may be used to specify link dependencies // that are otherwise excluded from usage requirements. if (implFor == LinkInterfaceFor::Usage) { |