Skip to content

Commit 16a13b5

Browse files
author
Petr Hodina
committed
Set and propagate RPATH settings across targets and Python components
1 parent c4a52f6 commit 16a13b5

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

CMakeLists.txt

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,92 @@ if(DEPTHAI_INSTALL)
12041204
if(NOT DEPTHAI_BINARIES_RESOURCE_COMPILE)
12051205
install(DIRECTORY "${DEPTHAI_RESOURCES_OUTPUT_DIR}/" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}")
12061206
endif()
1207+
1208+
# Set RPATH handling
1209+
# use, i.e. don't skip the full RPATH for the build tree
1210+
set(CMAKE_SKIP_BUILD_RPATH FALSE)
1211+
1212+
# when building, use the install RPATH already
1213+
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
1214+
1215+
# add the automatically determined parts of the RPATH
1216+
# which point to directories outside the build tree to the install RPATH
1217+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
1218+
1219+
# the RPATH to be used when installing, but only if it's not a system directory
1220+
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
1221+
if("${isSystemDir}" STREQUAL "-1")
1222+
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
1223+
endif()
1224+
1225+
# Install Python examples
1226+
if(DEPTHAI_BUILD_PYTHON)
1227+
# Define Python installation directory if not already defined
1228+
if(NOT DEFINED PYTHON_INSTALL_DIR)
1229+
set(PYTHON_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages")
1230+
endif()
1231+
1232+
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/examples/python/"
1233+
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/python-examples")
1234+
1235+
# Install Python CLI utilities
1236+
install(FILES
1237+
"${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/utilities/stress_test.py"
1238+
"${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/utilities/cam_test.py"
1239+
DESTINATION "${PYTHON_INSTALL_DIR}/depthai_cli")
1240+
1241+
install(FILES
1242+
"${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/depthai_cli/__init__.py"
1243+
"${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/depthai_cli/depthai_cli.py"
1244+
DESTINATION "${PYTHON_INSTALL_DIR}/depthai_cli")
1245+
endif()
1246+
1247+
# Find and install all shared libraries
1248+
file(GLOB_RECURSE SHARED_LIBS
1249+
LIST_DIRECTORIES false
1250+
RELATIVE "${CMAKE_BINARY_DIR}"
1251+
"${CMAKE_BINARY_DIR}/*.so*"
1252+
"${CMAKE_BINARY_DIR}/*.dylib*")
1253+
1254+
foreach(LIB_FILE ${SHARED_LIBS})
1255+
get_filename_component(LIB_NAME ${LIB_FILE} NAME)
1256+
if(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${LIB_NAME}")
1257+
install(FILES "${CMAKE_BINARY_DIR}/${LIB_FILE}"
1258+
DESTINATION "${CMAKE_INSTALL_LIBDIR}")
1259+
endif()
1260+
endforeach()
1261+
1262+
# Find and install all executables in bin directory
1263+
file(GLOB BIN_EXECUTABLES
1264+
LIST_DIRECTORIES false
1265+
"${CMAKE_BINARY_DIR}/bin/*")
1266+
1267+
foreach(EXEC_FILE ${BIN_EXECUTABLES})
1268+
if(NOT IS_DIRECTORY "${EXEC_FILE}")
1269+
install(PROGRAMS "${EXEC_FILE}"
1270+
DESTINATION "${CMAKE_INSTALL_BINDIR}")
1271+
endif()
1272+
endforeach()
1273+
1274+
# Find and install all executables in examples directory
1275+
file(GLOB EXAMPLE_EXECUTABLES
1276+
LIST_DIRECTORIES false
1277+
"${CMAKE_BINARY_DIR}/examples/*")
1278+
1279+
foreach(EXEC_FILE ${EXAMPLE_EXECUTABLES})
1280+
if(NOT IS_DIRECTORY "${EXEC_FILE}")
1281+
install(PROGRAMS "${EXEC_FILE}"
1282+
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/examples")
1283+
endif()
1284+
endforeach()
1285+
1286+
# Install Python modules
1287+
if(DEPTHAI_BUILD_PYTHON)
1288+
install(DIRECTORY "${CMAKE_BINARY_DIR}/bindings/python/"
1289+
DESTINATION "${PYTHON_INSTALL_DIR}"
1290+
FILES_MATCHING PATTERN "*.so*" PATTERN "*.dylib*")
1291+
endif()
1292+
12071293
# Install any required dll files
12081294
if(DEFINED required_dll_files)
12091295
set(DLL_INSTALLATION_DIR "${CMAKE_INSTALL_LIBDIR}")

bindings/python/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ target_link_libraries(${TARGET_NAME}
299299
spdlog::spdlog
300300
)
301301

302+
# Set RPATH for the Python module
303+
if(APPLE)
304+
set_target_properties(${TARGET_NAME} PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/../lib")
305+
elseif(UNIX)
306+
set_target_properties(${TARGET_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib")
307+
endif()
308+
# Ensure we use the install RPATH during build
309+
set_target_properties(${TARGET_NAME} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
310+
302311
# Add embedded module option, otherwise link to pybind11 as usual
303312
if(DEPTHAI_PYTHON_EMBEDDED_MODULE)
304313
target_compile_definitions(${TARGET_NAME} PRIVATE DEPTHAI_PYTHON_EMBEDDED_MODULE)

bindings/python/tests/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,13 @@ add_custom_target(
4242
)
4343

4444
# Link to depthai
45-
target_link_libraries(${TARGET_TEST_MODULE} PRIVATE pybind11::pybind11 depthai::core)
45+
target_link_libraries(${TARGET_TEST_MODULE} PRIVATE pybind11::pybind11 depthai::core)
46+
47+
# Set RPATH for the Python test module
48+
if(APPLE)
49+
set_target_properties(${TARGET_TEST_MODULE} PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/../../../lib")
50+
elseif(UNIX)
51+
set_target_properties(${TARGET_TEST_MODULE} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/../../../lib")
52+
endif()
53+
# Ensure we use the install RPATH during build
54+
set_target_properties(${TARGET_TEST_MODULE} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)

0 commit comments

Comments
 (0)