Skip to content

Commit 0571499

Browse files
committed
cmake: Install shared libs
1 parent 8fb5a13 commit 0571499

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
@@ -1162,6 +1162,39 @@ elseif(UNIX)
11621162
set_target_properties(${TARGET_CORE_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/cmake/${PROJECT_NAME}/dependencies/lib")
11631163
endif()
11641164

1165+
# Apply the same RPATH settings to other targets if they exist
1166+
if(TARGET ${TARGET_OPENCV_NAME})
1167+
if(APPLE)
1168+
set_target_properties(${TARGET_OPENCV_NAME} PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/cmake/${PROJECT_NAME}/dependencies/lib")
1169+
elseif(UNIX)
1170+
set_target_properties(${TARGET_OPENCV_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/cmake/${PROJECT_NAME}/dependencies/lib")
1171+
endif()
1172+
endif()
1173+
1174+
if(TARGET ${TARGET_PCL_NAME})
1175+
if(APPLE)
1176+
set_target_properties(${TARGET_PCL_NAME} PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/cmake/${PROJECT_NAME}/dependencies/lib")
1177+
elseif(UNIX)
1178+
set_target_properties(${TARGET_PCL_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/cmake/${PROJECT_NAME}/dependencies/lib")
1179+
endif()
1180+
endif()
1181+
1182+
if(TARGET ${TARGET_RTABMAP_NAME})
1183+
if(APPLE)
1184+
set_target_properties(${TARGET_RTABMAP_NAME} PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/cmake/${PROJECT_NAME}/dependencies/lib")
1185+
elseif(UNIX)
1186+
set_target_properties(${TARGET_RTABMAP_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/cmake/${PROJECT_NAME}/dependencies/lib")
1187+
endif()
1188+
endif()
1189+
1190+
if(TARGET ${TARGET_BASALT_NAME})
1191+
if(APPLE)
1192+
set_target_properties(${TARGET_BASALT_NAME} PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/cmake/${PROJECT_NAME}/dependencies/lib")
1193+
elseif(UNIX)
1194+
set_target_properties(${TARGET_BASALT_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/cmake/${PROJECT_NAME}/dependencies/lib")
1195+
endif()
1196+
endif()
1197+
11651198
# Export to CMake registry if specified
11661199
if(CMAKE_EXPORT_PACKAGE_REGISTRY)
11671200
export(PACKAGE depthai)
@@ -1189,6 +1222,92 @@ if(DEPTHAI_INSTALL)
11891222
if(NOT DEPTHAI_BINARIES_RESOURCE_COMPILE)
11901223
install(DIRECTORY "${DEPTHAI_RESOURCES_OUTPUT_DIR}/" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}")
11911224
endif()
1225+
1226+
# Set RPATH handling
1227+
# use, i.e. don't skip the full RPATH for the build tree
1228+
set(CMAKE_SKIP_BUILD_RPATH FALSE)
1229+
1230+
# when building, use the install RPATH already
1231+
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
1232+
1233+
# add the automatically determined parts of the RPATH
1234+
# which point to directories outside the build tree to the install RPATH
1235+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
1236+
1237+
# the RPATH to be used when installing, but only if it's not a system directory
1238+
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
1239+
if("${isSystemDir}" STREQUAL "-1")
1240+
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
1241+
endif()
1242+
1243+
# Install Python examples
1244+
if(DEPTHAI_BUILD_PYTHON)
1245+
# Define Python installation directory if not already defined
1246+
if(NOT DEFINED PYTHON_INSTALL_DIR)
1247+
set(PYTHON_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages")
1248+
endif()
1249+
1250+
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/examples/python/"
1251+
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/python-examples")
1252+
1253+
# Install Python CLI utilities
1254+
install(FILES
1255+
"${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/utilities/stress_test.py"
1256+
"${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/utilities/cam_test.py"
1257+
DESTINATION "${PYTHON_INSTALL_DIR}/depthai_cli")
1258+
1259+
install(FILES
1260+
"${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/depthai_cli/__init__.py"
1261+
"${CMAKE_CURRENT_SOURCE_DIR}/bindings/python/depthai_cli/depthai_cli.py"
1262+
DESTINATION "${PYTHON_INSTALL_DIR}/depthai_cli")
1263+
endif()
1264+
1265+
# Find and install all shared libraries
1266+
file(GLOB_RECURSE SHARED_LIBS
1267+
LIST_DIRECTORIES false
1268+
RELATIVE "${CMAKE_BINARY_DIR}"
1269+
"${CMAKE_BINARY_DIR}/*.so*"
1270+
"${CMAKE_BINARY_DIR}/*.dylib*")
1271+
1272+
foreach(LIB_FILE ${SHARED_LIBS})
1273+
get_filename_component(LIB_NAME ${LIB_FILE} NAME)
1274+
if(NOT EXISTS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${LIB_NAME}")
1275+
install(FILES "${CMAKE_BINARY_DIR}/${LIB_FILE}"
1276+
DESTINATION "${CMAKE_INSTALL_LIBDIR}")
1277+
endif()
1278+
endforeach()
1279+
1280+
# Find and install all executables in bin directory
1281+
file(GLOB BIN_EXECUTABLES
1282+
LIST_DIRECTORIES false
1283+
"${CMAKE_BINARY_DIR}/bin/*")
1284+
1285+
foreach(EXEC_FILE ${BIN_EXECUTABLES})
1286+
if(NOT IS_DIRECTORY "${EXEC_FILE}")
1287+
install(PROGRAMS "${EXEC_FILE}"
1288+
DESTINATION "${CMAKE_INSTALL_BINDIR}")
1289+
endif()
1290+
endforeach()
1291+
1292+
# Find and install all executables in examples directory
1293+
file(GLOB EXAMPLE_EXECUTABLES
1294+
LIST_DIRECTORIES false
1295+
"${CMAKE_BINARY_DIR}/examples/*")
1296+
1297+
foreach(EXEC_FILE ${EXAMPLE_EXECUTABLES})
1298+
if(NOT IS_DIRECTORY "${EXEC_FILE}")
1299+
install(PROGRAMS "${EXEC_FILE}"
1300+
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/examples")
1301+
endif()
1302+
endforeach()
1303+
1304+
# Install Python modules
1305+
if(DEPTHAI_BUILD_PYTHON)
1306+
install(DIRECTORY "${CMAKE_BINARY_DIR}/bindings/python/"
1307+
DESTINATION "${PYTHON_INSTALL_DIR}"
1308+
FILES_MATCHING PATTERN "*.so*" PATTERN "*.dylib*")
1309+
endif()
1310+
11921311
# Install any required dll files
11931312
if(DEFINED required_dll_files)
11941313
install(FILES ${required_dll_files} DESTINATION "${CMAKE_INSTALL_BINDIR}")

bindings/python/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ target_link_libraries(${TARGET_NAME}
303303
xtensor-python
304304
)
305305

306+
# Set RPATH for the Python module
307+
if(APPLE)
308+
set_target_properties(${TARGET_NAME} PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/../lib")
309+
elseif(UNIX)
310+
set_target_properties(${TARGET_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib")
311+
endif()
312+
# Ensure we use the install RPATH during build
313+
set_target_properties(${TARGET_NAME} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
314+
306315
# Add embedded module option, otherwise link to pybind11 as usual
307316
if(DEPTHAI_PYTHON_EMBEDDED_MODULE)
308317
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)