diff options
author | Brad King <brad.king@kitware.com> | 2022-03-25 13:12:33 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-03-25 13:12:39 (GMT) |
commit | 25b9fb0b1adcff94534443ada1ba27e564a4ead7 (patch) | |
tree | 79b765bd3d03a04a37d1263943a7abeed2a1b442 /Tests | |
parent | 96420a4afdd1467e05384dd8ba83e73154388fb7 (diff) | |
parent | cf312a2e5423c49cc5da446f5407a6f4a596a3cb (diff) | |
download | CMake-25b9fb0b1adcff94534443ada1ba27e564a4ead7.zip CMake-25b9fb0b1adcff94534443ada1ba27e564a4ead7.tar.gz CMake-25b9fb0b1adcff94534443ada1ba27e564a4ead7.tar.bz2 |
Merge topic 'link-interface-direct'
cf312a2e54 LINK_LIBRARIES: Add support for LINK_ONLY genex
41a6b4a53b INTERFACE_LINK_LIBRARIES_DIRECT: Honor link dependencies through LINK_ONLY
73337cb383 LINK_LIBRARIES: Evaluate separately for linking and usage requirements
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !7107
Diffstat (limited to 'Tests')
7 files changed, 68 insertions, 6 deletions
diff --git a/Tests/InterfaceLinkLibraries/CMakeLists.txt b/Tests/InterfaceLinkLibraries/CMakeLists.txt index 9e14c44..07a747b 100644 --- a/Tests/InterfaceLinkLibraries/CMakeLists.txt +++ b/Tests/InterfaceLinkLibraries/CMakeLists.txt @@ -59,3 +59,12 @@ set_property(TARGET bar_static_private APPEND PROPERTY INTERFACE_LINK_LIBRARIES add_executable(InterfaceLinkLibraries main_vs6_4.cpp) set_property(TARGET InterfaceLinkLibraries APPEND PROPERTY LINK_LIBRARIES bar_static_private) + +add_library(foo_link_only STATIC foo_link_only.c) +target_compile_definitions(foo_link_only PUBLIC FOO_LINK_ONLY) +add_executable(use_foo_link_only_CMP0131_OLD use_foo_link_only.c) +target_link_libraries(use_foo_link_only_CMP0131_OLD PRIVATE "$<LINK_ONLY:foo_link_only>") +target_compile_definitions(use_foo_link_only_CMP0131_OLD PRIVATE EXPECT_FOO_LINK_ONLY) +cmake_policy(SET CMP0131 NEW) +add_executable(use_foo_link_only_CMP0131_NEW use_foo_link_only.c) +target_link_libraries(use_foo_link_only_CMP0131_NEW PRIVATE "$<LINK_ONLY:foo_link_only>") diff --git a/Tests/InterfaceLinkLibraries/foo_link_only.c b/Tests/InterfaceLinkLibraries/foo_link_only.c new file mode 100644 index 0000000..9ca1c01 --- /dev/null +++ b/Tests/InterfaceLinkLibraries/foo_link_only.c @@ -0,0 +1,8 @@ +#ifndef FOO_LINK_ONLY +# error "FOO_LINK_ONLY incorrectly not defined" +#endif + +int foo_link_only(void) +{ + return 0; +} diff --git a/Tests/InterfaceLinkLibraries/use_foo_link_only.c b/Tests/InterfaceLinkLibraries/use_foo_link_only.c new file mode 100644 index 0000000..e975c1b --- /dev/null +++ b/Tests/InterfaceLinkLibraries/use_foo_link_only.c @@ -0,0 +1,16 @@ +#ifdef EXPECT_FOO_LINK_ONLY +# ifndef FOO_LINK_ONLY +# error "FOO_LINK_ONLY incorrectly not defined" +# endif +#else +# ifdef FOO_LINK_ONLY +# error "FOO_LINK_ONLY incorrectly defined" +# endif +#endif + +extern int foo_link_only(void); + +int main(void) +{ + return foo_link_only(); +} diff --git a/Tests/InterfaceLinkLibrariesDirect/CMakeLists.txt b/Tests/InterfaceLinkLibrariesDirect/CMakeLists.txt index b06a2fb..dec131d 100644 --- a/Tests/InterfaceLinkLibrariesDirect/CMakeLists.txt +++ b/Tests/InterfaceLinkLibrariesDirect/CMakeLists.txt @@ -52,7 +52,7 @@ set_property(TARGET A APPEND PROPERTY INTERFACE_LINK_LIBRARIES_DIRECT add_library(static_A_public STATIC static_A_public.c) target_link_libraries(static_A_public PUBLIC A) -# Uses A's usage requirements, but does not propagate them. +# Uses A's usage requirements, but propagates only the linking requirements. # Does not use the exe-only usage requirement. Does use the optional one. add_library(static_A_private STATIC static_A_private.c) target_link_libraries(static_A_private PRIVATE A) @@ -63,10 +63,15 @@ add_executable(exe_use_static_A_public exe_use_static_A_public.c) target_link_libraries(exe_use_static_A_public PRIVATE static_A_public) set_property(TARGET exe_use_static_A_public PROPERTY A_LINK_OPTIONAL 1) -# Does not use A's usage requirements. +# Does not use A's usage requirements, but does use its non-optional linking requirements. add_executable(exe_use_static_A_private exe_use_static_A_private.c) target_link_libraries(exe_use_static_A_private PRIVATE static_A_private) +# Uses A's usage requirements, including an optional one, but overrides the link ordering. +add_executable(exe_use_static_A_public_explicit exe_use_static_A_public_explicit.c) +target_link_libraries(exe_use_static_A_public_explicit PRIVATE static_A_public A direct_from_A direct_from_A_for_exe direct_from_A_optional) +set_property(TARGET exe_use_static_A_public_explicit PROPERTY A_LINK_OPTIONAL 1) + #---------------------------------------------------------------------------- # Test how original and injected dependencies get ordered. diff --git a/Tests/InterfaceLinkLibrariesDirect/exe_use_static_A_private.c b/Tests/InterfaceLinkLibrariesDirect/exe_use_static_A_private.c index 024e96e..12cf309 100644 --- a/Tests/InterfaceLinkLibrariesDirect/exe_use_static_A_private.c +++ b/Tests/InterfaceLinkLibrariesDirect/exe_use_static_A_private.c @@ -9,15 +9,15 @@ #endif extern void static_A_private(void); -extern void not_direct_from_A(void); -extern void not_direct_from_A_for_exe(void); +extern void direct_from_A(void); +extern void direct_from_A_for_exe(void); extern void not_direct_from_A_optional(void); int main(void) { static_A_private(); - not_direct_from_A(); - not_direct_from_A_for_exe(); + direct_from_A(); + direct_from_A_for_exe(); not_direct_from_A_optional(); return 0; } diff --git a/Tests/InterfaceLinkLibrariesDirect/exe_use_static_A_public_explicit.c b/Tests/InterfaceLinkLibrariesDirect/exe_use_static_A_public_explicit.c new file mode 100644 index 0000000..f698a24 --- /dev/null +++ b/Tests/InterfaceLinkLibrariesDirect/exe_use_static_A_public_explicit.c @@ -0,0 +1,23 @@ +#ifndef DEF_DIRECT_FROM_A +# error "DEF_DIRECT_FROM_A incorrectly not defined" +#endif +#ifndef DEF_DIRECT_FROM_A_FOR_EXE +# error "DEF_DIRECT_FROM_A_FOR_EXE incorrectly not defined" +#endif +#ifndef DEF_DIRECT_FROM_A_OPTIONAL +# error "DEF_DIRECT_FROM_A_OPTIONAL incorrectly not defined" +#endif + +extern void static_A_public(void); +extern void not_direct_from_A(void); +extern void not_direct_from_A_for_exe(void); +extern void not_direct_from_A_optional(void); + +int main(void) +{ + static_A_public(); + not_direct_from_A(); + not_direct_from_A_for_exe(); + not_direct_from_A_optional(); + return 0; +} diff --git a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt index 3846d7c..97c3394 100644 --- a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt +++ b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt @@ -35,6 +35,7 @@ \* CMP0112 \* CMP0113 \* CMP0119 + \* CMP0131 Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) |