summaryrefslogtreecommitdiffstats
path: root/Tests/InterfaceLinkLibraries
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-03-22 15:09:23 (GMT)
committerBrad King <brad.king@kitware.com>2022-03-24 12:23:55 (GMT)
commitcf312a2e5423c49cc5da446f5407a6f4a596a3cb (patch)
tree3bde9691ad13e40b06744b63a2c53dda75cbdf2a /Tests/InterfaceLinkLibraries
parent41a6b4a53ba844ef986b0bc4efe8938b97eea810 (diff)
downloadCMake-cf312a2e5423c49cc5da446f5407a6f4a596a3cb.zip
CMake-cf312a2e5423c49cc5da446f5407a6f4a596a3cb.tar.gz
CMake-cf312a2e5423c49cc5da446f5407a6f4a596a3cb.tar.bz2
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`.
Diffstat (limited to 'Tests/InterfaceLinkLibraries')
-rw-r--r--Tests/InterfaceLinkLibraries/CMakeLists.txt9
-rw-r--r--Tests/InterfaceLinkLibraries/foo_link_only.c8
-rw-r--r--Tests/InterfaceLinkLibraries/use_foo_link_only.c16
3 files changed, 33 insertions, 0 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();
+}