summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/target_link_libraries
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/target_link_libraries
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/target_link_libraries')
-rw-r--r--Tests/RunCMake/target_link_libraries/AliasTargets.cmake36
-rw-r--r--Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake32
2 files changed, 59 insertions, 9 deletions
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)