summaryrefslogtreecommitdiffstats
path: root/Tests/ExportImport
diff options
context:
space:
mode:
authorRobert Maynard <rmaynard@nvidia.com>2023-04-11 19:49:52 (GMT)
committerRobert Maynard <rmaynard@nvidia.com>2023-05-04 13:39:06 (GMT)
commitc42630ee62df80e649211e99c510cab7ac28fc0b (patch)
tree8b450a62d4e4c9559b8fe03b11575bde8d154608 /Tests/ExportImport
parent0fb923c46041d67110c8e0907afdf66b3b25f25a (diff)
downloadCMake-c42630ee62df80e649211e99c510cab7ac28fc0b.zip
CMake-c42630ee62df80e649211e99c510cab7ac28fc0b.tar.gz
CMake-c42630ee62df80e649211e99c510cab7ac28fc0b.tar.bz2
cmGeneratorExpressionNode: implement `COMPILE_ONLY` genex
This generator expression is the inverse of `LINK_ONLY` and only coveys usage requirements for the purposes of compilation. Its intended use is to avoid needing to export targets that do not have link usage requirements (e.g., header-only libraries) when used by another target. See: #15415
Diffstat (limited to 'Tests/ExportImport')
-rw-r--r--Tests/ExportImport/Export/CMakeLists.txt10
-rw-r--r--Tests/ExportImport/Export/testLib2.c4
2 files changed, 14 insertions, 0 deletions
diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt
index 6f19c13..67f2fcb 100644
--- a/Tests/ExportImport/Export/CMakeLists.txt
+++ b/Tests/ExportImport/Export/CMakeLists.txt
@@ -22,9 +22,18 @@ add_executable(testExe2 testExe2.c)
set_property(TARGET testExe2 PROPERTY ENABLE_EXPORTS 1)
set_property(TARGET testExe2 PROPERTY LINK_INTERFACE_LIBRARIES testExe2lib)
+add_library(compileOnly INTERFACE)
+target_compile_definitions(compileOnly INTERFACE FROM_compileOnly)
+target_link_options(compileOnly INTERFACE -fthis-flag-does-not-exist)
+
add_library(testLib1 STATIC testLib1.c)
add_library(testLib2 STATIC testLib2.c)
target_link_libraries(testLib2 testLib1)
+target_link_libraries(testLib2
+ PRIVATE
+ testLib1
+ "$<COMPILE_ONLY:compileOnly>")
+
# Test install(FILES) with generator expressions referencing testLib1.
add_custom_command(TARGET testLib1 POST_BUILD
@@ -556,6 +565,7 @@ install(FILES
# Install and export from install tree.
install(
TARGETS
+ compileOnly
testExe1 testLib1 testLib2 testExe2 testLib3 testLib4 testExe3 testExe4
testExe2lib testLib4lib testLib4libdbg testLib4libopt
testLib6 testLib7 testLib8
diff --git a/Tests/ExportImport/Export/testLib2.c b/Tests/ExportImport/Export/testLib2.c
index 7a5206f..f5faffa 100644
--- a/Tests/ExportImport/Export/testLib2.c
+++ b/Tests/ExportImport/Export/testLib2.c
@@ -1,4 +1,8 @@
+#ifndef FROM_compileOnly
+# error "Usage requirements from `compileOnly` not found"
+#endif
+
extern int testLib1(void);
int testLib2(void)