cmake_minimum_required(VERSION 3.8)
project(vehicle_agent_gateway)

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

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(calibration_common_interfaces REQUIRED)
find_package(calibration_chassis_interfaces REQUIRED)
find_package(calibration_control_interfaces REQUIRED)
find_package(nlohmann_json REQUIRED)

# 共享库：包含帧协议层、TCP 客户端、两个网关节点组件
add_library(vehicle_agent_gateway_component SHARED
  src/proto_frame.cpp
  src/tcp_client.cpp
  src/chassis_bridge_node.cpp
  src/control_bridge_node.cpp
)

target_include_directories(vehicle_agent_gateway_component PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
)

ament_target_dependencies(vehicle_agent_gateway_component
  rclcpp
  rclcpp_action
  rclcpp_components
  calibration_common_interfaces
  calibration_chassis_interfaces
  calibration_control_interfaces
)

target_link_libraries(vehicle_agent_gateway_component
  nlohmann_json::nlohmann_json
)

rclcpp_components_register_nodes(vehicle_agent_gateway_component
  "vehicle_agent_gateway::ChassisBridgeNode"
  "vehicle_agent_gateway::ControlBridgeNode"
)

# 可执行：同进程启动两个节点
add_executable(vehicle_agent_gateway_node src/main.cpp)
ament_target_dependencies(vehicle_agent_gateway_node
  rclcpp
  rclcpp_components
)
target_link_libraries(vehicle_agent_gateway_node
  vehicle_agent_gateway_component
)

install(TARGETS
  vehicle_agent_gateway_component
  vehicle_agent_gateway_node
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY include/
  DESTINATION include/
)

install(DIRECTORY launch/
  DESTINATION share/${PROJECT_NAME}/launch
)

install(DIRECTORY scripts/
  DESTINATION share/${PROJECT_NAME}/scripts
)

ament_package()
