From c94cfe92eb579b07ab7a9bbb66d98090ec6fe840 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 11 Apr 2024 13:37:46 -0400 Subject: GenEx: Fix COMPATIBLE_INTERFACE_ evaluation outside usage requirements In commit ff6c401309 (cmTarget: Add interface for compatible numeric properties, 2013-10-22, v3.0.0-rc1~460^2) the condition dagCheckerParent && !dagCheckerParent->EvaluatingLinkLibraries() was written that way to avoid a nullptr dereference, but is actually meant to say "is not evaluating link libraries". That can also be true when there is no `dagCheckerParent`, such as when evaluating a generator expression outside of usage requirements, e.g., for `add_custom_target`. The original commit tried to account for that by duplicating the implementation in another code path, but that did not work in all cases. Fix the condition, remove the duplication, and enable tests for the now-working cases. --- Source/cmGeneratorExpressionNode.cxx | 23 +---------------------- Tests/CompatibleInterface/CMakeLists.txt | 5 ++--- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 65da33c..5c97e22 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -2980,29 +2980,8 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode context->Config); return propContent ? propContent : ""; } - // FIXME: This duplicates the COMPATIBLE_INTERFACE_NUMBER_{MAX,MIN} - // evaluation below because it is not reached when evaluating outside of - // usage requirements, such as in add_custom_target, because there is no - // dagCheckerParent. - if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName, - context->Config)) { - context->HadContextSensitiveCondition = true; - const char* propContent = - target->GetLinkInterfaceDependentNumberMinProperty(propertyName, - context->Config); - return propContent ? propContent : ""; - } - if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName, - context->Config)) { - context->HadContextSensitiveCondition = true; - const char* propContent = - target->GetLinkInterfaceDependentNumberMaxProperty(propertyName, - context->Config); - return propContent ? propContent : ""; - } } - if (!target->IsImported() && dagCheckerParent && - !dagCheckerParent->EvaluatingLinkLibraries()) { + if (!evaluatingLinkLibraries && !target->IsImported()) { if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName, context->Config)) { context->HadContextSensitiveCondition = true; diff --git a/Tests/CompatibleInterface/CMakeLists.txt b/Tests/CompatibleInterface/CMakeLists.txt index 4927329..5d57ce4 100644 --- a/Tests/CompatibleInterface/CMakeLists.txt +++ b/Tests/CompatibleInterface/CMakeLists.txt @@ -228,9 +228,8 @@ add_custom_target(check ALL VERBATIM "ON" "$" "prop4" "$" - #FIXME: These two cases do not work correctly. - #"6" "$" - #"4" "$" + "6" "$" + "4" "$" "ON" "$" "prop4" "$" -- cgit v0.12