summaryrefslogtreecommitdiffstats
path: root/Tests/ExportImport
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-01-12 22:14:40 (GMT)
committerBrad King <brad.king@kitware.com>2022-01-29 11:48:13 (GMT)
commitf3ad061858d03cc2a0569f903df3560152106050 (patch)
treebe604880c112a5b7b6eeee586cf2238c4e952c3e /Tests/ExportImport
parent193a999cd5ed345d79b91dae1fd284248ec93ba2 (diff)
downloadCMake-f3ad061858d03cc2a0569f903df3560152106050.zip
CMake-f3ad061858d03cc2a0569f903df3560152106050.tar.gz
CMake-f3ad061858d03cc2a0569f903df3560152106050.tar.bz2
Add usage requirements to update direct link dependencies
Link line construction starts with `LINK_LIBRARIES` and appends dependencies from the transitive closure of `INTERFACE_LINK_LIBRARIES`. Only the entries of `LINK_LIBRARIES` are considered direct link dependencies. In some advanced use cases, particularly involving static libraries and static plugins, usage requirements need to update the list of direct link dependencies. This may mean adding new items, removing existing items, or both. Add target properties to encode these usage requirements: * INTERFACE_LINK_LIBRARIES_DIRECT * INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE Fixes: #22496
Diffstat (limited to 'Tests/ExportImport')
-rw-r--r--Tests/ExportImport/Export/CMakeLists.txt16
-rw-r--r--Tests/ExportImport/Import/A/CMakeLists.txt14
-rw-r--r--Tests/ExportImport/Import/A/imp_testExe1.c6
3 files changed, 34 insertions, 2 deletions
diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt
index a79efd0..c9e41f5 100644
--- a/Tests/ExportImport/Export/CMakeLists.txt
+++ b/Tests/ExportImport/Export/CMakeLists.txt
@@ -163,6 +163,16 @@ install(
cmake_policy(PUSH)
cmake_policy(SET CMP0022 NEW)
+
+# Test control over direct linking.
+include(../../InterfaceLinkLibrariesDirect/testStaticLibPlugin.cmake)
+include(../../InterfaceLinkLibrariesDirect/testSharedLibWithHelper.cmake)
+include(../../InterfaceLinkLibrariesDirect/testExeWithPluginHelper.cmake)
+if(NOT maybe_OBJECTS_DESTINATION)
+ target_compile_definitions(testSharedLibHelperObj INTERFACE testSharedLibHelperObj_NO_OBJECT)
+ target_compile_definitions(testExePluginHelperObj INTERFACE testExePluginHelperObj_NO_OBJECT)
+endif()
+
# Test exporting dependent libraries into different exports
add_library(testLibRequired testLibRequired.c)
add_library(testLibDepends testLibDepends.c)
@@ -544,6 +554,9 @@ install(
testLibDeprecation
testLibCycleA testLibCycleB
testLibNoSONAME
+ testStaticLibWithPlugin testStaticLibPluginExtra testStaticLibPlugin
+ testSharedLibWithHelper testSharedLibHelperObj
+ testExeWithPluginHelper testExePluginHelperObj
testMod1 testMod2
cmp0022NEW cmp0022OLD
TopDirLib SubDirLinkA
@@ -619,6 +632,9 @@ export(TARGETS testExe2 testLib4 testLib5 testLib6 testLib7 testExe3 testExe4 te
testLib4lib testLib4libdbg testLib4libopt
testLibCycleA testLibCycleB
testLibNoSONAME
+ testStaticLibWithPlugin testStaticLibPluginExtra testStaticLibPlugin
+ testSharedLibWithHelper testSharedLibHelperObj
+ testExeWithPluginHelper testExePluginHelperObj
testMod1 testMod2
testLibPerConfigDest
NAMESPACE bld_
diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt
index d6cc8d0..272c7a9 100644
--- a/Tests/ExportImport/Import/A/CMakeLists.txt
+++ b/Tests/ExportImport/Import/A/CMakeLists.txt
@@ -68,16 +68,23 @@ target_link_libraries(imp_testExe1
exp_testLib7
exp_testLibCycleA
exp_testLibPerConfigDest
+ exp_testStaticLibWithPlugin
)
add_library(imp_testInterfaceInclude1 STATIC imp_testInterfaceInclude1.c)
target_include_directories(imp_testInterfaceInclude1 SYSTEM PRIVATE testInterfaceIncludeSystem)
target_link_libraries(imp_testInterfaceInclude1 PRIVATE exp_testInterfaceIncludeUser)
+add_executable(imp_UseSharedLibWithHelper1 ../../../InterfaceLinkLibrariesDirect/UseSharedLibWithHelper.c)
+target_link_libraries(imp_UseSharedLibWithHelper1 PRIVATE exp_testSharedLibWithHelper testSharedLibHelperExclude)
+
# Try building a plugin to an executable imported from the install tree.
add_library(imp_mod1 MODULE imp_mod1.c)
target_link_libraries(imp_mod1 exp_testExe2)
+add_library(imp_ExePlugin1 MODULE ../../../InterfaceLinkLibrariesDirect/ExePlugin.c)
+target_link_libraries(imp_ExePlugin1 PRIVATE exp_testExeWithPluginHelper testExePluginHelperExclude)
+
# Try referencing an executable imported from the build tree.
add_custom_command(
OUTPUT ${Import_BINARY_DIR}/bld_generated.c
@@ -112,6 +119,7 @@ target_link_libraries(imp_testExe1b
bld_testLib7
bld_testLibCycleA
bld_testLibPerConfigDest
+ bld_testStaticLibWithPlugin
)
add_library(imp_testInterfaceInclude1b STATIC imp_testInterfaceInclude1.c)
@@ -183,10 +191,16 @@ target_link_libraries(SubDirLink_bld PRIVATE bld_TopDirLib bld_SubDirLinkA)
add_executable(SubDirLink_exp SubDirLink.c)
target_link_libraries(SubDirLink_exp PRIVATE exp_TopDirLib exp_SubDirLinkA)
+add_executable(imp_UseSharedLibWithHelper1b ../../../InterfaceLinkLibrariesDirect/UseSharedLibWithHelper.c)
+target_link_libraries(imp_UseSharedLibWithHelper1b PRIVATE bld_testSharedLibWithHelper testSharedLibHelperExclude)
+
# Try building a plugin to an executable imported from the build tree.
add_library(imp_mod1b MODULE imp_mod1.c)
target_link_libraries(imp_mod1b bld_testExe2)
+add_library(imp_ExePlugin1b MODULE ../../../InterfaceLinkLibrariesDirect/ExePlugin.c)
+target_link_libraries(imp_ExePlugin1b PRIVATE bld_testExeWithPluginHelper testExePluginHelperExclude)
+
# Export/CMakeLists.txt pretends the RelWithDebInfo (as well as Debug)
# configuration should link to debug libs.
foreach(c DEBUG RELWITHDEBINFO)
diff --git a/Tests/ExportImport/Import/A/imp_testExe1.c b/Tests/ExportImport/Import/A/imp_testExe1.c
index 8173557..7490a80 100644
--- a/Tests/ExportImport/Import/A/imp_testExe1.c
+++ b/Tests/ExportImport/Import/A/imp_testExe1.c
@@ -10,6 +10,7 @@ extern int testLib6(void);
extern int testLib7(void);
extern int testLibCycleA1(void);
extern int testLibPerConfigDest(void);
+extern int testStaticLibPlugin(void);
/* Switch a symbol between debug and optimized builds to make sure the
proper library is found from the testLib4 link interface. */
@@ -24,6 +25,7 @@ int main()
{
return (testLib2() + generated_by_testExe1() + testLib3() + testLib4() +
testLib5() + testLib6() + testLib7() + testLibCycleA1() +
- testLibPerConfigDest() + generated_by_testExe3() +
- generated_by_testExe4() + testLib4lib() + testLib4libcfg());
+ testLibPerConfigDest() + testStaticLibPlugin() +
+ generated_by_testExe3() + generated_by_testExe4() + testLib4lib() +
+ testLib4libcfg());
}