summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/GenEx-TARGET_PROPERTY
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-11-15 15:53:49 (GMT)
committerBrad King <brad.king@kitware.com>2022-11-17 12:57:21 (GMT)
commit8437141b53919619f6d21f5f446d26df42373c68 (patch)
tree025fe7b9aea2bbdd4504304463ea7299bd4b4d9f /Tests/RunCMake/GenEx-TARGET_PROPERTY
parentd22a225251ebc10323e934a8790984dcbbb9b18a (diff)
downloadCMake-8437141b53919619f6d21f5f446d26df42373c68.zip
CMake-8437141b53919619f6d21f5f446d26df42373c68.tar.gz
CMake-8437141b53919619f6d21f5f446d26df42373c68.tar.bz2
Genex: Fix TARGET_PROPERTY lookup scope in transitive usage requirements
When `$<TARGET_PROPERTY:tgt,prop>` is used in an `INTERFACE_*` target property for usage requirements, it may be evaluated in the context of a dependent target in another directory. Look up the `tgt` name in the directory of the target whose property holds the expression so that imported targets isolated to that directory are visible. Fixes: #24163
Diffstat (limited to 'Tests/RunCMake/GenEx-TARGET_PROPERTY')
-rw-r--r--Tests/RunCMake/GenEx-TARGET_PROPERTY/RunCMakeTest.cmake7
-rw-r--r--Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope-build-stdout.txt6
-rw-r--r--Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope.c12
-rw-r--r--Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope.cmake19
-rw-r--r--Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope1/CMakeLists.txt15
-rw-r--r--Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope2/CMakeLists.txt10
6 files changed, 69 insertions, 0 deletions
diff --git a/Tests/RunCMake/GenEx-TARGET_PROPERTY/RunCMakeTest.cmake b/Tests/RunCMake/GenEx-TARGET_PROPERTY/RunCMakeTest.cmake
index ac0843e..b613ad1 100644
--- a/Tests/RunCMake/GenEx-TARGET_PROPERTY/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GenEx-TARGET_PROPERTY/RunCMakeTest.cmake
@@ -13,3 +13,10 @@ run_cmake(LinkImplementationCycle5)
run_cmake(LinkImplementationCycle6)
run_cmake(LOCATION)
run_cmake(SOURCES)
+
+block()
+ run_cmake(Scope)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Scope-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ run_cmake_command(Scope-build ${CMAKE_COMMAND} --build . --config Debug)
+endblock()
diff --git a/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope-build-stdout.txt b/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope-build-stdout.txt
new file mode 100644
index 0000000..fefad22
--- /dev/null
+++ b/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope-build-stdout.txt
@@ -0,0 +1,6 @@
+.*iface scope1: 'SCOPED_A_1;SCOPED_B_1'
+.*iface scope2: 'SCOPED_A_2'
+.*iface scope2 in scope1: 'SCOPED_A_2'
+.*custom scope1: 'SCOPED_A_1;SCOPED_B_1'
+.*custom scope2: 'SCOPED_A_2'
+.*custom scope2 in scope1: 'SCOPED_A_1'
diff --git a/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope.c b/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope.c
new file mode 100644
index 0000000..a4bec6f
--- /dev/null
+++ b/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope.c
@@ -0,0 +1,12 @@
+#ifndef SCOPED_A_1
+# error "SCOPED_A_1 not defined"
+#endif
+#ifndef SCOPED_B_1
+# error "SCOPED_B_1 not defined"
+#endif
+#ifndef SCOPED_A_2
+# error "SCOPED_A_2 not defined"
+#endif
+void Scope(void)
+{
+}
diff --git a/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope.cmake b/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope.cmake
new file mode 100644
index 0000000..48a878a
--- /dev/null
+++ b/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope.cmake
@@ -0,0 +1,19 @@
+enable_language(C)
+
+add_subdirectory(Scope1)
+add_subdirectory(Scope2)
+
+add_library(Scope Scope.c)
+target_link_libraries(Scope PRIVATE
+ scope1_iface
+ scope2_iface
+ )
+
+add_custom_target(Custom ALL VERBATIM
+ COMMAND ${CMAKE_COMMAND} -E echo "iface scope1: '$<TARGET_PROPERTY:scope1_iface,INTERFACE_COMPILE_DEFINITIONS>'"
+ COMMAND ${CMAKE_COMMAND} -E echo "iface scope2: '$<TARGET_PROPERTY:scope2_iface,INTERFACE_COMPILE_DEFINITIONS>'"
+ COMMAND ${CMAKE_COMMAND} -E echo "iface scope2 in scope1: '$<TARGET_GENEX_EVAL:scope1_iface,$<TARGET_PROPERTY:scope2_iface,INTERFACE_COMPILE_DEFINITIONS>>'"
+ COMMAND ${CMAKE_COMMAND} -E echo "custom scope1: '$<TARGET_GENEX_EVAL:scope1_iface,$<TARGET_PROPERTY:scope1_iface,CUSTOM_PROP>>'"
+ COMMAND ${CMAKE_COMMAND} -E echo "custom scope2: '$<TARGET_GENEX_EVAL:scope2_iface,$<TARGET_PROPERTY:scope2_iface,CUSTOM_PROP>>'"
+ COMMAND ${CMAKE_COMMAND} -E echo "custom scope2 in scope1: '$<TARGET_GENEX_EVAL:scope1_iface,$<TARGET_PROPERTY:scope2_iface,CUSTOM_PROP>>'"
+ )
diff --git a/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope1/CMakeLists.txt b/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope1/CMakeLists.txt
new file mode 100644
index 0000000..d546267
--- /dev/null
+++ b/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope1/CMakeLists.txt
@@ -0,0 +1,15 @@
+add_library(scopedA INTERFACE IMPORTED)
+set_property(TARGET scopedA PROPERTY INTERFACE_COMPILE_DEFINITIONS "SCOPED_A_1")
+
+add_library(scopedB INTERFACE IMPORTED)
+set_property(TARGET scopedB PROPERTY INTERFACE_COMPILE_DEFINITIONS "SCOPED_B_1")
+
+add_library(scope1_iface INTERFACE)
+set_property(TARGET scope1_iface PROPERTY INTERFACE_COMPILE_DEFINITIONS
+ "$<TARGET_PROPERTY:scopedA,INTERFACE_COMPILE_DEFINITIONS>"
+ "$<TARGET_PROPERTY:scopedB,INTERFACE_COMPILE_DEFINITIONS>"
+ )
+set_property(TARGET scope1_iface PROPERTY CUSTOM_PROP
+ "$<TARGET_PROPERTY:scopedA,INTERFACE_COMPILE_DEFINITIONS>"
+ "$<TARGET_PROPERTY:scopedB,INTERFACE_COMPILE_DEFINITIONS>"
+ )
diff --git a/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope2/CMakeLists.txt b/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope2/CMakeLists.txt
new file mode 100644
index 0000000..a6d7e6b
--- /dev/null
+++ b/Tests/RunCMake/GenEx-TARGET_PROPERTY/Scope2/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_library(scopedA INTERFACE IMPORTED)
+set_property(TARGET scopedA PROPERTY INTERFACE_COMPILE_DEFINITIONS "SCOPED_A_2")
+
+add_library(scope2_iface INTERFACE)
+set_property(TARGET scope2_iface PROPERTY INTERFACE_COMPILE_DEFINITIONS
+ "$<TARGET_PROPERTY:scopedA,INTERFACE_COMPILE_DEFINITIONS>"
+ )
+set_property(TARGET scope2_iface PROPERTY CUSTOM_PROP
+ "$<TARGET_PROPERTY:scopedA,INTERFACE_COMPILE_DEFINITIONS>"
+ )