Skip to content

Commit d47a0f7

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

File tree

3 files changed

+138
-1
lines changed

3 files changed

+138
-1
lines changed

CMakeLists.txt

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,39 @@ elseif(UNIX)
11801180
set_target_properties(${TARGET_CORE_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/")
11811181
endif()
11821182

1183+
# Apply the same RPATH settings to other targets if they exist
1184+
if(TARGET ${TARGET_OPENCV_NAME})
1185+
if(APPLE)
1186+
set_target_properties(${TARGET_OPENCV_NAME} PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/cmake/${PROJECT_NAME}/dependencies/lib")
1187+
elseif(UNIX)
1188+
set_target_properties(${TARGET_OPENCV_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/cmake/${PROJECT_NAME}/dependencies/lib")
1189+
endif()
1190+
endif()
1191+
1192+
if(TARGET ${TARGET_PCL_NAME})
1193+
if(APPLE)
1194+
set_target_properties(${TARGET_PCL_NAME} PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/cmake/${PROJECT_NAME}/dependencies/lib")
1195+
elseif(UNIX)
1196+
set_target_properties(${TARGET_PCL_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/cmake/${PROJECT_NAME}/dependencies/lib")
1197+
endif()
1198+
endif()
1199+
1200+
if(TARGET ${TARGET_RTABMAP_NAME})
1201+
if(APPLE)
1202+
set_target_properties(${TARGET_RTABMAP_NAME} PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/cmake/${PROJECT_NAME}/dependencies/lib")
1203+
elseif(UNIX)
1204+
set_target_properties(${TARGET_RTABMAP_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/cmake/${PROJECT_NAME}/dependencies/lib")
1205+
endif()
1206+
endif()
1207+
1208+
if(TARGET ${TARGET_BASALT_NAME})
1209+
if(APPLE)
1210+
set_target_properties(${TARGET_BASALT_NAME} PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/cmake/${PROJECT_NAME}/dependencies/lib")
1211+
elseif(UNIX)
1212+
set_target_properties(${TARGET_BASALT_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/cmake/${PROJECT_NAME}/dependencies/lib")
1213+
endif()
1214+
endif()
1215+
11831216
# Export to CMake registry if specified
11841217
if(CMAKE_EXPORT_PACKAGE_REGISTRY)
11851218
export(PACKAGE depthai)
@@ -1204,6 +1237,92 @@ if(DEPTHAI_INSTALL)
12041237
if(NOT DEPTHAI_BINARIES_RESOURCE_COMPILE)
12051238
install(DIRECTORY "${DEPTHAI_RESOURCES_OUTPUT_DIR}/" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}")
12061239
endif()
1240+
1241+
# Set RPATH handling
1242+
# use, i.e. don't skip the full RPATH for the build tree
1243+
set(CMAKE_SKIP_BUILD_RPATH FALSE)
1244+
1245+
# when building, use the install RPATH already
1246+
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
1247+
1248+
# add the automatically determined parts of the RPATH
1249+
# which point to directories outside the build tree to the install RPATH
1250+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
1251+
1252+
# the RPATH to be used when installing, but only if it's not a system directory
1253+
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
1254+
if("${isSystemDir}" STREQUAL "-1")
1255+
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
1256+
endif()
1257+
1258+
# Install Python examples
1259+
if(DEPTHAI_BUILD_PYTHON)
1260+
# Define Python installation directory if not already defined
1261+
if(NOT DEFINED PYTHON_INSTALL_DIR)
1262+
set(PYTHON_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages")
1263+
endif()
1264+
1265+
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/examples/python/"
1266+
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/python-examples")
1267+
1268+
# Install Python CLI utilities
1269+
install(FILES
1270+
"${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/utilities/stress_test.py"
1271+
"${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/utilities/cam_test.py"
1272+
DESTINATION "${PYTHON_INSTALL_DIR}/depthai_cli")
1273+
1274+
install(FILES
1275+
"${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/depthai_cli/__init__.py"
1276+
"${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/depthai_cli/depthai_cli.py"
1277+
DESTINATION "${PYTHON_INSTALL_DIR}/depthai_cli")
1278+
endif()
1279+
1280+
# Find and install all shared libraries
1281+
file(GLOB_RECURSE SHARED_LIBS
1282+
LIST_DIRECTORIES false
1283+
RELATIVE "${CMAKE_BINARY_DIR}"
1284+
"${CMAKE_BINARY_DIR}/*.so*"
1285+
"${CMAKE_BINARY_DIR}/*.dylib*")
1286+
1287+
foreach(LIB_FILE ${SHARED_LIBS})
1288+
get_filename_component(LIB_NAME ${LIB_FILE} NAME)
1289+
if(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${LIB_NAME}")
1290+
install(FILES "${CMAKE_BINARY_DIR}/${LIB_FILE}"
1291+
DESTINATION "${CMAKE_INSTALL_LIBDIR}")
1292+
endif()
1293+
endforeach()
1294+
1295+
# Find and install all executables in bin directory
1296+
file(GLOB BIN_EXECUTABLES
1297+
LIST_DIRECTORIES false
1298+
"${CMAKE_BINARY_DIR}/bin/*")
1299+
1300+
foreach(EXEC_FILE ${BIN_EXECUTABLES})
1301+
if(NOT IS_DIRECTORY "${EXEC_FILE}")
1302+
install(PROGRAMS "${EXEC_FILE}"
1303+
DESTINATION "${CMAKE_INSTALL_BINDIR}")
1304+
endif()
1305+
endforeach()
1306+
1307+
# Find and install all executables in examples directory
1308+
file(GLOB EXAMPLE_EXECUTABLES
1309+
LIST_DIRECTORIES false
1310+
"${CMAKE_BINARY_DIR}/examples/*")
1311+
1312+
foreach(EXEC_FILE ${EXAMPLE_EXECUTABLES})
1313+
if(NOT IS_DIRECTORY "${EXEC_FILE}")
1314+
install(PROGRAMS "${EXEC_FILE}"
1315+
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/examples")
1316+
endif()
1317+
endforeach()
1318+
1319+
# Install Python modules
1320+
if(DEPTHAI_BUILD_PYTHON)
1321+
install(DIRECTORY "${CMAKE_BINARY_DIR}/bindings/python/"
1322+
DESTINATION "${PYTHON_INSTALL_DIR}"
1323+
FILES_MATCHING PATTERN "*.so*" PATTERN "*.dylib*")
1324+
endif()
1325+
12071326
# Install any required dll files
12081327
if(DEFINED required_dll_files)
12091328
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)