cmake_minimum_required(VERSION 3.8)
project(mc)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)

# Generate message
rosidl_generate_interfaces(${PROJECT_NAME} "msg/CanFrame.msg" "msg/McCtrl.msg"
                           DEPENDENCIES std_msgs)

ament_export_dependencies(rosidl_default_runtime)

# 搜索 src 目录下所有 .cpp 文件
file(GLOB SRC_FILES src/*.cpp)

# 创建可执行文件
add_executable(mc_node ${SRC_FILES})

ament_target_dependencies(mc_node rclcpp std_msgs)
rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME}
                              "rosidl_typesupport_cpp")

target_link_libraries(mc_node ${cpp_typesupport_target})

# Set include directories for the target
target_include_directories(
  mc_node
  PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
         $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_cpp>
         $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_cpp>
         $<INSTALL_INTERFACE:include>)

target_compile_features(mc_node PUBLIC c_std_99 cxx_std_17) # Require C99 and
                                                            # C++17

# Install target
install(TARGETS mc_node DESTINATION lib/${PROJECT_NAME})

# 安装配置目录
install(DIRECTORY config DESTINATION share/${PROJECT_NAME})

# Handle testing if needed
if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # Skip linter checking for copyrights if not relevant
  set(ament_cmake_copyright_FOUND TRUE)
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
