diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2020-06-17 08:51:39 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-06-17 12:02:33 (GMT) |
commit | 0951b1fe072da311e9adb55337ef364e2b6c01d0 (patch) | |
tree | d913a6530d58ae2e9197614107143a4cf8f8ba39 /Tests/RunCMake/target_link_libraries-ALIAS | |
parent | 2ae33f7ace90c0fbe0fae43de5a55d5d31dde4bc (diff) | |
download | CMake-0951b1fe072da311e9adb55337ef364e2b6c01d0.zip CMake-0951b1fe072da311e9adb55337ef364e2b6c01d0.tar.gz CMake-0951b1fe072da311e9adb55337ef364e2b6c01d0.tar.bz2 |
Tests: Split RunCMake.target_link_libraries test
Fixes: #20836
Diffstat (limited to 'Tests/RunCMake/target_link_libraries-ALIAS')
6 files changed, 91 insertions, 0 deletions
diff --git a/Tests/RunCMake/target_link_libraries-ALIAS/AliasTargets.cmake b/Tests/RunCMake/target_link_libraries-ALIAS/AliasTargets.cmake new file mode 100644 index 0000000..73f8a7d --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-ALIAS/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-ALIAS/CMakeLists.txt b/Tests/RunCMake/target_link_libraries-ALIAS/CMakeLists.txt new file mode 100644 index 0000000..9cf020f --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-ALIAS/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.1) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE) diff --git a/Tests/RunCMake/target_link_libraries-ALIAS/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries-ALIAS/RunCMakeTest.cmake new file mode 100644 index 0000000..4d24a6e --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-ALIAS/RunCMakeTest.cmake @@ -0,0 +1,23 @@ +include(RunCMake) + +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) diff --git a/Tests/RunCMake/target_link_libraries-ALIAS/func.c b/Tests/RunCMake/target_link_libraries-ALIAS/func.c new file mode 100644 index 0000000..415a9bf --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-ALIAS/func.c @@ -0,0 +1,7 @@ + +#if defined(_WIN32) +__declspec(dllexport) +#endif + void func_c() +{ +} diff --git a/Tests/RunCMake/target_link_libraries-ALIAS/lib.c b/Tests/RunCMake/target_link_libraries-ALIAS/lib.c new file mode 100644 index 0000000..b2d1b66 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-ALIAS/lib.c @@ -0,0 +1,10 @@ + +#if defined(_WIN32) +__declspec(dllimport) +#endif + void func_c(); + +void lib() +{ + func_c(); +} diff --git a/Tests/RunCMake/target_link_libraries-ALIAS/main.c b/Tests/RunCMake/target_link_libraries-ALIAS/main.c new file mode 100644 index 0000000..a908dea --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-ALIAS/main.c @@ -0,0 +1,12 @@ + +#if defined(_WIN32) +__declspec(dllimport) +#endif + void func_c(); + +int main() +{ + func_c(); + + return 0; +} |