Skip to content

Commit 3caf449

Browse files
committed
cmake: Install shared libs
1 parent eb0d612 commit 3caf449

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
@@ -1177,6 +1177,39 @@ elseif(UNIX)
11771177
set_target_properties(${TARGET_CORE_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/")
11781178
endif()
11791179

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

300+
# Set RPATH for the Python module
301+
if(APPLE)
302+
set_target_properties(${TARGET_NAME} PROPERTIES INSTALL_RPATH "@loader_path;@loader_path/../lib")
303+
elseif(UNIX)
304+
set_target_properties(${TARGET_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib")
305+
endif()
306+
# Ensure we use the install RPATH during build
307+
set_target_properties(${TARGET_NAME} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
308+
300309
# Add embedded module option, otherwise link to pybind11 as usual
301310
if(DEPTHAI_PYTHON_EMBEDDED_MODULE)
302311
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)