summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/alias_targets
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2020-05-28 11:51:22 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2020-06-02 15:11:47 (GMT)
commit056489d567b657bd1ebeae8bf78f4937f900b2e0 (patch)
treed3800c8fdf726c1e04cf73e463b68861efe6abd3 /Tests/RunCMake/alias_targets
parent254f2b9058f814e952ef0178e13b3f98e8d216a1 (diff)
downloadCMake-056489d567b657bd1ebeae8bf78f4937f900b2e0.zip
CMake-056489d567b657bd1ebeae8bf78f4937f900b2e0.tar.gz
CMake-056489d567b657bd1ebeae8bf78f4937f900b2e0.tar.bz2
add_library/add_executable: allow local alias to imported targets
Fixes: #20641
Diffstat (limited to 'Tests/RunCMake/alias_targets')
-rw-r--r--Tests/RunCMake/alias_targets/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/alias_targets/get_property-subdir/CMakeLists.txt8
-rw-r--r--Tests/RunCMake/alias_targets/get_property.cmake59
-rw-r--r--Tests/RunCMake/alias_targets/imported-target-result.txt1
-rw-r--r--Tests/RunCMake/alias_targets/imported-target-stderr.txt17
-rw-r--r--Tests/RunCMake/alias_targets/imported-target-subdir1/CMakeLists.txt6
-rw-r--r--Tests/RunCMake/alias_targets/imported-target-subdir2/CMakeLists.txt20
-rw-r--r--Tests/RunCMake/alias_targets/imported-target.cmake11
8 files changed, 107 insertions, 16 deletions
diff --git a/Tests/RunCMake/alias_targets/RunCMakeTest.cmake b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake
index 676de08..4be1b9d 100644
--- a/Tests/RunCMake/alias_targets/RunCMakeTest.cmake
+++ b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake
@@ -12,6 +12,7 @@ run_cmake(imported-global-target)
run_cmake(imported-target)
run_cmake(alias-target)
run_cmake(set_property)
+run_cmake(get_property)
run_cmake(set_target_properties)
run_cmake(target_link_libraries)
run_cmake(target_include_directories)
diff --git a/Tests/RunCMake/alias_targets/get_property-subdir/CMakeLists.txt b/Tests/RunCMake/alias_targets/get_property-subdir/CMakeLists.txt
new file mode 100644
index 0000000..bfd9840
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/get_property-subdir/CMakeLists.txt
@@ -0,0 +1,8 @@
+
+
+add_library(alias::import-local-subdir ALIAS import-local)
+
+check_property (alias::import-local-subdir ALIASED_TARGET "import-local")
+check_property (alias::import-local-subdir IMPORTED "TRUE")
+check_property (alias::import-local-subdir ALIAS_GLOBAL "FALSE")
+check_property (alias::import-local-subdir IMPORT_LOCAL_PROPERTY "IMPORT_LOCAL")
diff --git a/Tests/RunCMake/alias_targets/get_property.cmake b/Tests/RunCMake/alias_targets/get_property.cmake
new file mode 100644
index 0000000..8a01c6f
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/get_property.cmake
@@ -0,0 +1,59 @@
+
+enable_language(CXX)
+
+function (check_property alias property value)
+ get_property (data TARGET ${alias} PROPERTY ${property})
+ if (NOT "${value}" STREQUAL "${data}")
+ message (SEND_ERROR "get_property(): Target property '${property}' from ALIAS '${alias}' has wrong value: '${data}' instead of '${value}'.")
+ endif()
+ get_target_property (data ${alias} ${property})
+ if (NOT "${value}" STREQUAL "${data}")
+ message (SEND_ERROR "get_target_property(): Target property '${property}' from ALIAS '${alias}' has wrong value: '${data}' instead of '${value}'.")
+ endif()
+endfunction()
+
+
+add_library(lib empty.cpp)
+set_property (TARGET lib PROPERTY LIB_PROPERTY "LIB")
+
+add_library(alias::lib ALIAS lib)
+
+check_property (alias::lib ALIASED_TARGET "lib")
+check_property (alias::lib IMPORTED "FALSE")
+check_property (alias::lib ALIAS_GLOBAL "TRUE")
+check_property (alias::lib LIB_PROPERTY "LIB")
+
+
+add_library(import-global SHARED IMPORTED GLOBAL)
+set_property (TARGET import-global PROPERTY IMPORT_GLOBAL_PROPERTY "IMPORT_GLOBAL")
+
+add_library(alias::import-global ALIAS import-global)
+
+check_property (alias::import-global ALIASED_TARGET "import-global")
+check_property (alias::import-global IMPORTED "TRUE")
+check_property (alias::import-global ALIAS_GLOBAL "TRUE")
+check_property (alias::import-global IMPORT_GLOBAL_PROPERTY "IMPORT_GLOBAL")
+
+
+add_library(import-local SHARED IMPORTED)
+set_property (TARGET import-local PROPERTY IMPORT_LOCAL_PROPERTY "IMPORT_LOCAL")
+
+add_library(alias::import-local ALIAS import-local)
+
+check_property (alias::import-local ALIASED_TARGET "import-local")
+check_property (alias::import-local IMPORTED "TRUE")
+check_property (alias::import-local ALIAS_GLOBAL "FALSE")
+check_property (alias::import-local IMPORT_LOCAL_PROPERTY "IMPORT_LOCAL")
+
+
+## upgrade imported target from local to global, alias stay local
+add_library(import-lib SHARED IMPORTED)
+add_library(alias::import-lib ALIAS import-lib)
+check_property (alias::import-lib IMPORTED_GLOBAL "FALSE")
+check_property (alias::import-lib ALIAS_GLOBAL "FALSE")
+set_property (TARGET import-lib PROPERTY IMPORTED_GLOBAL "TRUE")
+check_property (alias::import-lib IMPORTED_GLOBAL "TRUE")
+check_property (alias::import-lib ALIAS_GLOBAL "FALSE")
+
+
+add_subdirectory (get_property-subdir)
diff --git a/Tests/RunCMake/alias_targets/imported-target-result.txt b/Tests/RunCMake/alias_targets/imported-target-result.txt
deleted file mode 100644
index d00491f..0000000
--- a/Tests/RunCMake/alias_targets/imported-target-result.txt
+++ /dev/null
@@ -1 +0,0 @@
-1
diff --git a/Tests/RunCMake/alias_targets/imported-target-stderr.txt b/Tests/RunCMake/alias_targets/imported-target-stderr.txt
index 465de03..8259c80 100644
--- a/Tests/RunCMake/alias_targets/imported-target-stderr.txt
+++ b/Tests/RunCMake/alias_targets/imported-target-stderr.txt
@@ -1,15 +1,2 @@
-^CMake Error at imported-target.cmake:[0-9]+ \(add_executable\):
- add_executable cannot create ALIAS target \"alias-test-exe\" because target
- \"test-exe\" is imported but not globally visible.
-Call Stack \(most recent call first\):
- CMakeLists.txt:[0-9]+ \(include\)
-+
-'alias-test-exe' does not exist![?]
-*
-CMake Error at imported-target.cmake:[0-9]+ \(add_library\):
- add_library cannot create ALIAS target "alias-test-lib" because target
- "test-lib" is imported but not globally visible.
-Call Stack \(most recent call first\):
- CMakeLists.txt:[0-9]+ \(include\)
-+
-'alias-test-lib' does not exist![?]$
+^'alias-test-exe' is an alias for 'test-exe' and its name-property contains 'test-exe'.
+'alias-test-lib' is an alias for 'test-lib' and its name-property contains 'test-lib'.$
diff --git a/Tests/RunCMake/alias_targets/imported-target-subdir1/CMakeLists.txt b/Tests/RunCMake/alias_targets/imported-target-subdir1/CMakeLists.txt
new file mode 100644
index 0000000..bec05b3
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/imported-target-subdir1/CMakeLists.txt
@@ -0,0 +1,6 @@
+
+add_executable(alias-test-exe-subdir1 ALIAS test-exe)
+add_executable(alias-test-exe-local ALIAS test-exe)
+
+add_library(alias-test-lib-subdir1 ALIAS test-lib)
+add_library(alias-test-lib-local ALIAS test-lib)
diff --git a/Tests/RunCMake/alias_targets/imported-target-subdir2/CMakeLists.txt b/Tests/RunCMake/alias_targets/imported-target-subdir2/CMakeLists.txt
new file mode 100644
index 0000000..23c85ba
--- /dev/null
+++ b/Tests/RunCMake/alias_targets/imported-target-subdir2/CMakeLists.txt
@@ -0,0 +1,20 @@
+
+add_executable(alias-test-exe-subdir2 ALIAS test-exe)
+add_executable(alias-test-exe-local ALIAS test-exe)
+
+add_library(alias-test-lib-subdir2 ALIAS test-lib)
+add_library(alias-test-lib-local ALIAS test-lib)
+
+
+foreach (item IN ITEMS exe lib)
+ get_property (aliasedTarget TARGET alias-test-${item}-local PROPERTY ALIASED_TARGET)
+ if (NOT aliasedTarget STREQUAL "test-${item}")
+ message (SEND_ERROR "Wrong aliased target '${aliasedTarget}' for ALIAS 'alias-test-${item}-local'.")
+ endif()
+endforeach()
+
+foreach (item IN ITEMS exe lib)
+ if (TARGET alias-test-${item}-subdir1)
+ message (SEND_ERROR "ALIAS 'alias-test-${item}-subdir1' unexpectedly defined.")
+ endif()
+endforeach()
diff --git a/Tests/RunCMake/alias_targets/imported-target.cmake b/Tests/RunCMake/alias_targets/imported-target.cmake
index bb682fe..fa6f8d3 100644
--- a/Tests/RunCMake/alias_targets/imported-target.cmake
+++ b/Tests/RunCMake/alias_targets/imported-target.cmake
@@ -44,3 +44,14 @@ if(TARGET alias-test-lib)
else()
message("'alias-test-lib' does not exist!?")
endif()
+
+add_subdirectory (imported-target-subdir1)
+add_subdirectory (imported-target-subdir2)
+
+foreach (alias IN ITEMS exe-local lib-local
+ exe-subdir1 lib-subdir1
+ exe-subdir2 lib-subdir2)
+ if (TARGET alias-test-${alias})
+ message (SEND_ERROR "ALIAS 'alias-test-${alias}' unexpectedly defined.")
+ endif()
+endforeach()