This commit is contained in:
HiepLM 2026-01-07 09:18:57 +07:00
parent 831e4e00d7
commit 7cb758a986
2 changed files with 87 additions and 13 deletions

View File

@ -1,4 +1,18 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
# ========================================================
# Dual-mode CMakeLists.txt: Supports both Catkin and Standalone CMake
# ========================================================
# Detect if building with Catkin
if(DEFINED CATKIN_DEVEL_PREFIX OR DEFINED CATKIN_TOPLEVEL)
set(BUILDING_WITH_CATKIN TRUE)
message(STATUS "Building robot_laser_geometry with Catkin")
else()
set(BUILDING_WITH_CATKIN FALSE)
message(STATUS "Building robot_laser_geometry with Standalone CMake")
endif()
project(robot_laser_geometry) project(robot_laser_geometry)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
@ -6,10 +20,37 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(CTest) include(CTest)
# ========================================================
# Find dependencies # Find dependencies
# ========================================================
# Find system dependencies
find_package(Eigen3 REQUIRED) find_package(Eigen3 REQUIRED)
find_package(GTest REQUIRED) find_package(GTest REQUIRED)
if(BUILDING_WITH_CATKIN)
find_package(catkin REQUIRED COMPONENTS
robot_sensor_msgs
geometry_msgs
robot_time
tf3
data_convert
)
endif()
# ========================================================
# Catkin specific configuration
# ========================================================
if(BUILDING_WITH_CATKIN)
catkin_package(
INCLUDE_DIRS include
LIBRARIES robot_laser_geometry
CATKIN_DEPENDS robot_sensor_msgs geometry_msgs robot_time tf3 data_convert
DEPENDS Eigen3
)
endif()
# Include directories # Include directories
include_directories( include_directories(
include include
@ -17,6 +58,10 @@ include_directories(
${GTEST_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}
) )
if(BUILDING_WITH_CATKIN)
include_directories(${catkin_INCLUDE_DIRS})
endif()
# Create library # Create library
add_library(robot_laser_geometry SHARED src/laser_geometry.cpp) add_library(robot_laser_geometry SHARED src/laser_geometry.cpp)
@ -26,6 +71,12 @@ target_include_directories(robot_laser_geometry
$<INSTALL_INTERFACE:include/${PROJECT_NAME}> $<INSTALL_INTERFACE:include/${PROJECT_NAME}>
) )
# Link libraries
if(BUILDING_WITH_CATKIN)
target_link_libraries(robot_laser_geometry PUBLIC
${catkin_LIBRARIES}
)
else()
target_link_libraries(robot_laser_geometry PUBLIC target_link_libraries(robot_laser_geometry PUBLIC
robot_sensor_msgs robot_sensor_msgs
geometry_msgs geometry_msgs
@ -33,6 +84,11 @@ target_link_libraries(robot_laser_geometry PUBLIC
tf3 tf3
data_convert data_convert
) )
endif()
if(BUILDING_WITH_CATKIN)
add_dependencies(robot_laser_geometry ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
endif()
if(TARGET Eigen3::Eigen) if(TARGET Eigen3::Eigen)
target_link_libraries(robot_laser_geometry PUBLIC Eigen3::Eigen) target_link_libraries(robot_laser_geometry PUBLIC Eigen3::Eigen)
@ -44,6 +100,10 @@ endif()
# which is appropriate when building the dll but not consuming it. # which is appropriate when building the dll but not consuming it.
target_compile_definitions(robot_laser_geometry PRIVATE "ROBOT_LASER_GEOMETRY_BUILDING_LIBRARY") target_compile_definitions(robot_laser_geometry PRIVATE "ROBOT_LASER_GEOMETRY_BUILDING_LIBRARY")
# ========================================================
# Installation
# ========================================================
# --- Cài đt thư vin vào h thng khi chy make install --- # --- Cài đt thư vin vào h thng khi chy make install ---
install(TARGETS robot_laser_geometry install(TARGETS robot_laser_geometry
EXPORT robot_laser_geometry-targets EXPORT robot_laser_geometry-targets
@ -53,10 +113,13 @@ install(TARGETS robot_laser_geometry
INCLUDES DESTINATION include # Cài đt include INCLUDES DESTINATION include # Cài đt include
) )
if(NOT BUILDING_WITH_CATKIN)
# Cài đt headers (standalone)
install( install(
DIRECTORY include/ DIRECTORY include/
DESTINATION include/${PROJECT_NAME} DESTINATION include/${PROJECT_NAME}
) )
endif()
# --- Xut export set robot_laser_geometry-targets thành file CMake module --- # --- Xut export set robot_laser_geometry-targets thành file CMake module ---
# --- To file lib/cmake/robot_laser_geometry/laser_geometry-targets.cmake --- # --- To file lib/cmake/robot_laser_geometry/laser_geometry-targets.cmake ---

View File

@ -19,8 +19,19 @@
<buildtool_depend version_gte="0.5.68">catkin</buildtool_depend> <buildtool_depend version_gte="0.5.68">catkin</buildtool_depend>
<build_depend>libconsole-bridge-dev</build_depend> <build_depend>robot_sensor_msgs</build_depend>
<run_depend>robot_sensor_msgs</run_depend>
<run_depend>libconsole-bridge-dev</run_depend> <build_depend>geometry_msgs</build_depend>
<run_depend>geometry_msgs</run_depend>
<build_depend>robot_time</build_depend>
<run_depend>robot_time</run_depend>
<build_depend>tf3</build_depend>
<run_depend>tf3</run_depend>
<build_depend>data_convert</build_depend>
<run_depend>data_convert</run_depend>
</package> </package>