cmake_minimum_required(VERSION 3.8)
project(obstacle_scanner)

if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 17)
endif()

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/Obstacle.msg"
  "msg/ObstacleArray.msg"
  DEPENDENCIES std_msgs
)

add_executable(obstacle_scanner_node
  src/obstacle_scanner_node.cpp
  src/detection.cpp
  src/tracking.cpp
)
target_compile_features(obstacle_scanner_node PUBLIC cxx_std_17)
target_include_directories(obstacle_scanner_node PUBLIC include ${EIGEN3_INCLUDE_DIRS})
ament_target_dependencies(obstacle_scanner_node
  rclcpp
  sensor_msgs
  std_msgs
  cv_bridge
  OpenCV
)
rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME} "rosidl_typesupport_cpp")
target_link_libraries(obstacle_scanner_node ${cpp_typesupport_target})

install(TARGETS obstacle_scanner_node
  DESTINATION lib/${PROJECT_NAME}
)

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

ament_export_dependencies(rosidl_default_runtime)

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

  ament_add_gtest(test_tracking test/test_tracking.cpp src/tracking.cpp)
  target_include_directories(test_tracking PUBLIC include ${EIGEN3_INCLUDE_DIRS})

  ament_add_gtest(test_detection test/test_detection.cpp src/detection.cpp)
  target_include_directories(test_detection PUBLIC include ${EIGEN3_INCLUDE_DIRS})
endif()

ament_package()
