diff options
author | Brad King <brad.king@kitware.com> | 2024-05-09 17:38:35 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-05-21 13:22:51 (GMT) |
commit | b9ee79b8a13abb957a176ff0b5eab1e5d33efc50 (patch) | |
tree | b3cb6301b38f03f953dcea719fa1dec800022ada /Tests/ExportImport | |
parent | 633afa0b2e27a6eca3a4b1e123a80cf4338fe509 (diff) | |
download | CMake-b9ee79b8a13abb957a176ff0b5eab1e5d33efc50.zip CMake-b9ee79b8a13abb957a176ff0b5eab1e5d33efc50.tar.gz CMake-b9ee79b8a13abb957a176ff0b5eab1e5d33efc50.tar.bz2 |
GenEx: Add support for custom transitive compile properties
Teach the `$<TARGET_PROPERTY:...>` generator expression to check for a
new `TRANSITIVE_COMPILE_PROPERTIES` property in the target's link
closure to enable transitive evaluation of named properties through
the link closure, excluding entries guarded by `$<LINK_ONLY:...>`.
Issue: #20416
Diffstat (limited to 'Tests/ExportImport')
-rw-r--r-- | Tests/ExportImport/Export/CMakeLists.txt | 25 | ||||
-rw-r--r-- | Tests/ExportImport/Export/testLib10.c | 4 | ||||
-rw-r--r-- | Tests/ExportImport/Export/testLib11.c | 6 | ||||
-rw-r--r-- | Tests/ExportImport/Import/A/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Tests/ExportImport/Import/A/imp_testLib10.c | 10 | ||||
-rw-r--r-- | Tests/ExportImport/Import/A/imp_testLib11.c | 18 |
6 files changed, 73 insertions, 0 deletions
diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index 0b7f739..20e7c08 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -116,6 +116,29 @@ target_link_libraries(testLib9 INTERFACE testLib9ObjIface PUBLIC testLib9ObjPub target_link_libraries(testLib9 PUBLIC Foo::Foo) cmake_policy(POP) +block() + cmake_policy(SET CMP0022 NEW) + add_library(testLib10 STATIC testLib10.c) + set_target_properties(testLib10 PROPERTIES + TRANSITIVE_COMPILE_PROPERTIES "CUSTOM_C" + INTERFACE_CUSTOM_C "TESTLIB10_INTERFACE_CUSTOM_C" + ) + target_compile_definitions(testLib10 INTERFACE + "$<TARGET_PROPERTY:CUSTOM_C>" + ) + add_library(testLib11 STATIC testLib11.c) + target_link_libraries(testLib11 PRIVATE testLib10) + set_target_properties(testLib11 PROPERTIES + INTERFACE_CUSTOM_C "TESTLIB11_INTERFACE_CUSTOM_C" + TRANSITIVE_COMPILE_PROPERTIES "CUSTOM_D" + INTERFACE_CUSTOM_D "TESTLIB11_INTERFACE_CUSTOM_D" + ) + target_compile_definitions(testLib11 INTERFACE + "$<TARGET_PROPERTY:CUSTOM_C>" + "$<TARGET_PROPERTY:CUSTOM_D>" + ) +endblock() + # Test using the target_link_libraries command to set the # LINK_INTERFACE_LIBRARIES* properties. We construct two libraries # providing the same two symbols. In each library one of the symbols @@ -574,6 +597,7 @@ install( testExe2lib testLib4lib testLib4libdbg testLib4libopt testLib6 testLib7 testLib8 testLib9 + testLib10 testLib11 testLibDeprecation testLibCycleA testLibCycleB testLibNoSONAME @@ -653,6 +677,7 @@ export(TARGETS testExe1 testLib1 testLib2 testLib3 export(TARGETS testExe2 testLib4 testLib5 testLib6 testLib7 testExe3 testExe4 testExe2lib testLib8 testLib9 testLib9ObjPub testLib9ObjPriv testLib9ObjIface + testLib10 testLib11 testLibDeprecation testLib4lib testLib4libdbg testLib4libopt testLibCycleA testLibCycleB diff --git a/Tests/ExportImport/Export/testLib10.c b/Tests/ExportImport/Export/testLib10.c new file mode 100644 index 0000000..d5ecb7f --- /dev/null +++ b/Tests/ExportImport/Export/testLib10.c @@ -0,0 +1,4 @@ +int testLib10(void) +{ + return 0; +} diff --git a/Tests/ExportImport/Export/testLib11.c b/Tests/ExportImport/Export/testLib11.c new file mode 100644 index 0000000..b288b29 --- /dev/null +++ b/Tests/ExportImport/Export/testLib11.c @@ -0,0 +1,6 @@ +int testLib10(void); + +int testLib11(void) +{ + return testLib10(); +} diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index 2a57633..632825d 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -328,6 +328,16 @@ foreach(vis Pub Priv Iface) endif() endforeach() +# Create executables to verify custom transitive properties. +add_executable(imp_testLib10 imp_testLib10.c) +target_link_libraries(imp_testLib10 PRIVATE exp_testLib10) +add_executable(imp_testLib10b imp_testLib10.c) +target_link_libraries(imp_testLib10b PRIVATE bld_testLib10) +add_executable(imp_testLib11 imp_testLib11.c) +target_link_libraries(imp_testLib11 PRIVATE exp_testLib11) +add_executable(imp_testLib11b imp_testLib11.c) +target_link_libraries(imp_testLib11b PRIVATE bld_testLib11) + #----------------------------------------------------------------------------- # Test that handling imported targets, including transitive dependencies, # works in CheckFunctionExists (...and hopefully all other try_compile() checks diff --git a/Tests/ExportImport/Import/A/imp_testLib10.c b/Tests/ExportImport/Import/A/imp_testLib10.c new file mode 100644 index 0000000..bac772c --- /dev/null +++ b/Tests/ExportImport/Import/A/imp_testLib10.c @@ -0,0 +1,10 @@ +#ifndef TESTLIB10_INTERFACE_CUSTOM_C +# error "TESTLIB10_INTERFACE_CUSTOM_C incorrectly not defined!" +#endif + +int testLib10(void); + +int main(void) +{ + return testLib10(); +} diff --git a/Tests/ExportImport/Import/A/imp_testLib11.c b/Tests/ExportImport/Import/A/imp_testLib11.c new file mode 100644 index 0000000..a17d7e7 --- /dev/null +++ b/Tests/ExportImport/Import/A/imp_testLib11.c @@ -0,0 +1,18 @@ +#ifdef TESTLIB10_INTERFACE_CUSTOM_C +# error "TESTLIB10_INTERFACE_CUSTOM_C incorrectly defined!" +#endif + +#ifdef TESTLIB11_INTERFACE_CUSTOM_C +# error "TESTLIB11_INTERFACE_CUSTOM_C incorrectly defined!" +#endif + +#ifndef TESTLIB11_INTERFACE_CUSTOM_D +# error "TESTLIB11_INTERFACE_CUSTOM_D incorrectly not defined!" +#endif + +int testLib11(void); + +int main(void) +{ + return testLib11(); +} |