summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r--Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-ALIAS_GLOBAL-check.cmake6
-rw-r--r--Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-ALIAS_GLOBAL.cmake16
-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
-rw-r--r--Tests/RunCMake/target_link_libraries/AliasTargets.cmake36
-rw-r--r--Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake32
13 files changed, 189 insertions, 25 deletions
diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
index 24c3642..7d3c22b 100644
--- a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
@@ -111,6 +111,7 @@ run_cmake(TARGET_LINKER_FILE_BASE_NAME-non-valid-target)
run_cmake(TARGET_PROPERTY-INCLUDE_DIRECTORIES)
run_cmake(TARGET_PROPERTY-LOCATION)
run_cmake(TARGET_PROPERTY-SOURCES)
+run_cmake(TARGET_PROPERTY-ALIAS_GLOBAL)
run_cmake(LINK_ONLY-not-linking)
run_cmake(TARGET_EXISTS-no-arg)
run_cmake(TARGET_EXISTS-empty-arg)
diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-ALIAS_GLOBAL-check.cmake b/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-ALIAS_GLOBAL-check.cmake
new file mode 100644
index 0000000..0fbf837
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-ALIAS_GLOBAL-check.cmake
@@ -0,0 +1,6 @@
+file(STRINGS ${RunCMake_TEST_BINARY_DIR}/alias_global.txt alias_global)
+
+set(expected "TRUE(lib-global):TRUE;FALSE(lib-local):FALSE;TRUE(lib):FALSE")
+if(NOT alias_global STREQUAL expected)
+ set(RunCMake_TEST_FAILED "ALIAS_GLOBAL was:\n [[${alias_global}]]\nbut expected:\n [[${expected}]]")
+endif()
diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-ALIAS_GLOBAL.cmake b/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-ALIAS_GLOBAL.cmake
new file mode 100644
index 0000000..212c034
--- /dev/null
+++ b/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-ALIAS_GLOBAL.cmake
@@ -0,0 +1,16 @@
+
+cmake_minimum_required(VERSION 3.17)
+
+add_library(lib-global SHARED IMPORTED GLOBAL)
+add_library(alias-lib-global ALIAS lib-global)
+
+add_library(lib-local SHARED IMPORTED)
+add_library(alias-lib-local ALIAS lib-local)
+
+add_library(lib SHARED IMPORTED)
+add_library(alias-lib ALIAS lib)
+# switch from local to global
+set_property (TARGET lib PROPERTY IMPORTED_GLOBAL TRUE)
+
+
+file(GENERATE OUTPUT alias_global.txt CONTENT "$<TARGET_PROPERTY:lib-global,IMPORTED_GLOBAL>($<TARGET_PROPERTY:alias-lib-global,ALIASED_TARGET>):$<TARGET_PROPERTY:alias-lib-global,ALIAS_GLOBAL>\n$<TARGET_PROPERTY:lib-local,IMPORTED_GLOBAL>($<TARGET_PROPERTY:alias-lib-local,ALIASED_TARGET>):$<TARGET_PROPERTY:alias-lib-local,ALIAS_GLOBAL>\n$<TARGET_PROPERTY:lib,IMPORTED_GLOBAL>($<TARGET_PROPERTY:alias-lib,ALIASED_TARGET>):$<TARGET_PROPERTY:alias-lib,ALIAS_GLOBAL>\n")
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()
diff --git a/Tests/RunCMake/target_link_libraries/AliasTargets.cmake b/Tests/RunCMake/target_link_libraries/AliasTargets.cmake
new file mode 100644
index 0000000..73f8a7d
--- /dev/null
+++ b/Tests/RunCMake/target_link_libraries/AliasTargets.cmake
@@ -0,0 +1,36 @@
+
+cmake_minimum_required(VERSION 3.16...3.17)
+
+enable_language(C)
+
+add_library (func SHARED func.c)
+
+set (binary_dir "${CMAKE_BINARY_DIR}")
+get_property (is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if (is_multi_config)
+ string (APPEND binary_dir "/Release")
+endif()
+
+
+add_library(import-local SHARED IMPORTED)
+set_property(TARGET import-local PROPERTY IMPORTED_LOCATION "${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}func${CMAKE_SHARED_LIBRARY_SUFFIX}")
+set_property(TARGET import-local PROPERTY IMPORTED_IMPLIB "${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}func${CMAKE_IMPORT_LIBRARY_SUFFIX}")
+add_library(alias-local ALIAS import-local)
+
+add_library (lib-local SHARED lib.c)
+target_link_libraries (lib-local PRIVATE import-local)
+
+add_executable (main-local main.c)
+target_link_libraries (main-local PRIVATE import-local)
+
+
+add_library(import-global SHARED IMPORTED GLOBAL)
+set_property(TARGET import-global PROPERTY IMPORTED_LOCATION "${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}func${CMAKE_SHARED_LIBRARY_SUFFIX}")
+set_property(TARGET import-global PROPERTY IMPORTED_IMPLIB "${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}func${CMAKE_IMPORT_LIBRARY_SUFFIX}")
+add_library(alias-global ALIAS import-global)
+
+add_library (lib-global SHARED lib.c)
+target_link_libraries (lib-global PRIVATE import-global)
+
+add_executable (main-global main.c)
+target_link_libraries (main-global PRIVATE import-global)
diff --git a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
index dfa71dd..1f4077c 100644
--- a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
+++ b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
@@ -30,6 +30,29 @@ run_cmake(StaticPrivateDepNotExported)
run_cmake(StaticPrivateDepNotTarget)
run_cmake(UNKNOWN-IMPORTED-GLOBAL)
run_cmake(empty_keyword_args)
+
+macro(run_cmake_target test subtest target)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ run_cmake_command(${test}-${subtest} ${CMAKE_COMMAND} --build . --target ${target} ${ARGN})
+
+ unset(RunCMake_TEST_BINARY_DIR)
+ unset(RunCMake_TEST_NO_CLEAN)
+endmacro()
+
+set(RunCMake_TEST_OUTPUT_MERGE TRUE)
+if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Release)
+endif()
+run_cmake(AliasTargets)
+run_cmake_target(AliasTargets func func --config Release)
+run_cmake_target(AliasTargets lib-local lib-local --config Release)
+run_cmake_target(AliasTargets main-local main-local --config Release)
+run_cmake_target(AliasTargets lib-global lib-global --config Release)
+run_cmake_target(AliasTargets main-global main-global --config Release)
+unset(RunCMake_TEST_OPTIONS)
+unset(RunCMake_TEST_OUTPUT_MERGE)
+
run_cmake(genex_LINK_LANGUAGE-bad-usage)
if (RunCMake_GENERATOR MATCHES "Makefiles|Ninja|Visual Studio|Xcode|Watcom WMake")
@@ -37,15 +60,6 @@ if (RunCMake_GENERATOR MATCHES "Makefiles|Ninja|Visual Studio|Xcode|Watcom WMake
run_cmake(genex_LINK_LANGUAGE-bad-mix-lang)
run_cmake(genex_LINK_LANG_AND_ID-bad-mix-lang)
- macro(run_cmake_target test subtest target)
- set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
- set(RunCMake_TEST_NO_CLEAN 1)
- run_cmake_command(${test}-${subtest} ${CMAKE_COMMAND} --build . --target ${target} ${ARGN})
-
- unset(RunCMake_TEST_BINARY_DIR)
- unset(RunCMake_TEST_NO_CLEAN)
- endmacro()
-
set(RunCMake_TEST_OUTPUT_MERGE TRUE)
if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Release)