Skip to content

[CMake] Use explicit RPATHs for unit test executables #68388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions cmake/modules/AddSwiftUnittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,31 @@ function(add_swift_unittest test_dirname)
endif()
endif()

file(RELATIVE_PATH relative_lib_path "${CMAKE_CURRENT_BINARY_DIR}" "${SWIFT_LIBRARY_OUTPUT_INTDIR}")

if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
set_property(
TARGET ${test_dirname}
APPEND PROPERTY INSTALL_RPATH "@executable_path/${relative_lib_path}")
elseif(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD")
set_property(
TARGET ${test_dirname}
APPEND PROPERTY INSTALL_RPATH "$ORIGIN/${relative_lib_path}")
endif()

if (SWIFT_SWIFT_PARSER AND NOT ASU_IS_TARGET_TEST)
# Link to stdlib the compiler uses.
_add_swift_runtime_link_flags(${test_dirname} "../../lib" "")
set_property(TARGET ${test_dirname} PROPERTY BUILD_WITH_INSTALL_RPATH OFF)
_add_swift_runtime_link_flags(${test_dirname} "${relative_lib_path}" "")

if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
set_property(
TARGET ${test_dirname}
APPEND PROPERTY INSTALL_RPATH "@executable_path/${relative_lib_path}/swift/host")
elseif(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD")
set_property(
TARGET ${test_dirname}
APPEND PROPERTY INSTALL_RPATH "$ORIGIN/${relative_lib_path}/swift/host")
endif()
endif()
endfunction()