cmake_minimum_required(VERSION 3.10) project(robot_sensor_msgs) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # ======================================================== # Catkin specific configuration # ======================================================== if(DEFINED CATKIN_DEVEL_PREFIX OR DEFINED CATKIN_TOPLEVEL) set(BUILDING_WITH_CATKIN TRUE) message(STATUS "Building robot_sensor_msgs with Catkin") else() set(BUILDING_WITH_CATKIN FALSE) message(STATUS "Building robot_sensor_msgs with Standalone CMake") endif() if(BUILDING_WITH_CATKIN) find_package(catkin REQUIRED COMPONENTS robot_std_msgs robot_geometry_msgs) ## The catkin_package macro generates cmake config files for your package catkin_package( INCLUDE_DIRS include LIBRARIES robot_sensor_msgs CATKIN_DEPENDS robot_std_msgs robot_geometry_msgs ) endif() # Thư viện header-only add_library(robot_sensor_msgs INTERFACE) # Include path tới thư mục chứa file header target_include_directories(robot_sensor_msgs INTERFACE $ $ ) # 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_sensor_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_sensor_msgs EXPORT robot_sensor_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_sensor_msgs-targets thành file CMake module --- # --- Tạo file lib/cmake/robot_sensor_msgs/robot_sensor_msgs-targets.cmake --- # --- File này chứa cấu hình giúp project khác có thể dùng --- # --- Find_package(robot_sensor_msgs REQUIRED) --- # --- Target_link_libraries(my_app PRIVATE robot_sensor_msgs::robot_sensor_msgs) --- install(EXPORT robot_sensor_msgs-targets FILE robot_sensor_msgs-targets.cmake NAMESPACE robot_sensor_msgs:: DESTINATION lib/cmake/robot_sensor_msgs ) # Tạo file test ví dụ add_executable(test_battery_state test/main.cpp) target_link_libraries(test_battery_state PRIVATE robot_sensor_msgs)