LINK_LIBRARIES: Add support for LINK_ONLY genex

Previously we always used content guarded by `$<LINK_ONLY:...>`
in `LINK_LIBRARIES`, even when evaluating for non-linking usage
requirements.  Add a policy to honor `LINK_ONLY` in `LINK_LIBRARIES`
the same way we already do in `INTERFACE_LINK_LIBRARIES`.
This commit is contained in:
Brad King
2022-03-22 11:09:23 -04:00
parent 41a6b4a53b
commit cf312a2e54
10 changed files with 99 additions and 8 deletions

View File

@@ -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>")

View File

@@ -0,0 +1,8 @@
#ifndef FOO_LINK_ONLY
# error "FOO_LINK_ONLY incorrectly not defined"
#endif
int foo_link_only(void)
{
return 0;
}

View File

@@ -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();
}