This commit is contained in:
HiepLM 2025-12-29 17:10:32 +07:00
parent a09cd3d98b
commit cbdf8e6525

View File

@ -29,24 +29,6 @@ endif()
# ======================================================== # ========================================================
find_package(Boost REQUIRED) find_package(Boost REQUIRED)
# If building with Catkin, use catkin_package to find dependencies
if(BUILDING_WITH_CATKIN)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
geometry_msgs
nav_msgs
tf2
tf2_ros
actionlib
dynamic_reconfigure
)
# Find internal packages (these should be built in the same workspace)
# Catkin will handle these through workspace dependencies
find_package(yaml-cpp REQUIRED)
endif()
# ======================================================== # ========================================================
# Source Files # Source Files
@ -61,11 +43,6 @@ include_directories(
${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/include
) )
if(BUILDING_WITH_CATKIN)
include_directories(
${catkin_INCLUDE_DIRS}
)
endif()
# ======================================================== # ========================================================
# RPATH settings: ưu tiên thư vin build ti ch # RPATH settings: ưu tiên thư vin build ti ch
@ -84,57 +61,9 @@ add_library(move_base SHARED ${SOURCES} ${HEADERS})
# ======================================================== # ========================================================
# Dependencies and Link Libraries # Dependencies and Link Libraries
# ======================================================== # ========================================================
if(BUILDING_WITH_CATKIN)
# Catkin mode: use catkin dependencies
catkin_package(
INCLUDE_DIRS include
LIBRARIES move_base
CATKIN_DEPENDS
roscpp
rospy
std_msgs
geometry_msgs
nav_msgs
tf2
tf2_ros
actionlib
dynamic_reconfigure
DEPENDS
yaml-cpp
Boost
)
# Link against catkin packages # Standalone CMake mode: link all dependencies manually
target_link_libraries(move_base set(PACKAGES_DIR
${catkin_LIBRARIES}
${Boost_LIBRARIES}
yaml-cpp
)
# Internal packages (assumed to be in same workspace)
# These will be linked via catkin workspace dependencies
target_link_libraries(move_base
move_base_core
nav_core
costmap_2d
plugins # Link vi plugins library đ có StaticLayer typeinfo
xmlrpcpp
robot_cpp
tf3_sensor_msgs
tf3_geometry_msgs
dl
pthread
)
# Set RPATH đ ưu tiên thư vin build cc b
set_target_properties(move_base PROPERTIES
BUILD_RPATH "${CMAKE_BINARY_DIR}/src/Libraries/costmap_2d:${CMAKE_BINARY_DIR}/src/Libraries/node_handle:${CMAKE_BINARY_DIR}/src/Libraries/tf3:${CMAKE_BINARY_DIR}/src/Libraries/robot_time:${CMAKE_BINARY_DIR}/src/Libraries/xmlrpcpp"
INSTALL_RPATH "${CMAKE_BINARY_DIR}/src/Libraries/costmap_2d:${CMAKE_BINARY_DIR}/src/Libraries/node_handle:${CMAKE_BINARY_DIR}/src/Libraries/tf3:${CMAKE_BINARY_DIR}/src/Libraries/robot_time:${CMAKE_BINARY_DIR}/src/Libraries/xmlrpcpp"
LINK_FLAGS "-Wl,--disable-new-dtags"
)
else()
# Standalone CMake mode: link all dependencies manually
set(PACKAGES_DIR
geometry_msgs geometry_msgs
std_msgs std_msgs
move_base_core move_base_core
@ -149,19 +78,19 @@ else()
dl dl
pthread pthread
robot_nav_2d_utils robot_nav_2d_utils
) )
target_link_libraries(move_base target_link_libraries(move_base
PUBLIC ${PACKAGES_DIR} PUBLIC ${PACKAGES_DIR}
PUBLIC robot_cpp PUBLIC robot_cpp
PRIVATE Boost::boost PRIVATE Boost::boost
) )
# Set RPATH đ ưu tiên thư vin build cc b # Set RPATH đ ưu tiên thư vin build cc b
set_target_properties(move_base PROPERTIES set_target_properties(move_base PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
) )
endif()
# ======================================================== # ========================================================
# Include Directories for Target # Include Directories for Target
@ -187,12 +116,6 @@ target_link_libraries(move_base_main
PRIVATE Boost::boost PRIVATE Boost::boost
) )
if(BUILDING_WITH_CATKIN)
target_link_libraries(move_base_main
PRIVATE ${catkin_LIBRARIES}
)
endif()
# Set RPATH for executable to find libraries in build directory first # Set RPATH for executable to find libraries in build directory first
# Use RPATH instead of RUNPATH for higher priority # Use RPATH instead of RUNPATH for higher priority
set_target_properties(move_base_main PROPERTIES set_target_properties(move_base_main PROPERTIES
@ -208,37 +131,25 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--disable-new-dtags")
# ======================================================== # ========================================================
# Installation # Installation
# ======================================================== # ========================================================
if(BUILDING_WITH_CATKIN)
# Catkin installation
install(DIRECTORY include/move_base
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
)
install(TARGETS move_base move_base_main # Standalone CMake installation
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} install(DIRECTORY include/move_base
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)
else()
# Standalone CMake installation
install(DIRECTORY include/move_base
DESTINATION include DESTINATION include
FILES_MATCHING PATTERN "*.h" FILES_MATCHING PATTERN "*.h"
) )
install(TARGETS move_base move_base_main install(TARGETS move_base move_base_main
EXPORT move_base-targets EXPORT move_base-targets
LIBRARY DESTINATION lib LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
) )
install(EXPORT move_base-targets install(EXPORT move_base-targets
FILE move_base-targets.cmake FILE move_base-targets.cmake
DESTINATION lib/cmake/move_base DESTINATION lib/cmake/move_base
) )
endif()
# ======================================================== # ========================================================
# Build Options # Build Options