diff options
author | Brad King <brad.king@kitware.com> | 2022-08-10 15:30:03 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-08-15 14:40:03 (GMT) |
commit | 0ebff0d61acf27c077545a36ee83526cef22e1fc (patch) | |
tree | 03dfed920c4421d20d9d71b126656555aad8ee49 /Tests/RunCMake | |
parent | 4be24f031a4829db75b85062cc67125035d8831e (diff) | |
download | CMake-0ebff0d61acf27c077545a36ee83526cef22e1fc.zip CMake-0ebff0d61acf27c077545a36ee83526cef22e1fc.tar.gz CMake-0ebff0d61acf27c077545a36ee83526cef22e1fc.tar.bz2 |
export: Restore exclusion of private shared library dependencies from checks
Refactoring in commit 8c65b7042e (cmExportFileGenerator: Simplify
collection of targets missing from export set, 2022-04-11,
v3.24.0-rc1~281^2) accidentally dropped the behavior change from
commit 0ad2a1c181 (Export: Never treat private link libraries as
public package dependencies., 2013-09-24, v3.0.0-rc1~559^2).
Restore the behavior and add a test.
Fixes: #23838
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/ExportImport/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/ExportImport/RunCMakeTest.cmake | 24 | ||||
-rw-r--r-- | Tests/RunCMake/ExportImport/SharedDep-export.cmake | 13 | ||||
-rw-r--r-- | Tests/RunCMake/ExportImport/SharedDep-import.cmake | 1 | ||||
-rw-r--r-- | Tests/RunCMake/ExportImport/bar-config.cmake.in | 2 | ||||
-rw-r--r-- | Tests/RunCMake/ExportImport/bar.c | 12 | ||||
-rw-r--r-- | Tests/RunCMake/ExportImport/foo-config.cmake.in | 1 | ||||
-rw-r--r-- | Tests/RunCMake/ExportImport/foo.c | 7 |
9 files changed, 64 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 69def6d..09f248e 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -301,6 +301,7 @@ if("${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja") add_RunCMake_test(ExportCompileCommands) endif() add_RunCMake_test(ExcludeFromAll) +add_RunCMake_test(ExportImport) add_RunCMake_test(ExternalData) add_RunCMake_test(FeatureSummary) add_RunCMake_test(FPHSA) diff --git a/Tests/RunCMake/ExportImport/CMakeLists.txt b/Tests/RunCMake/ExportImport/CMakeLists.txt new file mode 100644 index 0000000..5ff8d3e --- /dev/null +++ b/Tests/RunCMake/ExportImport/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.23) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/ExportImport/RunCMakeTest.cmake b/Tests/RunCMake/ExportImport/RunCMakeTest.cmake new file mode 100644 index 0000000..d07fca2 --- /dev/null +++ b/Tests/RunCMake/ExportImport/RunCMakeTest.cmake @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.23) +include(RunCMake) + +function(run_ExportImport_test case) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-export-build) + set(CMAKE_INSTALL_PREFIX ${RunCMake_TEST_BINARY_DIR}/root) + if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug) + endif() + run_cmake(${case}-export) + unset(RunCMake_TEST_OPTIONS) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(${case}-export-build ${CMAKE_COMMAND} --build . --config Debug) + run_cmake_command(${case}-export-install ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DBUILD_TYPE=Debug -P cmake_install.cmake) + unset(RunCMake_TEST_NO_CLEAN) + + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-import-build) + run_cmake_with_options(${case}-import + -Dfoo_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/foo + -Dbar_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/bar + ) +endfunction() + +run_ExportImport_test(SharedDep) diff --git a/Tests/RunCMake/ExportImport/SharedDep-export.cmake b/Tests/RunCMake/ExportImport/SharedDep-export.cmake new file mode 100644 index 0000000..2da3e47 --- /dev/null +++ b/Tests/RunCMake/ExportImport/SharedDep-export.cmake @@ -0,0 +1,13 @@ +enable_language(C) + +add_library(foo SHARED foo.c) +install(TARGETS foo EXPORT foo) +install(EXPORT foo DESTINATION lib/cmake/foo) +install(FILES foo-config.cmake.in RENAME foo-config.cmake DESTINATION lib/cmake/foo) + +add_library(bar SHARED bar.c) +target_link_libraries(bar PRIVATE foo) +# 'foo' only appears in IMPORTED_LINK_DEPENDENT_LIBRARIES, and so is not enforced on import. +install(TARGETS bar EXPORT bar) +install(EXPORT bar DESTINATION lib/cmake/bar) +install(FILES bar-config.cmake.in RENAME bar-config.cmake DESTINATION lib/cmake/bar) diff --git a/Tests/RunCMake/ExportImport/SharedDep-import.cmake b/Tests/RunCMake/ExportImport/SharedDep-import.cmake new file mode 100644 index 0000000..2e2c2f6 --- /dev/null +++ b/Tests/RunCMake/ExportImport/SharedDep-import.cmake @@ -0,0 +1 @@ +find_package(bar REQUIRED CONFIG NO_DEFAULT_PATH) diff --git a/Tests/RunCMake/ExportImport/bar-config.cmake.in b/Tests/RunCMake/ExportImport/bar-config.cmake.in new file mode 100644 index 0000000..9148046 --- /dev/null +++ b/Tests/RunCMake/ExportImport/bar-config.cmake.in @@ -0,0 +1,2 @@ +# find_dependency(foo) intentionally left out for this test case +include(${CMAKE_CURRENT_LIST_DIR}/bar.cmake) diff --git a/Tests/RunCMake/ExportImport/bar.c b/Tests/RunCMake/ExportImport/bar.c new file mode 100644 index 0000000..19adca9 --- /dev/null +++ b/Tests/RunCMake/ExportImport/bar.c @@ -0,0 +1,12 @@ +#if defined(_WIN32) +__declspec(dllimport) +#endif + int foo(void); + +#ifdef _WIN32 +__declspec(dllexport) +#endif + int bar(void) +{ + return foo(); +} diff --git a/Tests/RunCMake/ExportImport/foo-config.cmake.in b/Tests/RunCMake/ExportImport/foo-config.cmake.in new file mode 100644 index 0000000..b038138 --- /dev/null +++ b/Tests/RunCMake/ExportImport/foo-config.cmake.in @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_LIST_DIR}/foo.cmake) diff --git a/Tests/RunCMake/ExportImport/foo.c b/Tests/RunCMake/ExportImport/foo.c new file mode 100644 index 0000000..8794965 --- /dev/null +++ b/Tests/RunCMake/ExportImport/foo.c @@ -0,0 +1,7 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif + int foo(void) +{ + return 0; +} |