Skip to content

Commit

Permalink
Use @loader_path instead of $ORIGIN on MacOS (#403)
Browse files Browse the repository at this point in the history
The dynamic libraries currently produced by rapids-cmake on MacOS for cython modules don't work, because the wrong "ORIGIN" marker is used. The typical suggestion appears to be to use `@loader_path` in place of `$ORIGIN` on MacOS, although there is one more option that I can't currently recall.

Please excuse my ignorance around your processes. Please feel free to make/request changes.

Authors:
  - Manolis Papadakis (https://github.com/manopapad)
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - Robert Maynard (https://github.com/robertmaynard)
  - Bradley Dice (https://github.com/bdice)

URL: #403
  • Loading branch information
manopapad authored May 30, 2023
1 parent 1bcafd8 commit a63aa0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ rapids_cpm_find(fmt 7.1.3
add_library(example SHARED source.cu)

set_target_properties(example
PROPERTIES BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
PROPERTIES BUILD_RPATH "$ORIGIN"
INSTALL_RPATH "$ORIGIN"
# set target compile options
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
Expand Down
7 changes: 6 additions & 1 deletion rapids-cmake/cython/add_rpath_entries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,19 @@ function(rapids_cython_add_rpath_entries)
list(APPEND cleaned_paths "${path}")
endforeach()

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(platform_rpath_origin "@loader_path")
else()
set(platform_rpath_origin "$ORIGIN")
endif()
get_property(targets GLOBAL PROPERTY "rapids_cython_associations_${_RAPIDS_CYTHON_TARGET}")
foreach(target IN LISTS targets)
# Compute the path relative to the current target.
set(target_paths)
get_target_property(target_source_dir ${target} SOURCE_DIR)
foreach(target_path IN LISTS cleaned_paths)
cmake_path(RELATIVE_PATH target_path BASE_DIRECTORY "${target_source_dir}")
list(APPEND target_paths "$ORIGIN/${target_path}")
list(APPEND target_paths "${platform_rpath_origin}/${target_path}")
endforeach()
list(JOIN target_paths ";" target_paths)

Expand Down
7 changes: 6 additions & 1 deletion rapids-cmake/cython/create_modules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ function(rapids_cython_create_modules)
install(TARGETS ${cython_module} DESTINATION ${_RAPIDS_CYTHON_INSTALL_DIR})

# Default the INSTALL_RPATH for all modules to $ORIGIN.
set_target_properties(${cython_module} PROPERTIES INSTALL_RPATH "\$ORIGIN")
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(platform_rpath_origin "@loader_path")
else()
set(platform_rpath_origin "$ORIGIN")
endif()
set_target_properties(${cython_module} PROPERTIES INSTALL_RPATH "${platform_rpath_origin}")

# Store any provided associated targets in a global list
foreach(associated_target IN LISTS _RAPIDS_CYTHON_ASSOCIATED_TARGETS)
Expand Down

0 comments on commit a63aa0e

Please sign in to comment.