BUILD_SBPL_LATTICE_TESTS now defaults to OFF in both build modes instead of following BUILDING_WITH_CATKIN. Enable the tests with -DBUILD_SBPL_LATTICE_TESTS=ON.
251 lines
9.4 KiB
CMake
251 lines
9.4 KiB
CMake
cmake_minimum_required(VERSION 3.0.2)
|
|
project(sbpl_lattice_planner VERSION 1.0.0 LANGUAGES CXX)
|
|
|
|
if(DEFINED CATKIN_DEVEL_PREFIX OR DEFINED CATKIN_TOPLEVEL)
|
|
set(BUILDING_WITH_CATKIN TRUE)
|
|
message(STATUS "Building sbpl_lattice_planner with Catkin")
|
|
|
|
else()
|
|
set(BUILDING_WITH_CATKIN FALSE)
|
|
message(STATUS "Building sbpl_lattice_planner with Standalone CMake")
|
|
endif()
|
|
|
|
# C++ Standard - must be set before find_package
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
# Find dependencies
|
|
#
|
|
# Hai bản sbpl có thể cùng tồn tại trên máy: ros-noetic-sbpl (apt, 2020, /opt/ros/noetic, file
|
|
# libsbpl.so) và gói robot_sbpl (DuongTD/sbpl, file librobot_sbpl.so; in-tree src/Libraries/sbpl hoặc
|
|
# cài /usr/local). Chỉ robot_sbpl có abort flag (cancel cắt được lượt search). Tên file khác nhau nên
|
|
# bản apt không còn che được robot_sbpl lúc chạy.
|
|
#
|
|
# Build standalone của pnkx_nav_core: root CMake đã add_subdirectory(src/Libraries/sbpl) trước gói này,
|
|
# nên link thẳng target `robot_sbpl` — header và .so cùng một cây nguồn, không phụ thuộc bản cài.
|
|
# Build catkin (máy dev): dùng robot_sbpl đã cài (robot_sbpl_DIR). Còn bản cài cũ tên `sbpl` thì vẫn
|
|
# build được nhưng cảnh báo, vì lúc chạy bản apt có thể che nó. Sai bản thì configure cảnh báo, và lúc
|
|
# chạy plugin còn probe symbol trước khi đụng cờ (mismatch header/.so là ghi đè bộ nhớ).
|
|
if(TARGET robot_sbpl)
|
|
set(SBPL_INCLUDE_DIRS "${robot_sbpl_SOURCE_DIR}/src/include")
|
|
set(SBPL_LIBRARIES robot_sbpl)
|
|
message(STATUS "sbpl_lattice_planner: SBPL from the in-tree target 'robot_sbpl' (${robot_sbpl_SOURCE_DIR})")
|
|
else()
|
|
if(NOT DEFINED robot_sbpl_DIR AND EXISTS "/usr/local/share/robot_sbpl/robot_sbpl-config.cmake")
|
|
set(robot_sbpl_DIR "/usr/local/share/robot_sbpl" CACHE PATH "robot_sbpl config dir")
|
|
endif()
|
|
find_package(robot_sbpl QUIET)
|
|
if(robot_sbpl_FOUND)
|
|
set(SBPL_INCLUDE_DIRS ${robot_sbpl_INCLUDE_DIRS})
|
|
set(SBPL_LIBRARIES ${robot_sbpl_LIBRARIES})
|
|
message(STATUS "sbpl_lattice_planner: SBPL from robot_sbpl '${robot_sbpl_DIR}' (lib: ${SBPL_LIBRARIES})")
|
|
else()
|
|
if(NOT DEFINED SBPL_DIR AND EXISTS "/usr/local/share/sbpl/sbpl-config.cmake")
|
|
set(SBPL_DIR "/usr/local/share/sbpl" CACHE PATH "old sbpl config dir")
|
|
endif()
|
|
find_package(SBPL REQUIRED)
|
|
message(WARNING
|
|
"sbpl_lattice_planner: robot_sbpl not found, using the old sbpl install '${SBPL_DIR}' "
|
|
"(lib: ${SBPL_LIBRARIES}). Its file name libsbpl.so equals the one of ros-noetic-sbpl, which "
|
|
"LD_LIBRARY_PATH can load instead at runtime. Build and install DuongTD/sbpl again.")
|
|
endif()
|
|
endif()
|
|
set(_sbpl_planner_h "")
|
|
foreach(_dir ${SBPL_INCLUDE_DIRS})
|
|
if(EXISTS "${_dir}/sbpl/planners/planner.h")
|
|
set(_sbpl_planner_h "${_dir}/sbpl/planners/planner.h")
|
|
endif()
|
|
endforeach()
|
|
if(_sbpl_planner_h)
|
|
file(READ "${_sbpl_planner_h}" _sbpl_planner_h_text)
|
|
string(FIND "${_sbpl_planner_h_text}" "SBPL_HAS_ABORT_FLAG" _sbpl_abort_pos)
|
|
if(_sbpl_abort_pos EQUAL -1)
|
|
message(WARNING
|
|
"sbpl_lattice_planner: '${_sbpl_planner_h}' has no SBPL_HAS_ABORT_FLAG — this sbpl cannot be "
|
|
"preempted; cancel/pause will wait for allocated_time. Build+install Test/sbpl and point "
|
|
"-DSBPL_DIR=/usr/local/share/sbpl (or drop ros-noetic-sbpl) to get preempt.")
|
|
else()
|
|
message(STATUS "sbpl_lattice_planner: sbpl abort flag available (preempt on)")
|
|
endif()
|
|
endif()
|
|
find_package(Eigen3 REQUIRED)
|
|
find_package(Boost REQUIRED COMPONENTS system thread filesystem)
|
|
|
|
if (NOT BUILDING_WITH_CATKIN)
|
|
|
|
# Enable Position Independent Code
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
# Cấu hình RPATH để tránh cycle trong runtime search path
|
|
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
|
|
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|
set(CMAKE_BUILD_RPATH "${CMAKE_BINARY_DIR}")
|
|
|
|
set(PACKAGES_DIR
|
|
robot_visualization_msgs
|
|
robot_nav_msgs
|
|
robot_std_msgs
|
|
robot_geometry_msgs
|
|
tf3
|
|
robot_tf3_geometry_msgs
|
|
robot_time
|
|
data_convert
|
|
robot_costmap_2d
|
|
robot_nav_core
|
|
robot_protocol_msgs
|
|
robot_cpp
|
|
)
|
|
|
|
else()
|
|
|
|
# ========================================================
|
|
# Catkin specific configuration
|
|
# ========================================================
|
|
find_package(catkin REQUIRED COMPONENTS
|
|
robot_visualization_msgs
|
|
robot_nav_msgs
|
|
robot_std_msgs
|
|
robot_geometry_msgs
|
|
robot_tf3_geometry_msgs
|
|
robot_time
|
|
data_convert
|
|
robot_costmap_2d
|
|
robot_nav_core
|
|
robot_protocol_msgs
|
|
robot_cpp
|
|
)
|
|
|
|
find_library(TF3_LIBRARY NAMES tf3)
|
|
|
|
catkin_package(
|
|
INCLUDE_DIRS include
|
|
LIBRARIES ${PROJECT_NAME}
|
|
CATKIN_DEPENDS robot_visualization_msgs robot_nav_msgs robot_std_msgs robot_geometry_msgs robot_tf3_geometry_msgs robot_time data_convert robot_costmap_2d robot_nav_core robot_protocol_msgs robot_cpp
|
|
DEPENDS Eigen3 Boost SBPL # SBPL_INCLUDE_DIRS / SBPL_LIBRARIES are set above in every branch
|
|
)
|
|
|
|
include_directories(
|
|
include
|
|
${catkin_INCLUDE_DIRS}
|
|
${EIGEN3_INCLUDE_DIRS}
|
|
${Boost_INCLUDE_DIRS}
|
|
)
|
|
endif()
|
|
|
|
# ========================================================
|
|
# Libraries
|
|
# ========================================================
|
|
add_library(${PROJECT_NAME} SHARED
|
|
src/sbpl_lattice_planner.cpp
|
|
src/directional_environment.cpp
|
|
)
|
|
|
|
# Header sbpl phải là bản mà SBPL_DIR chọn, ĐỨNG TRƯỚC mọi include của catkin: /opt/ros/noetic/include
|
|
# (ros-noetic-sbpl, apt) cũng có sbpl/planners/planner.h và nếu đứng trước sẽ thắng — khi đó plugin
|
|
# build với header CŨ (không abort flag, preempt bị compile out) dù link libsbpl mới. Đã xảy ra
|
|
# 2026-09-11 trên máy dev: log "built against an sbpl without abort flag" trong khi cmake báo
|
|
# "preempt on". Lúc chạy: robot_sbpl mang file librobot_sbpl.so nên LD_LIBRARY_PATH của ROS
|
|
# (/opt/ros/noetic/lib đứng trước mọi RUNPATH) không còn thay nó bằng libsbpl.so của apt.
|
|
target_include_directories(${PROJECT_NAME} BEFORE PRIVATE ${SBPL_INCLUDE_DIRS})
|
|
|
|
if(BUILDING_WITH_CATKIN)
|
|
add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
|
|
|
|
target_include_directories(${PROJECT_NAME}
|
|
PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
$<INSTALL_INTERFACE:include>
|
|
)
|
|
|
|
target_link_libraries(${PROJECT_NAME}
|
|
PUBLIC ${catkin_LIBRARIES} ${SBPL_LIBRARIES}
|
|
PRIVATE Eigen3::Eigen Boost::system Boost::thread Boost::filesystem
|
|
)
|
|
|
|
else()
|
|
|
|
target_include_directories(${PROJECT_NAME}
|
|
PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
$<INSTALL_INTERFACE:include>
|
|
)
|
|
|
|
target_link_libraries(${PROJECT_NAME}
|
|
PUBLIC
|
|
${PACKAGES_DIR}
|
|
PRIVATE
|
|
${SBPL_LIBRARIES} Eigen3::Eigen Boost::system Boost::thread Boost::filesystem
|
|
)
|
|
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
|
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
BUILD_RPATH "${CMAKE_BINARY_DIR}"
|
|
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
|
|
)
|
|
|
|
endif()
|
|
|
|
# ========================================================
|
|
# Install
|
|
# ========================================================
|
|
if(BUILDING_WITH_CATKIN)
|
|
## Mark libraries for installation
|
|
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
|
|
install(TARGETS ${PROJECT_NAME}
|
|
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
|
|
)
|
|
|
|
## Mark cpp header files for installation
|
|
install(DIRECTORY include/${PROJECT_NAME}/
|
|
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
|
|
FILES_MATCHING PATTERN "*.h"
|
|
PATTERN ".svn" EXCLUDE
|
|
)
|
|
|
|
else()
|
|
|
|
install(TARGETS ${PROJECT_NAME}
|
|
EXPORT ${PROJECT_NAME}-targets
|
|
ARCHIVE DESTINATION lib
|
|
LIBRARY DESTINATION lib
|
|
RUNTIME DESTINATION bin
|
|
)
|
|
|
|
# Export targets
|
|
install(EXPORT ${PROJECT_NAME}-targets
|
|
FILE ${PROJECT_NAME}-targets.cmake
|
|
NAMESPACE ${PROJECT_NAME}::
|
|
DESTINATION lib/cmake/${PROJECT_NAME}
|
|
)
|
|
|
|
## Mark cpp header files for installation
|
|
install(DIRECTORY include/${PROJECT_NAME}/
|
|
DESTINATION include
|
|
FILES_MATCHING PATTERN "*.h"
|
|
PATTERN ".svn" EXCLUDE
|
|
)
|
|
|
|
# Print configuration info
|
|
message(STATUS "=================================")
|
|
message(STATUS "Project: ${PROJECT_NAME}")
|
|
message(STATUS "Version: ${PROJECT_VERSION}")
|
|
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
|
|
message(STATUS "Dependencies: robot_visualization_msgs, robot_nav_msgs, robot_std_msgs, robot_geometry_msgs, tf3, robot_tf3_geometry_msgs, robot_time, data_convert, robot_costmap_2d, robot_nav_core, robot_protocol_msgs, robot_cpp, Eigen3, Boost")
|
|
message(STATUS "=================================")
|
|
endif()
|
|
|
|
# Tests are OFF by default in both build modes; enable with -DBUILD_SBPL_LATTICE_TESTS=ON.
|
|
option(BUILD_SBPL_LATTICE_TESTS "Build sbpl_lattice_planner test executables" OFF)
|
|
if(BUILD_SBPL_LATTICE_TESTS)
|
|
find_package(GTest REQUIRED)
|
|
add_executable(direction_environment_test test/direction_environment_test.cpp)
|
|
target_include_directories(direction_environment_test BEFORE PRIVATE ${SBPL_INCLUDE_DIRS})
|
|
target_compile_definitions(direction_environment_test PRIVATE
|
|
DIRECTION_TEST_MPRIM="${CMAKE_CURRENT_SOURCE_DIR}/test/data/unicycle_0125.mprim")
|
|
target_link_libraries(direction_environment_test PRIVATE ${PROJECT_NAME} ${SBPL_LIBRARIES}
|
|
robot_costmap_2d GTest::GTest GTest::Main)
|
|
endif()
|