cmake_minimum_required(VERSION 3.8)
project(mg_control)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(pluginlib REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(rclcpp_components REQUIRED)
include(FindPkgConfig)
pkg_search_module(LIBSERIAL REQUIRED libserial)

add_library(
  mg_control
  SHARED
  src/mg_control.cpp
)

target_include_directories(
  mg_control
  PRIVATE
  ${LIBSERIAL_INCLUDE_DIRS}
  include
)

target_link_libraries(
  mg_control
  ${LIBSERIAL_LIBRARIES}
)

ament_target_dependencies(
  mg_control
  rclcpp
  pluginlib
  hardware_interface
  rclcpp_lifecycle
)
pluginlib_export_plugin_description_file(hardware_interface mg_control_interfaces.xml)

install(
  TARGETS mg_control
  DESTINATION lib
)

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

target_compile_features(mg_control PUBLIC c_std_99 cxx_std_17)  # Require C99 and C++17

ament_package()
