87 lines
3.5 KiB
CMake
87 lines
3.5 KiB
CMake
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_visualization_msgs with Catkin")
|
|
find_package(catkin REQUIRED)
|
|
else()
|
|
set(BUILDING_WITH_CATKIN FALSE)
|
|
message(STATUS "Building robot_visualization_msgs with Standalone CMake")
|
|
endif()
|
|
|
|
project(robot_visualization_msgs)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
# ========================================================
|
|
# Catkin specific configuration
|
|
# ========================================================
|
|
|
|
if(BUILDING_WITH_CATKIN)
|
|
## The catkin_package macro generates cmake config files for your package
|
|
## Note: Dependencies (robot_std_msgs) is not a Catkin package,
|
|
## it is built as a CMake target in the same workspace and will be available
|
|
## when this package is built. It is linked via target_link_libraries instead of CATKIN_DEPENDS
|
|
catkin_package(
|
|
INCLUDE_DIRS include
|
|
# LIBRARIES không cần vì đây là header-only library
|
|
# CATKIN_DEPENDS không cần vì dependencies không phải Catkin packages
|
|
)
|
|
endif()
|
|
|
|
# Thư viện header-only
|
|
add_library(robot_visualization_msgs INTERFACE)
|
|
|
|
# Include path tới thư mục chứa file header
|
|
target_include_directories(robot_visualization_msgs
|
|
INTERFACE
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
$<INSTALL_INTERFACE:include>
|
|
)
|
|
|
|
# Add include directories from dependencies explicitly for Catkin build
|
|
if(BUILDING_WITH_CATKIN)
|
|
# Use relative paths from current source directory
|
|
# From robot_visualization_msgs (pnkx_robot_nav_core2/src/Libraries/common_msgs/robot_visualization_msgs)
|
|
# to robot_std_msgs (pnkx_robot_nav_core2/src/Libraries/common_msgs/robot_std_msgs) is ../robot_std_msgs
|
|
get_filename_component(ROBOT_STD_MSGS_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/../robot_std_msgs/include" ABSOLUTE)
|
|
target_include_directories(robot_visualization_msgs INTERFACE
|
|
$<BUILD_INTERFACE:${ROBOT_STD_MSGS_INCLUDE}>
|
|
)
|
|
endif()
|
|
|
|
# Liên kết với robot_std_msgs nếu bạn có file Header.h trong include/robot_std_msgs/
|
|
target_link_libraries(robot_visualization_msgs INTERFACE robot_std_msgs)
|
|
|
|
# --- Cài đặt thư viện vào hệ thống khi chạy make install ---
|
|
# Export target trong mọi trường hợp để các target khác có thể export và phụ thuộc vào nó
|
|
install(TARGETS robot_visualization_msgs
|
|
EXPORT robot_visualization_msgs-targets
|
|
INCLUDES DESTINATION include # Cài đặt include
|
|
)
|
|
|
|
if(NOT BUILDING_WITH_CATKIN)
|
|
# Install headers for standalone mode
|
|
install(DIRECTORY include/
|
|
DESTINATION include
|
|
FILES_MATCHING PATTERN "*.h"
|
|
)
|
|
endif()
|
|
|
|
# --- Xuất export set robot_visualization_msgs-targets thành file CMake module ---
|
|
# --- Tạo file lib/cmake/robot_visualization_msgs/robot_visualization_msgs-targets.cmake ---
|
|
# --- File này chứa cấu hình giúp project khác có thể dùng ---
|
|
# --- Find_package(robot_visualization_msgs REQUIRED) ---
|
|
# --- Target_link_libraries(my_app PRIVATE robot_visualization_msgs::robot_visualization_msgs) ---
|
|
install(EXPORT robot_visualization_msgs-targets
|
|
FILE robot_visualization_msgs-targets.cmake
|
|
NAMESPACE robot_visualization_msgs::
|
|
DESTINATION lib/cmake/robot_visualization_msgs
|
|
)
|