2025-10-30 11:10:23 +08:00
|
|
|
|
cmake_minimum_required(VERSION 3.8)
|
|
|
|
|
|
cmake_policy(SET CMP0074 NEW)
|
|
|
|
|
|
project(rslidar_pointcloud_merger)
|
|
|
|
|
|
|
|
|
|
|
|
# 1. 默认开启 C++17
|
|
|
|
|
|
if(NOT CMAKE_CXX_STANDARD)
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
2026-03-11 17:22:18 +08:00
|
|
|
|
add_compile_options(-w) # 禁用所有警告
|
2025-10-30 11:10:23 +08:00
|
|
|
|
endif()
|
|
|
|
|
|
|
2026-03-11 13:59:03 +08:00
|
|
|
|
# 检查是否启用GPU加速
|
2026-03-11 17:22:18 +08:00
|
|
|
|
option(USE_GPU "Enable GPU acceleration (requires CUDA)" ON)
|
2026-03-11 13:59:03 +08:00
|
|
|
|
|
2025-10-30 11:10:23 +08:00
|
|
|
|
find_package(ament_cmake REQUIRED)
|
|
|
|
|
|
find_package(rclcpp REQUIRED)
|
|
|
|
|
|
find_package(sensor_msgs REQUIRED)
|
|
|
|
|
|
find_package(pcl_conversions REQUIRED)
|
|
|
|
|
|
find_package(pcl_ros REQUIRED)
|
|
|
|
|
|
find_package(tf2 REQUIRED)
|
|
|
|
|
|
find_package(tf2_ros REQUIRED)
|
|
|
|
|
|
find_package(tf2_sensor_msgs REQUIRED)
|
|
|
|
|
|
find_package(PCL REQUIRED COMPONENTS common io)
|
|
|
|
|
|
|
2026-03-11 13:59:03 +08:00
|
|
|
|
# GPU加速相关配置
|
|
|
|
|
|
if(USE_GPU)
|
|
|
|
|
|
message(STATUS "GPU acceleration enabled")
|
|
|
|
|
|
enable_language(CUDA)
|
|
|
|
|
|
|
2026-03-11 17:22:18 +08:00
|
|
|
|
# 设置CUDA架构(Orin使用sm_87)
|
|
|
|
|
|
set(CMAKE_CUDA_ARCHITECTURES "87")
|
|
|
|
|
|
|
2026-03-11 13:59:03 +08:00
|
|
|
|
# 查找CUDA
|
|
|
|
|
|
find_package(CUDAToolkit QUIET)
|
|
|
|
|
|
if(CUDAToolkit_FOUND)
|
|
|
|
|
|
message(STATUS "CUDAToolkit found: ${CUDAToolkit_VERSION}")
|
|
|
|
|
|
add_definitions(-DUSE_GPU)
|
|
|
|
|
|
include_directories(${CUDAToolkit_INCLUDE_DIRS})
|
|
|
|
|
|
else()
|
|
|
|
|
|
message(WARNING "CUDAToolkit not found, GPU acceleration disabled")
|
|
|
|
|
|
set(USE_GPU OFF)
|
|
|
|
|
|
endif()
|
|
|
|
|
|
endif()
|
|
|
|
|
|
|
2026-03-11 17:22:18 +08:00
|
|
|
|
include_directories(include ${PCL_INCLUDE_DIRS})
|
2025-10-30 11:10:23 +08:00
|
|
|
|
|
2026-03-11 13:59:03 +08:00
|
|
|
|
# 源文件列表
|
|
|
|
|
|
set(SOURCES src/merge_two_lidars.cpp)
|
|
|
|
|
|
|
|
|
|
|
|
# 如果启用GPU,添加GPU源文件
|
|
|
|
|
|
if(USE_GPU)
|
|
|
|
|
|
list(APPEND SOURCES src/gpu_processing.cu)
|
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
add_executable(merge_two_lidars ${SOURCES})
|
2026-03-11 17:22:18 +08:00
|
|
|
|
ament_target_dependencies(
|
|
|
|
|
|
merge_two_lidars
|
|
|
|
|
|
rclcpp
|
|
|
|
|
|
sensor_msgs
|
|
|
|
|
|
pcl_conversions
|
|
|
|
|
|
pcl_ros
|
|
|
|
|
|
tf2
|
|
|
|
|
|
tf2_ros
|
|
|
|
|
|
tf2_sensor_msgs)
|
2025-10-30 11:10:23 +08:00
|
|
|
|
|
|
|
|
|
|
target_link_libraries(merge_two_lidars ${PCL_LIBRARIES})
|
|
|
|
|
|
|
2026-03-11 13:59:03 +08:00
|
|
|
|
# GPU加速链接库
|
|
|
|
|
|
if(USE_GPU)
|
|
|
|
|
|
target_link_libraries(merge_two_lidars CUDA::cudart)
|
|
|
|
|
|
if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.0)
|
|
|
|
|
|
target_compile_features(merge_two_lidars PRIVATE cuda_std_17)
|
|
|
|
|
|
else()
|
|
|
|
|
|
target_compile_features(merge_two_lidars PRIVATE cuda_std_14)
|
|
|
|
|
|
endif()
|
|
|
|
|
|
endif()
|
|
|
|
|
|
|
2026-03-11 17:22:18 +08:00
|
|
|
|
install(TARGETS merge_two_lidars DESTINATION lib/${PROJECT_NAME})
|
2025-10-30 11:10:23 +08:00
|
|
|
|
|
2026-03-11 17:22:18 +08:00
|
|
|
|
install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})
|
2025-10-30 11:10:23 +08:00
|
|
|
|
|
|
|
|
|
|
ament_package()
|