@@ -6,6 +6,17 @@ MESSAGE(STATUS "Using compiler: ${CMAKE_CXX_COMPILER}")
66MESSAGE (STATUS "Build Type: ${CMAKE_BUILD_TYPE } " )
77MESSAGE (STATUS "Arch: ${CMAKE_SYSTEM_PROCESSOR } " )
88
9+ # Ensure installed binaries know where to find project / ROS / torch libs
10+ set (INSTALL_RPATH_DIRS
11+ "${CMAKE_INSTALL_PREFIX } /lib"
12+ "${CMAKE_INSTALL_PREFIX } /${PROJECT_NAME } /lib" )
13+ if (DEFINED ENV{ROS_DISTRO})
14+ list (APPEND INSTALL_RPATH_DIRS "/opt/ros/$ENV{ROS_DISTRO} /lib" )
15+ endif ()
16+ set (CMAKE_SKIP_BUILD_RPATH FALSE )
17+ set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE )
18+ set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
19+
920# ROS2 compilation
1021MESSAGE (STATUS "Compiling with ROS2" )
1122add_compile_definitions (ROS2 )
@@ -71,6 +82,14 @@ else()
7182 MESSAGE (WARNING "LibTorch not found - deep learning evaluator disabled" )
7283endif ()
7384
85+ if (Torch_FOUND AND EXISTS "${TORCH_INSTALL_PREFIX} /lib" )
86+ list (APPEND INSTALL_RPATH_DIRS "${TORCH_INSTALL_PREFIX} /lib" )
87+ endif ()
88+ list (REMOVE_DUPLICATES INSTALL_RPATH_DIRS)
89+ set (CMAKE_INSTALL_RPATH "${INSTALL_RPATH_DIRS} " CACHE STRING "Install RPATH" FORCE )
90+ set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "Use link paths in install RPATH" FORCE )
91+ set (CMAKE_SKIP_INSTALL_RPATH FALSE CACHE BOOL "Keep RPATH on install" FORCE )
92+
7493# Use C++20 for auto parameters, but fallback to C++17 for compatibility
7594if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "10.0" )
7695 SET (CMAKE_CXX_FLAGS "-std=c++20 -Wall" )
@@ -237,6 +256,16 @@ target_include_directories(navigation_tests PRIVATE
237256 ${OpenCV_INCLUDE_DIRS}
238257)
239258
259+ set_target_properties (navigation PROPERTIES
260+ INSTALL_RPATH "${INSTALL_RPATH_DIRS} "
261+ BUILD_RPATH "${INSTALL_RPATH_DIRS} "
262+ )
263+
264+ set_target_properties (navigation_tests PROPERTIES
265+ INSTALL_RPATH "${INSTALL_RPATH_DIRS} "
266+ BUILD_RPATH "${INSTALL_RPATH_DIRS} "
267+ )
268+
240269# Install targets
241270install (TARGETS navigation navigation_tests
242271 DESTINATION lib/${PROJECT_NAME }
0 commit comments