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-LINK_LANGUAGE | |
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-LINK_LANGUAGE')
15 files changed, 188 insertions, 0 deletions
diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/CMakeLists.txt b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/CMakeLists.txt new file mode 100644 index 0000000..9cf020f --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/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-LINK_LANGUAGE/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/RunCMakeTest.cmake new file mode 100644 index 0000000..487bf25 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/RunCMakeTest.cmake @@ -0,0 +1,41 @@ +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() + +run_cmake(genex_LINK_LANGUAGE-bad-usage) + +if (RunCMake_GENERATOR MATCHES "Makefiles|Ninja|Visual Studio|Xcode|Watcom WMake") + + run_cmake(genex_LINK_LANGUAGE-bad-mix-lang) + + set(RunCMake_TEST_OUTPUT_MERGE TRUE) + if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Release) + endif() + + run_cmake(genex_LINK_LANGUAGE) + + run_cmake_target(genex_LINK_LANGUAGE lib LinkLibraries_lib --config Release) + run_cmake_target(genex_LINK_LANGUAGE lib2 LinkLibraries_lib2 --config Release) + run_cmake_target(genex_LINK_LANGUAGE lib3 LinkLibraries_lib3 --config Release) + run_cmake_target(genex_LINK_LANGUAGE exe LinkLibraries_exe --config Release) + run_cmake_target(genex_LINK_LANGUAGE C_import LinkLibraries_C_import --config Release) + run_cmake_target(genex_LINK_LANGUAGE CXX_import LinkLibraries_CXX_import --config Release) + run_cmake_target(genex_LINK_LANGUAGE C_interface LinkLibraries_C_interface --config Release) + run_cmake_target(genex_LINK_LANGUAGE CXX_interface LinkLibraries_CXX_interface --config Release) + run_cmake_target(genex_LINK_LANGUAGE C_interface2 LinkLibraries_C_interface2 --config Release) + run_cmake_target(genex_LINK_LANGUAGE CXX_interface2 LinkLibraries_CXX_interface2 --config Release) + run_cmake_target(genex_LINK_LANGUAGE C_static LinkLibraries_C_static --config Release) + run_cmake_target(genex_LINK_LANGUAGE CXX_static LinkLibraries_CXX_static --config Release) + + unset(RunCMake_TEST_OPTIONS) + unset(RunCMake_TEST_OUTPUT_MERGE) + +endif() diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/empty.c b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/empty.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/empty.c diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/func.c b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/func.c new file mode 100644 index 0000000..415a9bf --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/func.c @@ -0,0 +1,7 @@ + +#if defined(_WIN32) +__declspec(dllexport) +#endif + void func_c() +{ +} diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/func.cxx b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/func.cxx new file mode 100644 index 0000000..a12caca --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/func.cxx @@ -0,0 +1,7 @@ + +#if defined(_WIN32) +__declspec(dllexport) +#endif + void func_cxx() +{ +} diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-mix-lang-result.txt b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-mix-lang-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-mix-lang-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-mix-lang-stderr.txt b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-mix-lang-stderr.txt new file mode 100644 index 0000000..2ecdc0c --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-mix-lang-stderr.txt @@ -0,0 +1,2 @@ +CMake Error: Evaluation of \$<LINK_LANGUAGE:...> or \$<LINK_LAND_AND_ID:...> changes +the linker language for target "LinkLibraries_bad_mix_languages" \(from 'C' to 'CXX'\) which is invalid. diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-mix-lang.cmake b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-mix-lang.cmake new file mode 100644 index 0000000..e8efa75 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-mix-lang.cmake @@ -0,0 +1,8 @@ + +enable_language(C) +enable_language(CXX) + +add_library(static_CXX STATIC func.cxx) + +add_executable(LinkLibraries_bad_mix_languages main.c) +target_link_libraries (LinkLibraries_bad_mix_languages PRIVATE $<$<LINK_LANGUAGE:C>:static_CXX>) diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-usage-result.txt b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-usage-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-usage-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-usage-stderr.txt b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-usage-stderr.txt new file mode 100644 index 0000000..469f1fe --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-usage-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at genex_LINK_LANGUAGE-bad-usage.cmake:4 \(target_link_libraries\): + Error evaluating generator expression: + + \$<LINK_LANGUAGE> + + \$<LINK_LANGUAGE> is not supported in link libraries expression. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-usage.cmake b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-usage.cmake new file mode 100644 index 0000000..81cfb0c --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE-bad-usage.cmake @@ -0,0 +1,4 @@ +enable_language(C) + +add_library(simple SHARED empty.c) +target_link_libraries(simple PRIVATE lib$<LINK_LANGUAGE>) diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE.cmake b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE.cmake new file mode 100644 index 0000000..f3fe955 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/genex_LINK_LANGUAGE.cmake @@ -0,0 +1,72 @@ + +cmake_minimum_required(VERSION 3.16...3.17) + +enable_language(C) +enable_language(CXX) + +add_library(shared_C SHARED func.c) +add_library(shared_CXX SHARED func.cxx) + + +add_library(static1_C STATIC empty.c) +target_link_libraries (static1_C INTERFACE $<$<LINK_LANGUAGE:C>:shared_C>) + +add_library(static2_C STATIC empty.c) +target_link_libraries (static2_C PRIVATE $<$<LINK_LANGUAGE:C>:shared_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 STATIC IMPORTED) +set_property(TARGET import PROPERTY IMPORTED_LOCATION "${binary_dir}/${CMAKE_STATIC_LIBRARY_PREFIX}static1_C${CMAKE_STATIC_LIBRARY_SUFFIX}") +target_link_libraries (import INTERFACE $<$<LINK_LANGUAGE:C>:shared_C>) +target_link_libraries (import INTERFACE $<$<LINK_LANGUAGE:CXX>:shared_CXX>) + + +add_library(interface INTERFACE) +target_link_libraries (interface INTERFACE $<$<LINK_LANGUAGE:C>:shared_C> + $<$<LINK_LANGUAGE:CXX>:shared_CXX>) + + +add_library(interface2 INTERFACE) +target_link_libraries (interface2 INTERFACE import) + + +add_library(static3 STATIC empty.c) +target_link_libraries (static3 PRIVATE interface) + + +add_library(LinkLibraries_lib SHARED lib.c) +target_link_libraries (LinkLibraries_lib PRIVATE $<$<LINK_LANGUAGE:C>:shared_C>) + +add_library(LinkLibraries_lib2 SHARED lib.c) +target_link_libraries (LinkLibraries_lib2 PRIVATE $<$<LINK_LANGUAGE:C>:static1_C>) + +add_library(LinkLibraries_lib3 SHARED lib.c) +target_link_libraries (LinkLibraries_lib3 PRIVATE $<$<LINK_LANGUAGE:C>:static2_C>) + +add_executable(LinkLibraries_exe main.c) +target_link_libraries (LinkLibraries_exe PRIVATE $<$<LINK_LANGUAGE:C>:shared_C>) + +add_executable(LinkLibraries_C_import main.c) +target_link_libraries (LinkLibraries_C_import PRIVATE import) +add_executable(LinkLibraries_CXX_import main.cxx) +target_link_libraries (LinkLibraries_CXX_import PRIVATE import) + +add_executable(LinkLibraries_C_interface main.c) +target_link_libraries (LinkLibraries_C_interface PRIVATE interface) +add_executable(LinkLibraries_CXX_interface main.cxx) +target_link_libraries (LinkLibraries_CXX_interface PRIVATE interface) + +add_executable(LinkLibraries_C_interface2 main.c) +target_link_libraries (LinkLibraries_C_interface2 PRIVATE interface2) +add_executable(LinkLibraries_CXX_interface2 main.cxx) +target_link_libraries (LinkLibraries_CXX_interface2 PRIVATE interface2) + +add_executable(LinkLibraries_C_static main.c) +target_link_libraries (LinkLibraries_C_static PRIVATE static3) +add_executable(LinkLibraries_CXX_static main.cxx) +target_link_libraries (LinkLibraries_CXX_static PRIVATE static3) diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/lib.c b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/lib.c new file mode 100644 index 0000000..b2d1b66 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/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-LINK_LANGUAGE/main.c b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/main.c new file mode 100644 index 0000000..a908dea --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/main.c @@ -0,0 +1,12 @@ + +#if defined(_WIN32) +__declspec(dllimport) +#endif + void func_c(); + +int main() +{ + func_c(); + + return 0; +} diff --git a/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/main.cxx b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/main.cxx new file mode 100644 index 0000000..ffaa3b4 --- /dev/null +++ b/Tests/RunCMake/target_link_libraries-LINK_LANGUAGE/main.cxx @@ -0,0 +1,12 @@ + +#if defined(_WIN32) +__declspec(dllimport) +#endif + void func_cxx(); + +int main() +{ + func_cxx(); + + return 0; +} |