cmake_minimum_required(VERSION 3.8)
project(obstacle_nav2)

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

find_package(ament_cmake REQUIRED)
find_package(nav2_costmap_2d REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(obstacle_scanner REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(std_msgs REQUIRED)

add_library(obstacle_array_layer SHARED
  src/obstacle_array_layer.cpp
)
target_include_directories(obstacle_array_layer PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
)
ament_target_dependencies(obstacle_array_layer
  nav2_costmap_2d
  pluginlib
  rclcpp
  tf2
  tf2_ros
  tf2_geometry_msgs
  obstacle_scanner
  geometry_msgs
  nav_msgs
  std_msgs
)

pluginlib_export_plugin_description_file(nav2_costmap_2d obstacle_nav2_plugins.xml)

install(TARGETS obstacle_array_layer
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)
install(DIRECTORY include/ DESTINATION include)
install(FILES obstacle_nav2_plugins.xml DESTINATION share/${PROJECT_NAME})

if(BUILD_TESTING)
  find_package(ament_cmake_gtest REQUIRED)
  ament_add_gtest(test_obstacle_array_layer test/test_obstacle_array_layer.cpp
    src/obstacle_array_layer.cpp
  )
  target_include_directories(test_obstacle_array_layer PRIVATE
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  )
  ament_target_dependencies(test_obstacle_array_layer
    nav2_costmap_2d
    pluginlib
    rclcpp
    tf2
    tf2_ros
    tf2_geometry_msgs
    obstacle_scanner
    geometry_msgs
    nav_msgs
    std_msgs
  )
endif()

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

ament_package()
