build: add the standalone branch this package never had

find_package(catkin REQUIRED ...) sat at top level, so a build without catkin
died at configure time - and it died pointing at a package that IS present:

    Could not find a package configuration file provided by "recovery_core"

recovery_core is in the tree and was added before this package. What is absent
is recovery_coreConfig.cmake, which only a catkin workspace produces. The error
sends you looking for a missing package instead of a missing build mode.

Standalone names the CMake targets directly rather than searching for them. The
root CMakeLists adds every package before this one, so their include
directories arrive through each target's PUBLIC interface - the order in that
file is the real constraint, not anything expressed here.

The plugin also goes to the top of the build tree in standalone mode. It is
loaded by boost::dll under a filename that PluginLoaderHelper resolves against
the build directory; left in its own subdirectory, it builds and is then
invisible at runtime.

Separately: catkin_add_gtest marks the test EXCLUDE_FROM_ALL, so catkin_make
never built it and ctest then failed with

    /bin/sh: 1: .../devel/lib/sbpl_recovery/detour_path_recovery_test: not found

which reads as a broken test rather than a missing binary. Every other package
in this repository opens the target back up; this one did not. It does now, and
the 24 tests pass.
This commit is contained in:
2026-08-27 10:37:37 +07:00
parent 72435b76fd
commit d1fd7230c0

View File

@@ -1,20 +1,33 @@
cmake_minimum_required(VERSION 3.10)
project(sbpl_recovery)
# ==================================================================================================
# Phát hiện chế độ build
#
# Gói này build được ở HAI chế độ và phải giữ cả hai:
# - catkin (`catkin_make` trong T800_ws)
# - standalone (root CMakeLists của pnkx_nav_core, không có catkin)
#
# Trước đây chỉ có nhánh catkin, và `find_package(catkin REQUIRED ...)` nằm ở cấp cao nhất nên
# build standalone chết ngay lúc configure với thông báo gây hiểu nhầm:
#
# Could not find a package configuration file provided by "recovery_core"
#
# `recovery_core` CÓ trong cây và đã được add trước đó — thứ không tồn tại là
# `recovery_coreConfig.cmake`, file mà chỉ một workspace catkin mới sinh ra.
# ==================================================================================================
if(DEFINED CATKIN_DEVEL_PREFIX OR DEFINED CATKIN_TOPLEVEL)
set(BUILDING_WITH_CATKIN TRUE)
message(STATUS "Building sbpl_recovery with Catkin")
else()
set(BUILDING_WITH_CATKIN FALSE)
message(STATUS "Building sbpl_recovery with Standalone CMake")
endif()
# C++17 theo quy ước workspace cho code mới.
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(catkin REQUIRED COMPONENTS
recovery_core
robot_cpp
robot_costmap_2d
robot_nav_core
robot_geometry_msgs
robot_nav_msgs
robot_tf3_geometry_msgs
)
find_package(Boost REQUIRED COMPONENTS
system
filesystem
@@ -39,14 +52,9 @@ if(NOT TF3_LIBRARY)
"Controllers/, Devices/, Localizations/) or add its location to CMAKE_PREFIX_PATH.")
endif()
catkin_package(
INCLUDE_DIRS
include
if(BUILDING_WITH_CATKIN)
LIBRARIES
sbpl_recovery
CATKIN_DEPENDS
find_package(catkin REQUIRED COMPONENTS
recovery_core
robot_cpp
robot_costmap_2d
@@ -54,10 +62,52 @@ catkin_package(
robot_geometry_msgs
robot_nav_msgs
robot_tf3_geometry_msgs
)
DEPENDS
Boost
)
catkin_package(
INCLUDE_DIRS
include
LIBRARIES
sbpl_recovery
CATKIN_DEPENDS
recovery_core
robot_cpp
robot_costmap_2d
robot_nav_core
robot_geometry_msgs
robot_nav_msgs
robot_tf3_geometry_msgs
DEPENDS
Boost
)
else()
# Ở chế độ standalone không có catkin để tra gói. Root CMakeLists của pnkx_nav_core đã
# `add_subdirectory` mọi gói trước gói này, nên chỉ cần NÊU TÊN TARGET: include của chúng tự lan
# sang qua interface PUBLIC, không phải khai lại đường dẫn.
#
# Thứ tự trong root CMakeLists là ràng buộc thật: gói này phải đứng sau `recovery_core` và
# `sbpl_lattice_planner`.
set(SBPL_RECOVERY_STANDALONE_LIBRARIES
recovery_core
robot_cpp
robot_costmap_2d
robot_nav_core
robot_geometry_msgs
robot_nav_msgs
robot_tf3_geometry_msgs
)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_BUILD_RPATH "${CMAKE_BINARY_DIR}")
endif()
# ==================================================================================================
# Plugin: libsbpl_recovery.so — export symbol `DetourPathRecovery` (Boost.DLL)
@@ -74,34 +124,75 @@ target_compile_options(sbpl_recovery PRIVATE -Wall -Wextra)
target_include_directories(sbpl_recovery SYSTEM
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
target_link_libraries(sbpl_recovery
PRIVATE
${catkin_LIBRARIES}
Boost::system
Boost::filesystem
Boost::thread
Threads::Threads
${CMAKE_DL_LIBS}
${TF3_LIBRARY}
)
if(BUILDING_WITH_CATKIN)
add_dependencies(sbpl_recovery ${catkin_EXPORTED_TARGETS})
target_include_directories(sbpl_recovery SYSTEM PRIVATE ${catkin_INCLUDE_DIRS})
install(TARGETS sbpl_recovery
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)
target_link_libraries(sbpl_recovery
PRIVATE
${catkin_LIBRARIES}
Boost::system
Boost::filesystem
Boost::thread
Threads::Threads
${CMAKE_DL_LIBS}
${TF3_LIBRARY}
)
add_dependencies(sbpl_recovery ${catkin_EXPORTED_TARGETS})
install(TARGETS sbpl_recovery
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)
else()
target_link_libraries(sbpl_recovery
PRIVATE
${SBPL_RECOVERY_STANDALONE_LIBRARIES}
Boost::system
Boost::filesystem
Boost::thread
Threads::Threads
${CMAKE_DL_LIBS}
${TF3_LIBRARY}
)
# Plugin được nạp bằng boost::dll theo TÊN FILE, và `PluginLoaderHelper` tra trong thư mục build.
# Đổ .so về gốc build như mọi plugin khác của cây standalone, nếu không runtime không thấy nó.
set_target_properties(sbpl_recovery PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
BUILD_RPATH "${CMAKE_BINARY_DIR}"
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
)
include(GNUInstallDirs)
install(TARGETS sbpl_recovery
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
FILES_MATCHING PATTERN "*.h"
)
endif()
# ==================================================================================================
# Test
# ==================================================================================================
if(CATKIN_ENABLE_TESTING)
# Test chạy qua `catkin_add_gtest` và cần `CATKIN_DEVEL_PREFIX` để biết plugin nằm ở đâu, nên chỉ
# có ở nhánh catkin. Ở standalone, thư viện vẫn build — chỉ không có test.
if(CATKIN_ENABLE_TESTING AND BUILDING_WITH_CATKIN)
# Planner giả cho unit test — nạp qua đúng đường Boost.DLL mà runtime đi.
add_library(sbpl_recovery_test_line_planner SHARED
test/plugins/test_line_planner.cpp
@@ -123,6 +214,14 @@ if(CATKIN_ENABLE_TESTING)
catkin_add_gtest(detour_path_recovery_test test/detour_path_recovery_test.cpp)
if(TARGET detour_path_recovery_test)
# catkin_add_gtest đặt target EXCLUDE_FROM_ALL, nên `catkin_make` thường KHÔNG build nó và
# `ctest` sau đó báo fail vì không tìm thấy binary — trông y hệt một test hỏng thật:
#
# /bin/sh: 1: .../devel/lib/sbpl_recovery/detour_path_recovery_test: not found
#
# Mở ra như các gói khác trong repo, để quy trình verify (`catkin_make` rồi chạy test) đúng là
# thứ nó tỏ ra.
set_target_properties(detour_path_recovery_test PROPERTIES EXCLUDE_FROM_ALL FALSE)
target_compile_options(detour_path_recovery_test PRIVATE -Wall -Wextra)
target_compile_definitions(detour_path_recovery_test PRIVATE
SBPL_RECOVERY_TEST_CONFIG_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test/config"