cmake_minimum_required(VERSION 3.5)
project(past_control)

if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

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(std_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(nav2_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(visualization_msgs REQUIRED)
find_package(origincar_msg REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(builtin_interfaces REQUIRED)

# generate custom messages
rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/Obstacle.msg"
  "msg/ObstacleArray.msg"
  DEPENDENCIES std_msgs
  ADD_LINTER_TESTS
)

include_directories(include)

# lane_follower_node
add_executable(lane_follower_node
  src/lane_follower_node.cpp
)
ament_target_dependencies(lane_follower_node
  rclcpp std_msgs geometry_msgs
)

# obstacle_detector_node
add_executable(obstacle_detector_node
  src/obstacle_detector_node.cpp
)
ament_target_dependencies(obstacle_detector_node
  rclcpp std_msgs geometry_msgs nav_msgs tf2 tf2_ros visualization_msgs
)
rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME} rosidl_typesupport_cpp)
target_link_libraries(obstacle_detector_node ${cpp_typesupport_target})

# racing_orchestrator — subscribes to /plan (Nav2 planner_server) + PID following
add_executable(racing_orchestrator
  src/racing_orchestrator.cpp
)
ament_target_dependencies(racing_orchestrator
  rclcpp rclcpp_action std_msgs nav_msgs nav2_msgs geometry_msgs tf2 tf2_ros origincar_msg visualization_msgs
)

install(TARGETS
  lane_follower_node
  obstacle_detector_node
  racing_orchestrator
  DESTINATION lib/${PROJECT_NAME}
)

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

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  set(ament_cmake_copyright_FOUND TRUE)
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
