Tests used to build whenever CATKIN_ENABLE_TESTING was on. They now also need -DBUILD_SBPL_RECOVERY_TESTS=ON, in both build modes.
255 lines
8.3 KiB
CMake
255 lines
8.3 KiB
CMake
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(Boost REQUIRED COMPONENTS
|
|
system
|
|
filesystem
|
|
thread
|
|
)
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
# tf3 cài sẵn ngoài workspace (xem CLAUDE.md) — không phải package catkin.
|
|
find_library(TF3_LIBRARY
|
|
NAMES tf3
|
|
|
|
PATHS
|
|
/usr/lib
|
|
/usr/local/lib
|
|
/usr/lib/x86_64-linux-gnu
|
|
)
|
|
|
|
if(NOT TF3_LIBRARY)
|
|
message(FATAL_ERROR
|
|
"sbpl_recovery: libtf3 not found. Install tf3 (see the auto_setup.sh scripts under "
|
|
"Controllers/, Devices/, Localizations/) or add its location to CMAKE_PREFIX_PATH.")
|
|
endif()
|
|
|
|
if(BUILDING_WITH_CATKIN)
|
|
|
|
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
|
|
)
|
|
|
|
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)
|
|
# ==================================================================================================
|
|
|
|
add_library(sbpl_recovery SHARED
|
|
plugins/detour_path_recovery.cpp
|
|
)
|
|
|
|
target_compile_options(sbpl_recovery PRIVATE -Wall -Wextra)
|
|
|
|
# Header dependency vào dạng SYSTEM để -Wall -Wextra của chính gói không bị warning của
|
|
# robot_cpp/costmap_2d nhấn chìm — cùng lý do với recovery_core.
|
|
target_include_directories(sbpl_recovery SYSTEM
|
|
PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
${Boost_INCLUDE_DIRS}
|
|
)
|
|
|
|
if(BUILDING_WITH_CATKIN)
|
|
|
|
target_include_directories(sbpl_recovery SYSTEM PRIVATE ${catkin_INCLUDE_DIRS})
|
|
|
|
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
|
|
# ==================================================================================================
|
|
|
|
# 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.
|
|
# Test mặc định OFF trong cả hai chế độ build; bật bằng -DBUILD_SBPL_RECOVERY_TESTS=ON.
|
|
option(BUILD_SBPL_RECOVERY_TESTS "Build the sbpl_recovery unit tests" OFF)
|
|
|
|
if(BUILD_SBPL_RECOVERY_TESTS AND 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
|
|
)
|
|
target_compile_options(sbpl_recovery_test_line_planner PRIVATE -Wall -Wextra)
|
|
target_include_directories(sbpl_recovery_test_line_planner SYSTEM
|
|
PRIVATE
|
|
${catkin_INCLUDE_DIRS}
|
|
${Boost_INCLUDE_DIRS}
|
|
)
|
|
target_link_libraries(sbpl_recovery_test_line_planner
|
|
PRIVATE
|
|
${catkin_LIBRARIES}
|
|
Boost::system
|
|
Boost::filesystem
|
|
Threads::Threads
|
|
${CMAKE_DL_LIBS}
|
|
)
|
|
|
|
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"
|
|
SBPL_RECOVERY_TEST_LIBRARY_DIR="${CATKIN_DEVEL_PREFIX}/lib"
|
|
)
|
|
target_include_directories(detour_path_recovery_test SYSTEM
|
|
PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
${catkin_INCLUDE_DIRS}
|
|
${Boost_INCLUDE_DIRS}
|
|
)
|
|
# catkin_add_gtest dùng target_link_libraries dạng plain, nên phần bổ sung cũng phải plain.
|
|
target_link_libraries(detour_path_recovery_test
|
|
${catkin_LIBRARIES}
|
|
${Boost_LIBRARIES}
|
|
pthread
|
|
${CMAKE_DL_LIBS}
|
|
${TF3_LIBRARY}
|
|
)
|
|
# Plugin KHÔNG link thẳng vào test: chúng được nạp qua RecoveryRegistry lúc chạy, đúng đường
|
|
# runtime — nhưng phải build xong trước khi test chạy.
|
|
add_dependencies(detour_path_recovery_test
|
|
sbpl_recovery
|
|
sbpl_recovery_test_line_planner
|
|
)
|
|
endif()
|
|
endif()
|