cmake_minimum_required(VERSION 3.5)

project(trajectory_generators)

# Default to C++14
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(example_interfaces REQUIRED)
find_package(rclcpp REQUIRED)
find_package(eigen3_cmake_module REQUIRED)
find_package(Eigen3)
find_package(rclcpp_components REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav_msgs REQUIRED)

include_directories(include)
include_directories(${Eigen_INCLUDE_DIRS})

# create ament index resource which references the libraries in the binary dir
set(node_plugins "")

add_library(cubic_spline SHARED
  src/cubic_spline/cubic_spline_node.cpp)
target_compile_definitions(cubic_spline
  PRIVATE "COMPOSITION_BUILDING_DLL")
ament_target_dependencies(cubic_spline
  "rclcpp"
  "rclcpp_components"
  "geometry_msgs"
  "nav_msgs"
  "std_msgs")
rclcpp_components_register_nodes(cubic_spline "trajectory_generators::cubic_spline::TrajectoryGenerator")
set(node_plugins "${node_plugins}trajectory_generators::cubic_spline::TrajectoryGenerator;$<TARGET_FILE:trajectory_generator_component>\n")

# since the package installs libraries without exporting them
# it needs to make sure that the library path is being exported
if(NOT WIN32)
  ament_environment_hooks(
    "${ament_cmake_package_templates_ENVIRONMENT_HOOK_LIBRARY_PATH}")
endif()

add_executable(cubic_spline_node
  src/cubic_spline/cubic_spline.cpp)
target_link_libraries(cubic_spline_node
  cubic_spline)
ament_target_dependencies(cubic_spline_node
  "rclcpp")

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  set(libs
    "-Wl,--no-as-needed"
    ${libs}
    "-Wl,--as-needed")
endif()

install(TARGETS
  cubic_spline
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin)

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

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()

endif()

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

ament_package()
