Merge topic 'genex-compatible-interface'

c94cfe92eb GenEx: Fix COMPATIBLE_INTERFACE_ evaluation outside usage requirements
061f7a6b97 GenEx: Remove redundant condition in COMPATIBLE_INTERFACE_ evaluation
86f99c5f6d GenEx: Add COMPATIBLE_INTERFACE_ implementation comments
541a788264 Tests: Add COMPATIBLE_INTERFACE_ cases outside usage requirements
5ebcf96170 Tests: Add COMPATIBLE_INTERFACE_ cases for library targets
f4249cf86f Tests: Add COMPATIBLE_INTERFACE_NUMBER_{MAX,MIN} transitive-only cases

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9423
This commit is contained in:
Brad King
2024-04-12 13:30:35 +00:00
committed by Kitware Robot
3 changed files with 245 additions and 28 deletions
+18 -22
View File
@@ -2950,8 +2950,20 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
return std::string();
}
if (!haveProp && !target->IsImported() &&
target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
// Properties named by COMPATIBLE_INTERFACE_ properties combine over
// the transitive link closure as a single order-independent value.
// Imported targets do not themselves have a defined value for these
// properties, but they can contribute to the value of a non-imported
// dependent.
//
// For COMPATIBLE_INTERFACE_{BOOL,STRING}:
// * If set on this target, use the value directly. It is checked
// elsewhere for consistency over the transitive link closure.
// * If not set on this target, compute the value from the closure.
//
// For COMPATIBLE_INTERFACE_NUMBER_{MAX,MIN} we always compute the value
// from this target and the transitive link closure to get the max or min.
if (!haveProp && !target->IsImported()) {
if (target->IsLinkInterfaceDependentBoolProperty(propertyName,
context->Config)) {
context->HadContextSensitiveCondition = true;
@@ -2968,6 +2980,8 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
context->Config);
return propContent ? propContent : "";
}
}
if (!evaluatingLinkLibraries && !target->IsImported()) {
if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
context->Config)) {
context->HadContextSensitiveCondition = true;
@@ -2986,26 +3000,8 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
}
}
if (!target->IsImported() && dagCheckerParent &&
!dagCheckerParent->EvaluatingLinkLibraries()) {
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 : "";
}
}
// Some properties, such as usage requirements, combine over the
// transitive link closure as an ordered list.
if (!interfacePropertyName.empty()) {
result = cmGeneratorExpression::StripEmptyListElements(
this->EvaluateDependentExpression(result, context->LG, context, target,
+117 -4
View File
@@ -13,12 +13,14 @@ set_property(TARGET iface1 APPEND PROPERTY
BOOL_PROP2
BOOL_PROP3
BOOL_PROP4
BOOL_PROP5
)
set_property(TARGET iface1 APPEND PROPERTY
COMPATIBLE_INTERFACE_STRING
STRING_PROP1
STRING_PROP2
STRING_PROP3
STRING_PROP4
)
set_property(TARGET iface1 APPEND PROPERTY
COMPATIBLE_INTERFACE_NUMBER_MIN
@@ -26,30 +28,40 @@ set_property(TARGET iface1 APPEND PROPERTY
NUMBER_MIN_PROP2
NUMBER_MIN_PROP3
NUMBER_MIN_PROP4
NUMBER_MIN_PROP5
NUMBER_MIN_PROP6
)
set_property(TARGET iface1 APPEND PROPERTY
COMPATIBLE_INTERFACE_NUMBER_MAX
NUMBER_MAX_PROP1
NUMBER_MAX_PROP2
NUMBER_MAX_PROP3
NUMBER_MAX_PROP4
)
set(CMAKE_DEBUG_TARGET_PROPERTIES
BOOL_PROP1 BOOL_PROP2 BOOL_PROP3 BOOL_PROP4
STRING_PROP1 STRING_PROP2 STRING_PROP3
NUMBER_MIN_PROP1 NUMBER_MIN_PROP2 NUMBER_MIN_PROP3 NUMBER_MIN_PROP4
NUMBER_MAX_PROP1 NUMBER_MAX_PROP2
BOOL_PROP1 BOOL_PROP2 BOOL_PROP3 BOOL_PROP4 BOOL_PROP5
STRING_PROP1 STRING_PROP2 STRING_PROP3 STRING_PROP4
NUMBER_MIN_PROP1 NUMBER_MIN_PROP2 NUMBER_MIN_PROP3 NUMBER_MIN_PROP4 NUMBER_MIN_PROP5 NUMBER_MIN_PROP6
NUMBER_MAX_PROP1 NUMBER_MAX_PROP2 NUMBER_MAX_PROP3 NUMBER_MAX_PROP4
)
set_property(TARGET iface1 PROPERTY INTERFACE_BOOL_PROP1 ON)
set_property(TARGET iface1 PROPERTY INTERFACE_BOOL_PROP2 ON)
set_property(TARGET iface1 PROPERTY INTERFACE_BOOL_PROP5 ON)
set_property(TARGET iface1 PROPERTY INTERFACE_STRING_PROP1 prop1)
set_property(TARGET iface1 PROPERTY INTERFACE_STRING_PROP2 prop2)
set_property(TARGET iface1 PROPERTY INTERFACE_STRING_PROP4 prop4)
set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP1 100)
set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP2 200)
set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP3 0x10)
set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP4 0x10)
set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP5 5)
set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MIN_PROP6 6)
set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MAX_PROP1 100)
set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MAX_PROP2 200)
set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MAX_PROP3 3)
set_property(TARGET iface1 PROPERTY INTERFACE_NUMBER_MAX_PROP4 4)
add_executable(CompatibleInterface main.cpp)
target_link_libraries(CompatibleInterface iface1)
@@ -86,8 +98,48 @@ target_compile_definitions(CompatibleInterface
$<$<STREQUAL:$<TARGET_PROPERTY:NUMBER_MIN_PROP2>,200>:NUMBER_MIN_PROP2=200>
$<$<EQUAL:$<TARGET_PROPERTY:NUMBER_MIN_PROP3>,0xA>:NUMBER_MIN_PROP3=0xA>
$<$<STREQUAL:$<TARGET_PROPERTY:NUMBER_MIN_PROP4>,0x10>:NUMBER_MIN_PROP4=0x10>
$<$<STREQUAL:$<TARGET_PROPERTY:NUMBER_MIN_PROP5>,5>:NUMBER_MIN_PROP5=5>
$<$<STREQUAL:$<TARGET_PROPERTY:NUMBER_MAX_PROP1>,100>:NUMBER_MAX_PROP1=100>
$<$<STREQUAL:$<TARGET_PROPERTY:NUMBER_MAX_PROP2>,250>:NUMBER_MAX_PROP2=250>
$<$<STREQUAL:$<TARGET_PROPERTY:NUMBER_MAX_PROP3>,3>:NUMBER_MAX_PROP3=3>
# Static libraries compute COMPATIBLE_INTERFACE_ properties transitively.
$<$<BOOL:$<TARGET_PROPERTY:static1,BOOL_PROP1>>:STATIC1_BOOL_PROP1>
$<$<STREQUAL:$<TARGET_PROPERTY:static1,STRING_PROP1>,prop1>:STATIC1_STRING_PROP1>
$<$<EQUAL:$<TARGET_PROPERTY:static1,NUMBER_MAX_PROP3>,3>:STATIC1_NUMBER_MAX_PROP3>
$<$<EQUAL:$<TARGET_PROPERTY:static1,NUMBER_MIN_PROP5>,5>:STATIC1_NUMBER_MIN_PROP5>
# Object libraries do not compute COMPATIBLE_INTERFACE_ properties transitively.
$<$<NOT:$<STREQUAL:$<TARGET_PROPERTY:object1,BOOL_PROP1>,>>:OBJECT1_BOOL_PROP1>
$<$<NOT:$<STREQUAL:$<TARGET_PROPERTY:object1,STRING_PROP1>,>>:OBJECT1_STRING_PROP1>
$<$<NOT:$<STREQUAL:$<TARGET_PROPERTY:object1,NUMBER_MAX_PROP3>,>>:OBJECT1_NUMBER_MAX_PROP3>
$<$<NOT:$<STREQUAL:$<TARGET_PROPERTY:object1,NUMBER_MIN_PROP5>,>>:OBJECT1_NUMBER_MIN_PROP5>
# Interface libraries do not compute COMPATIBLE_INTERFACE_ properties transitively.
$<$<NOT:$<STREQUAL:$<TARGET_PROPERTY:iface3,BOOL_PROP1>,>>:IFACE3_BOOL_PROP1>
$<$<NOT:$<STREQUAL:$<TARGET_PROPERTY:iface3,STRING_PROP1>,>>:IFACE3_STRING_PROP1>
$<$<NOT:$<STREQUAL:$<TARGET_PROPERTY:iface3,NUMBER_MAX_PROP3>,>>:IFACE3_NUMBER_MAX_PROP3>
$<$<NOT:$<STREQUAL:$<TARGET_PROPERTY:iface3,NUMBER_MIN_PROP5>,>>:IFACE3_NUMBER_MIN_PROP5>
# Static libraries compute COMPATIBLE_INTERFACE_ properties transitively.
$<$<BOOL:$<TARGET_PROPERTY:static1,BOOL_PROP5>>:STATIC1_BOOL_PROP5>
$<$<STREQUAL:$<TARGET_PROPERTY:static1,STRING_PROP4>,prop4>:STATIC1_STRING_PROP4>
$<$<EQUAL:$<TARGET_PROPERTY:static1,NUMBER_MIN_PROP6>,6>:STATIC1_NUMBER_MIN_PROP6>
$<$<EQUAL:$<TARGET_PROPERTY:static1,NUMBER_MAX_PROP4>,4>:STATIC1_NUMBER_MAX_PROP4>
# Object libraries do not compute COMPATIBLE_INTERFACE_ properties transitively,
# but can have properties set on them.
$<$<BOOL:$<TARGET_PROPERTY:object1,BOOL_PROP5>>:OBJECT1_BOOL_PROP5>
$<$<STREQUAL:$<TARGET_PROPERTY:object1,STRING_PROP4>,prop4>:OBJECT1_STRING_PROP4>
$<$<EQUAL:$<TARGET_PROPERTY:object1,NUMBER_MIN_PROP6>,7>:OBJECT1_NUMBER_MIN_PROP6>
$<$<EQUAL:$<TARGET_PROPERTY:object1,NUMBER_MAX_PROP4>,1>:OBJECT1_NUMBER_MAX_PROP4>
# Interface libraries do not compute COMPATIBLE_INTERFACE_ properties transitively,
# but can have properties set on them.
$<$<BOOL:$<TARGET_PROPERTY:iface3,BOOL_PROP5>>:IFACE3_BOOL_PROP5>
$<$<STREQUAL:$<TARGET_PROPERTY:iface3,STRING_PROP4>,prop4>:IFACE3_STRING_PROP4>
$<$<EQUAL:$<TARGET_PROPERTY:iface3,NUMBER_MIN_PROP6>,7>:IFACE3_NUMBER_MIN_PROP6>
$<$<EQUAL:$<TARGET_PROPERTY:iface3,NUMBER_MAX_PROP4>,1>:IFACE3_NUMBER_MAX_PROP4>
)
@@ -128,3 +180,64 @@ set_property(TARGET CompatibleInterface APPEND PROPERTY
COMPATIBLE_INTERFACE_BOOL
NON_RELEVANT_PROP
)
add_library(static1 STATIC foo.cpp)
set_property(TARGET static1 PROPERTY BOOL_PROP5 ON)
set_property(TARGET static1 PROPERTY STRING_PROP4 prop4)
set_property(TARGET static1 PROPERTY NUMBER_MIN_PROP6 7)
set_property(TARGET static1 PROPERTY NUMBER_MAX_PROP4 1)
target_link_libraries(static1 PUBLIC iface1)
add_library(object1 OBJECT foo.cpp)
set_property(TARGET object1 PROPERTY BOOL_PROP5 ON)
set_property(TARGET object1 PROPERTY STRING_PROP4 prop4)
set_property(TARGET object1 PROPERTY NUMBER_MIN_PROP6 7)
set_property(TARGET object1 PROPERTY NUMBER_MAX_PROP4 1)
target_link_libraries(object1 PUBLIC iface1)
add_library(iface3 INTERFACE)
set_property(TARGET iface3 PROPERTY BOOL_PROP5 ON)
set_property(TARGET iface3 PROPERTY STRING_PROP4 prop4)
set_property(TARGET iface3 PROPERTY NUMBER_MIN_PROP6 7)
set_property(TARGET iface3 PROPERTY NUMBER_MAX_PROP4 1)
target_link_libraries(iface3 INTERFACE iface1)
# Test COMPATIBLE_INTERFACE_* property evaluation outside of usage requirements.
add_custom_target(check ALL VERBATIM
COMMAND CompatibleInterface
# expect actual
"1" "$<TARGET_PROPERTY:CompatibleInterface,BOOL_PROP1>"
"prop1" "$<TARGET_PROPERTY:CompatibleInterface,STRING_PROP1>"
"3" "$<TARGET_PROPERTY:CompatibleInterface,NUMBER_MAX_PROP3>"
"5" "$<TARGET_PROPERTY:CompatibleInterface,NUMBER_MIN_PROP5>"
"1" "$<TARGET_PROPERTY:static1,BOOL_PROP1>"
"prop1" "$<TARGET_PROPERTY:static1,STRING_PROP1>"
"3" "$<TARGET_PROPERTY:static1,NUMBER_MAX_PROP3>"
"5" "$<TARGET_PROPERTY:static1,NUMBER_MIN_PROP5>"
"" "$<TARGET_PROPERTY:object1,BOOL_PROP1>"
"" "$<TARGET_PROPERTY:object1,STRING_PROP1>"
"" "$<TARGET_PROPERTY:object1,NUMBER_MAX_PROP3>"
"" "$<TARGET_PROPERTY:object1,NUMBER_MIN_PROP5>"
"" "$<TARGET_PROPERTY:iface3,BOOL_PROP1>"
"" "$<TARGET_PROPERTY:iface3,STRING_PROP1>"
"" "$<TARGET_PROPERTY:iface3,NUMBER_MAX_PROP3>"
"" "$<TARGET_PROPERTY:iface3,NUMBER_MIN_PROP5>"
"ON" "$<TARGET_PROPERTY:static1,BOOL_PROP5>"
"prop4" "$<TARGET_PROPERTY:static1,STRING_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>"
"7" "$<TARGET_PROPERTY:object1,NUMBER_MIN_PROP6>"
"1" "$<TARGET_PROPERTY:object1,NUMBER_MAX_PROP4>"
"ON" "$<TARGET_PROPERTY:iface3,BOOL_PROP5>"
"prop4" "$<TARGET_PROPERTY:iface3,STRING_PROP4>"
"7" "$<TARGET_PROPERTY:iface3,NUMBER_MIN_PROP6>"
"1" "$<TARGET_PROPERTY:iface3,NUMBER_MAX_PROP4>"
)
+110 -2
View File
@@ -1,3 +1,5 @@
#include <stdio.h>
#include <string.h>
#ifndef BOOL_PROP1
# error Expected BOOL_PROP1
@@ -23,6 +25,102 @@
# error Expected STRING_PROP3
#endif
#ifndef STATIC1_BOOL_PROP1
# error Expected STATIC1_BOOL_PROP1
#endif
#ifndef STATIC1_STRING_PROP1
# error Expected STATIC1_STRING_PROP1
#endif
#ifndef STATIC1_NUMBER_MAX_PROP3
# error Expected STATIC1_NUMBER_MAX_PROP3
#endif
#ifndef STATIC1_NUMBER_MIN_PROP5
# error Expected STATIC1_NUMBER_MIN_PROP5
#endif
#ifdef OBJECT1_BOOL_PROP1
# error Unexpected OBJECT1_BOOL_PROP1
#endif
#ifdef OBJECT1_STRING_PROP1
# error Unexpected OBJECT1_STRING_PROP1
#endif
#ifdef OBJECT1_NUMBER_MAX_PROP3
# error Unexpected OBJECT1_NUMBER_MAX_PROP3
#endif
#ifdef OBJECT1_NUMBER_MIN_PROP5
# error Unexpected OBJECT1_NUMBER_MIN_PROP5
#endif
#ifdef IFACE3_BOOL_PROP1
# error Unexpected IFACE3_BOOL_PROP1
#endif
#ifdef IFACE3_STRING_PROP1
# error Unexpected IFACE3_STRING_PROP1
#endif
#ifdef IFACE3_NUMBER_MAX_PROP3
# error Unexpected IFACE3_NUMBER_MAX_PROP3
#endif
#ifdef IFACE3_NUMBER_MIN_PROP5
# error Unexpected IFACE3_NUMBER_MIN_PROP5
#endif
#ifndef STATIC1_BOOL_PROP5
# error Expected STATIC1_BOOL_PROP5
#endif
#ifndef STATIC1_STRING_PROP4
# error Expected STATIC1_STRING_PROP4
#endif
#ifndef STATIC1_NUMBER_MIN_PROP6
# error Expected STATIC1_NUMBER_MIN_PROP6
#endif
#ifndef STATIC1_NUMBER_MAX_PROP4
# error Expected STATIC1_NUMBER_MAX_PROP4
#endif
#ifndef OBJECT1_BOOL_PROP5
# error Expected OBJECT1_BOOL_PROP5
#endif
#ifndef OBJECT1_STRING_PROP4
# error Expected OBJECT1_STRING_PROP4
#endif
#ifndef OBJECT1_NUMBER_MIN_PROP6
# error Expected OBJECT1_NUMBER_MIN_PROP6
#endif
#ifndef OBJECT1_NUMBER_MAX_PROP4
# error Expected OBJECT1_NUMBER_MAX_PROP4
#endif
#ifndef IFACE3_BOOL_PROP5
# error Expected IFACE3_BOOL_PROP5
#endif
#ifndef IFACE3_STRING_PROP4
# error Expected IFACE3_STRING_PROP4
#endif
#ifndef IFACE3_NUMBER_MIN_PROP6
# error Expected IFACE3_NUMBER_MIN_PROP6
#endif
#ifndef IFACE3_NUMBER_MAX_PROP4
# error Expected IFACE3_NUMBER_MAX_PROP4
#endif
template <bool test>
struct CMakeStaticAssert;
@@ -35,10 +133,12 @@ enum
{
NumericMaxTest1 = sizeof(CMakeStaticAssert<NUMBER_MAX_PROP1 == 100>),
NumericMaxTest2 = sizeof(CMakeStaticAssert<NUMBER_MAX_PROP2 == 250>),
NumericMaxTest3 = sizeof(CMakeStaticAssert<NUMBER_MAX_PROP3 == 3>),
NumericMinTest1 = sizeof(CMakeStaticAssert<NUMBER_MIN_PROP1 == 50>),
NumericMinTest2 = sizeof(CMakeStaticAssert<NUMBER_MIN_PROP2 == 200>),
NumericMinTest3 = sizeof(CMakeStaticAssert<NUMBER_MIN_PROP3 == 0xA>),
NumericMinTest4 = sizeof(CMakeStaticAssert<NUMBER_MIN_PROP4 == 0x10>)
NumericMinTest4 = sizeof(CMakeStaticAssert<NUMBER_MIN_PROP4 == 0x10>),
NumericMinTest5 = sizeof(CMakeStaticAssert<NUMBER_MIN_PROP5 == 5>)
};
#include "iface2.h"
@@ -51,6 +151,14 @@ __declspec(dllimport)
int main(int argc, char** argv)
{
int result = 0;
for (int i = 2; i < argc; i += 2) {
if (strcmp(argv[i - 1], argv[i]) != 0) {
fprintf(stderr, "Argument %d expected '%s' but got '%s'.\n", i,
argv[i - 1], argv[i]);
result = 1;
}
}
Iface2 if2;
return if2.foo() + foo() + bar();
return result + if2.foo() + foo() + bar();
}