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.
This commit is contained in:
Brad King
2024-04-11 13:37:46 -04:00
parent 061f7a6b97
commit c94cfe92eb
2 changed files with 3 additions and 25 deletions

View File

@@ -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;

View File

@@ -228,9 +228,8 @@ add_custom_target(check ALL VERBATIM
"ON" "$<TARGET_PROPERTY:static1,BOOL_PROP5>"
"prop4" "$<TARGET_PROPERTY:static1,STRING_PROP4>"
#FIXME: These two cases do not work correctly.
#"6" "$<TARGET_PROPERTY:static1,NUMBER_MIN_PROP6>"
#"4" "$<TARGET_PROPERTY:static1,NUMBER_MAX_PROP4>"
"6" "$<TARGET_PROPERTY:static1,NUMBER_MIN_PROP6>"
"4" "$<TARGET_PROPERTY:static1,NUMBER_MAX_PROP4>"
"ON" "$<TARGET_PROPERTY:object1,BOOL_PROP5>"
"prop4" "$<TARGET_PROPERTY:object1,STRING_PROP4>"