BUILD_DOCK_PLANNER_TESTS now defaults to OFF in both build modes instead of following BUILDING_WITH_CATKIN. Enable the tests with -DBUILD_DOCK_PLANNER_TESTS=ON.
192 lines
5.7 KiB
CMake
192 lines
5.7 KiB
CMake
cmake_minimum_required(VERSION 3.0.2)
|
|
project(dock_planner VERSION 1.0.0 LANGUAGES CXX)
|
|
|
|
if(DEFINED CATKIN_DEVEL_PREFIX OR DEFINED CATKIN_TOPLEVEL)
|
|
set(BUILDING_WITH_CATKIN TRUE)
|
|
message(STATUS "Building dock_planner with Catkin")
|
|
else()
|
|
set(BUILDING_WITH_CATKIN FALSE)
|
|
message(STATUS "Building dock_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. Boost is header-only here (boost/dll/alias.hpp exports the
|
|
# plugin symbol); no Boost component library is linked.
|
|
find_package(Boost REQUIRED)
|
|
find_package(yaml-cpp REQUIRED)
|
|
# librobot_time.so calls pthread_create but does not export the dependency;
|
|
# link it explicitly instead of inheriting it from an unrelated Boost component.
|
|
find_package(Threads REQUIRED)
|
|
|
|
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}")
|
|
|
|
# Library targets provided by the standalone parent build.
|
|
set(STANDALONE_DEP_TARGETS
|
|
robot_geometry_msgs
|
|
robot_time
|
|
data_convert
|
|
robot_costmap_2d
|
|
robot_nav_core
|
|
robot_cpp
|
|
)
|
|
|
|
else()
|
|
|
|
# ========================================================
|
|
# Catkin specific configuration
|
|
# ========================================================
|
|
find_package(catkin REQUIRED COMPONENTS
|
|
robot_geometry_msgs
|
|
robot_time
|
|
data_convert
|
|
robot_costmap_2d
|
|
robot_nav_core
|
|
robot_cpp
|
|
)
|
|
|
|
catkin_package(
|
|
INCLUDE_DIRS include
|
|
LIBRARIES ${PROJECT_NAME}
|
|
CATKIN_DEPENDS robot_geometry_msgs robot_time data_convert robot_costmap_2d robot_nav_core robot_cpp
|
|
DEPENDS Boost
|
|
)
|
|
endif()
|
|
|
|
# ========================================================
|
|
# Libraries
|
|
# ========================================================
|
|
add_library(${PROJECT_NAME} SHARED
|
|
src/dock_planner.cpp
|
|
src/dock_planner_config.cpp
|
|
src/dock_calc.cpp
|
|
)
|
|
|
|
target_include_directories(${PROJECT_NAME}
|
|
PUBLIC
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
$<INSTALL_INTERFACE:include>
|
|
PRIVATE
|
|
${Boost_INCLUDE_DIRS}
|
|
)
|
|
|
|
if(BUILDING_WITH_CATKIN)
|
|
add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
|
|
|
|
target_include_directories(${PROJECT_NAME} PUBLIC ${catkin_INCLUDE_DIRS})
|
|
|
|
target_link_libraries(${PROJECT_NAME}
|
|
PUBLIC ${catkin_LIBRARIES} Threads::Threads
|
|
PRIVATE yaml-cpp
|
|
)
|
|
|
|
else()
|
|
|
|
target_link_libraries(${PROJECT_NAME}
|
|
PUBLIC
|
|
${STANDALONE_DEP_TARGETS}
|
|
Threads::Threads
|
|
PRIVATE
|
|
yaml-cpp
|
|
)
|
|
|
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
|
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
BUILD_RPATH "${CMAKE_BINARY_DIR}"
|
|
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
|
|
)
|
|
|
|
endif()
|
|
|
|
if(COMMAND target_link_options)
|
|
target_link_options(${PROJECT_NAME} PRIVATE -Wl,--no-undefined)
|
|
endif()
|
|
|
|
# Focused contract tests use a tiny self-contained runner so both catkin and
|
|
# standalone builds exercise the same code without adding a test dependency.
|
|
#
|
|
# Tests are OFF by default in both build modes; enable with
|
|
# -DBUILD_DOCK_PLANNER_TESTS=ON.
|
|
#
|
|
# include(CTest) used to sit here for the standalone branch. It is deliberately
|
|
# gone: it defines BUILD_TESTING=ON for the WHOLE CMake tree, which switched the
|
|
# tests of every other package in the aggregate build back on.
|
|
option(BUILD_DOCK_PLANNER_TESTS "Build the dock_planner contract tests"
|
|
OFF)
|
|
|
|
if(BUILD_DOCK_PLANNER_TESTS AND
|
|
(NOT BUILDING_WITH_CATKIN OR CATKIN_ENABLE_TESTING))
|
|
if(NOT BUILDING_WITH_CATKIN)
|
|
enable_testing()
|
|
endif()
|
|
add_executable(${PROJECT_NAME}_test test/dock_planner_test.cpp)
|
|
# The test builds YAML nodes for the config loader directly; the library links
|
|
# yaml-cpp PRIVATE and does not pass it on, so the test links it itself.
|
|
target_link_libraries(${PROJECT_NAME}_test PRIVATE ${PROJECT_NAME} yaml-cpp)
|
|
if(BUILDING_WITH_CATKIN)
|
|
add_dependencies(${PROJECT_NAME}_test ${catkin_EXPORTED_TARGETS})
|
|
endif()
|
|
add_test(NAME ${PROJECT_NAME}_test COMMAND ${PROJECT_NAME}_test)
|
|
endif()
|
|
|
|
# ========================================================
|
|
# Install
|
|
# ========================================================
|
|
if(BUILDING_WITH_CATKIN)
|
|
## Mark libraries for installation
|
|
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_geometry_msgs, robot_time, data_convert, robot_costmap_2d, robot_nav_core, robot_cpp, Boost (headers), yaml-cpp")
|
|
message(STATUS "=================================")
|
|
endif()
|