cmake_minimum_required(VERSION 3.8)
project(hexapod_hardware)

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(hardware_interface REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)

add_library(
    hexapod_robot_hwi
    SHARED
    hardware/hexapod_robot_hwi.cpp
)

target_compile_features(hexapod_robot_hwi PUBLIC cxx_std_17)
target_include_directories(hexapod_robot_hwi PUBLIC 
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/hardware/include>
    $<INSTALL_INTERFACE:include>
)

ament_target_dependencies(
    hexapod_robot_hwi PUBLIC
    hardware_interface
    pluginlib
    rclcpp
    rclcpp_lifecycle
)

target_link_libraries(hexapod_robot_hwi PUBLIC i2c)

pluginlib_export_plugin_description_file(hardware_interface hexapod_hardware.xml)

# install(TARGETS hexapod_robot_ik_server
#     DESTINATION lib/${PROJECT_NAME}
# )

install(TARGETS hexapod_robot_hwi
    EXPORT export_hexapod_hardware
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION bin
)


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

ament_export_targets(export_hexapod_hardware HAS_LIBRARY_TARGET)
ament_export_dependencies(
    hardware_interface 
    pluginlib
    rclcpp
    rcl
    cpp_lifecycle
    i2c
)


ament_package()