diff options
author | Brad King <brad.king@kitware.com> | 2018-09-07 16:59:52 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-09-12 17:06:36 (GMT) |
commit | a1ad0a699be3a2e9e3a18cc07c3bf069dedcfbfc (patch) | |
tree | 1be5538764c5520f53e8c0938061512a59e4479a /Tests/ExportImport | |
parent | 9bbae5ae2870082a3e62596e25f53dcdadaa51a9 (diff) | |
download | CMake-a1ad0a699be3a2e9e3a18cc07c3bf069dedcfbfc.zip CMake-a1ad0a699be3a2e9e3a18cc07c3bf069dedcfbfc.tar.gz CMake-a1ad0a699be3a2e9e3a18cc07c3bf069dedcfbfc.tar.bz2 |
target_link_libraries: Allow use with targets in other directories
Previously the command did not allow naming targets on the LHS that
were not created in the calling directory. Lift this restriction to
enable more flexible use by projects.
Targets named on the RHS will need to be looked up during generation in
the scope of the call site rather than the scope of the LHS target.
Introduce an internal syntax in `[INTERFACE_]LINK_LIBRARIES` properties
to specify target names that need to be looked up in a directory other
than that containing the target on which the property is set. Add
minimal documentation of the syntax to help users that encounter it.
Unfortunately CMake previously did allow such calls in the case that
only `INTERFACE` libraries are specified, but those libraries would be
looked up in the target's directory rather than the caller's. Add
policy `CMP0079` to enable the new behavior with new lookup scope in a
compatible way.
Fixes: #17943
Diffstat (limited to 'Tests/ExportImport')
-rw-r--r-- | Tests/ExportImport/Export/CMakeLists.txt | 9 | ||||
-rw-r--r-- | Tests/ExportImport/Export/SubDirLinkA/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Tests/ExportImport/Export/SubDirLinkA/SubDirLinkA.c | 11 | ||||
-rw-r--r-- | Tests/ExportImport/Export/SubDirLinkB/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Tests/ExportImport/Export/testTopDirLib.c | 11 | ||||
-rw-r--r-- | Tests/ExportImport/Import/A/CMakeLists.txt | 11 | ||||
-rw-r--r-- | Tests/ExportImport/Import/A/SubDirLink.c | 14 |
7 files changed, 66 insertions, 0 deletions
diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt index fdb2fa1..cb048be 100644 --- a/Tests/ExportImport/Export/CMakeLists.txt +++ b/Tests/ExportImport/Export/CMakeLists.txt @@ -155,6 +155,13 @@ add_library(testStaticLibRequiredPrivate testStaticLibRequiredPrivate.c) target_link_libraries(testLibDepends PRIVATE testStaticLibRequiredPrivate) cmake_policy(POP) +cmake_policy(PUSH) +cmake_policy(SET CMP0079 NEW) +add_library(TopDirLib STATIC testTopDirLib.c) +add_subdirectory(SubDirLinkA) +add_subdirectory(SubDirLinkB) +cmake_policy(POP) + macro(add_include_lib _libName) file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_libName}.c" "/* no content */\n") add_library(${_libName} "${CMAKE_CURRENT_BINARY_DIR}/${_libName}.c") @@ -508,6 +515,7 @@ install( testLibCycleA testLibCycleB testLibNoSONAME cmp0022NEW cmp0022OLD + TopDirLib SubDirLinkA systemlib EXPORT exp RUNTIME DESTINATION $<1:bin>$<0:/wrong> @@ -566,6 +574,7 @@ export(TARGETS testExe1 testLib1 testLib2 testLib3 testSharedLibRequired testSharedLibRequiredUser testSharedLibRequiredUser2 testSharedLibDepends renamed_on_export cmp0022NEW cmp0022OLD + TopDirLib SubDirLinkA systemlib NAMESPACE bld_ FILE ExportBuildTree.cmake diff --git a/Tests/ExportImport/Export/SubDirLinkA/CMakeLists.txt b/Tests/ExportImport/Export/SubDirLinkA/CMakeLists.txt new file mode 100644 index 0000000..1c3c9dc --- /dev/null +++ b/Tests/ExportImport/Export/SubDirLinkA/CMakeLists.txt @@ -0,0 +1,6 @@ +add_library(SubDirLinkAImported IMPORTED INTERFACE) +target_compile_definitions(SubDirLinkAImported INTERFACE DEF_SubDirLinkAImportedForExport) + +target_link_libraries(TopDirLib PUBLIC SubDirLinkAImported) + +add_library(SubDirLinkA STATIC SubDirLinkA.c) diff --git a/Tests/ExportImport/Export/SubDirLinkA/SubDirLinkA.c b/Tests/ExportImport/Export/SubDirLinkA/SubDirLinkA.c new file mode 100644 index 0000000..abf76f5 --- /dev/null +++ b/Tests/ExportImport/Export/SubDirLinkA/SubDirLinkA.c @@ -0,0 +1,11 @@ +#ifdef DEF_SubDirLinkAImportedForExport +# error "DEF_SubDirLinkAImportedForExport is defined but should not be!" +#endif +#ifndef DEF_SubDirLinkBImportedForExport +# error "DEF_SubDirLinkBImportedForExport is not defined but should be!" +#endif + +int testSubDirLinkA(void) +{ + return 0; +} diff --git a/Tests/ExportImport/Export/SubDirLinkB/CMakeLists.txt b/Tests/ExportImport/Export/SubDirLinkB/CMakeLists.txt new file mode 100644 index 0000000..22e168f --- /dev/null +++ b/Tests/ExportImport/Export/SubDirLinkB/CMakeLists.txt @@ -0,0 +1,4 @@ +add_library(SubDirLinkBImported IMPORTED INTERFACE) +target_compile_definitions(SubDirLinkBImported INTERFACE DEF_SubDirLinkBImportedForExport) + +target_link_libraries(SubDirLinkA PUBLIC SubDirLinkBImported) diff --git a/Tests/ExportImport/Export/testTopDirLib.c b/Tests/ExportImport/Export/testTopDirLib.c new file mode 100644 index 0000000..1ec68de --- /dev/null +++ b/Tests/ExportImport/Export/testTopDirLib.c @@ -0,0 +1,11 @@ +#ifndef DEF_SubDirLinkAImportedForExport +# error "DEF_SubDirLinkAImportedForExport is not defined but should be!" +#endif +#ifdef DEF_SubDirLinkBImportedForExport +# error "DEF_SubDirLinkBImportedForExport is defined but should not be!" +#endif + +int testTopDirLib(void) +{ + return 0; +} diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index 7510d7e..8791a19 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -1,3 +1,9 @@ +# Prepare imported targets that the exported project itself imported. +add_library(SubDirLinkAImported IMPORTED INTERFACE) +target_compile_definitions(SubDirLinkAImported INTERFACE DEF_SubDirLinkAImportedForImport) +add_library(SubDirLinkBImported IMPORTED INTERFACE) +target_compile_definitions(SubDirLinkBImported INTERFACE DEF_SubDirLinkBImportedForImport) + # Import targets from the exported build tree. include(${Import_BINARY_DIR}/../Export/ExportBuildTree.cmake) @@ -158,6 +164,11 @@ target_link_libraries(cmp0022OLD_exp_test exp_cmp0022OLD) add_executable(cmp0022NEW_exp_test cmp0022NEW_test_vs6_2.cpp) target_link_libraries(cmp0022NEW_exp_test exp_cmp0022NEW) +add_executable(SubDirLink_bld SubDirLink.c) +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) + # 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) diff --git a/Tests/ExportImport/Import/A/SubDirLink.c b/Tests/ExportImport/Import/A/SubDirLink.c new file mode 100644 index 0000000..eb4b860 --- /dev/null +++ b/Tests/ExportImport/Import/A/SubDirLink.c @@ -0,0 +1,14 @@ +#ifndef DEF_SubDirLinkAImportedForImport +# error "DEF_SubDirLinkAImportedForImport is not defined but should be!" +#endif +#ifndef DEF_SubDirLinkBImportedForImport +# error "DEF_SubDirLinkBImportedForImport is not defined but should be!" +#endif + +extern int testTopDirLib(void); +extern int testSubDirLinkA(void); + +int main(void) +{ + return (testTopDirLib() + testSubDirLinkA() + 0); +} |