cmake_minimum_required(VERSION 3.8)
project(target_tracking)

# Required packages
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(pcl_conversions REQUIRED)
find_package(PCL REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_sensor_msgs REQUIRED)
find_package(OpenCV REQUIRED)
find_package(visualization_msgs REQUIRED)


# Include paths
include_directories(
  include
  ${PCL_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
)

# Node for preprocessing
add_executable(cloud_preprocessing_node 
      src/cloud_preprocessing.cpp
)

# Dependencies for preprocessing
ament_target_dependencies(cloud_preprocessing_node
  rclcpp
  sensor_msgs
  pcl_conversions
  tf2
  tf2_ros
  tf2_sensor_msgs
)

# Node for clustering
add_executable(cloud_clustering_node
      src/cloud_clustering_node.cpp
)

add_library(cloud_clustering SHARED
  src/cloud_clustering.cpp)
target_compile_definitions(cloud_clustering
  PRIVATE "COMPOSITION_BUILDING_DLL")


# Dependencies for clustering
ament_target_dependencies(cloud_clustering
  rclcpp
  sensor_msgs
  visualization_msgs 
  PCL
  pcl_conversions
  OpenCV
)

rclcpp_components_register_nodes(cloud_clustering "cloud_clustering::CloudClustering")
set(node_plugins "${node_plugins}cloud_clustering::CloudClustering;$<TARGET_FILE:cloud_clustering>\n")

target_link_libraries(cloud_clustering_node cloud_clustering)

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

install(TARGETS
    cloud_clustering
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION lib/${PACKAGE_NAME}
)

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

ament_package()
