Skip to content

Commit

Permalink
Fix RPATH on autoschedulers
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreinking committed Aug 30, 2024
1 parent 760f1e5 commit 8323ef0
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ set(Halide_INSTALL_PLUGINDIR "${CMAKE_INSTALL_LIBDIR}"
set(Halide_INSTALL_TOOLSDIR "${CMAKE_INSTALL_DATADIR}/tools"
CACHE STRING "Path to Halide build-time tools and sources")

##
# RPATH patching helper
##

function(_Halide_compute_rpath)
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "ORIGIN_DIR;LIB_DIR" "TARGETS")
if (APPLE)
set(rbase @loader_path)
else ()
set(rbase $ORIGIN)
endif ()

file(RELATIVE_PATH lib_dir
${CMAKE_CURRENT_BINARY_DIR}/${ARG_ORIGIN_DIR}
${CMAKE_CURRENT_BINARY_DIR}/${ARG_LIB_DIR})

set_target_properties(${ARG_TARGETS} PROPERTIES INSTALL_RPATH "${rbase};${rbase}/${lib_dir}")
endfunction()

##
# Main library exports
##
Expand All @@ -30,10 +49,20 @@ install(TARGETS Halide Halide_Generator Halide_GenGen
FILE_SET HEADERS COMPONENT Halide_Development)

if (WITH_AUTOSCHEDULERS)
install(TARGETS Halide_Adams2019 Halide_Li2018 Halide_Mullapudi2016 Halide_Anderson2021
set(autoschedulers Halide_Adams2019 Halide_Li2018 Halide_Mullapudi2016 Halide_Anderson2021)

install(TARGETS ${autoschedulers}
EXPORT Halide_Interfaces
LIBRARY DESTINATION ${Halide_INSTALL_PLUGINDIR} COMPONENT Halide_Runtime
NAMELINK_COMPONENT Halide_Development)

if (NOT CMAKE_INSTALL_RPATH)
_Halide_compute_rpath(
TARGETS ${autoschedulers}
ORIGIN_DIR "${Halide_INSTALL_PLUGINDIR}"
LIB_DIR "${CMAKE_INSTALL_LIBDIR}"
)
endif ()
endif ()

##
Expand Down Expand Up @@ -75,21 +104,6 @@ if (WITH_AUTOSCHEDULERS AND WITH_UTILS)
)
endif ()

function(_Halide_compute_rpath)
cmake_parse_arguments(PARSE_ARGV 0 ARG "" "ORIGIN_DIR;LIB_DIR" "TARGETS")
if (APPLE)
set(rbase @loader_path)
else ()
set(rbase $ORIGIN)
endif ()

file(RELATIVE_PATH lib_dir
${CMAKE_CURRENT_BINARY_DIR}/${ARG_ORIGIN_DIR}
${CMAKE_CURRENT_BINARY_DIR}/${ARG_LIB_DIR})

set_target_properties(${ARG_TARGETS} PROPERTIES INSTALL_RPATH "${rbase};${rbase}/${lib_dir}")
endfunction()

if (NOT CMAKE_INSTALL_RPATH)
_Halide_compute_rpath(
TARGETS ${utils}
Expand Down

0 comments on commit 8323ef0

Please sign in to comment.