cmake_minimum_required(VERSION 3.8)
project(hexapod_robot)

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)

find_package(geometry_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)

# Build hexapod_robot_interfaces

set(srv_files
    "msg/HexapodLeg.msg"
    "msg/HexapodPose.msg"
)

rosidl_generate_interfaces(${PROJECT_NAME}
    ${srv_files}
    DEPENDENCIES geometry_msgs
)

# Build hexapod_robot_ik_server

# add_executable(hexapod_robot_ik_server
#     "kinematics/hexapod_robot_ik_service.cpp"
# )

# target_compile_features(hexapod_robot_ik_server PUBLIC cxx_std_17)
# target_include_directories(hexapod_robot_ik_server PUBLIC 
#     $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/kinematics/include>
#     $<INSTALL_INTERFACE:include>
# )

# ament_target_dependencies(
#     hexapod_robot_ik_server
#     rclcpp
# )

# rosidl_target_interfaces(hexapod_robot_ik_server ${PROJECT_NAME} "rosidl_typesupport_cpp")

# Build hexapod_robot_hwi

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_robot.xml)


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


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

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


if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_export_targets(export_hexapod_robot HAS_LIBRARY_TARGET)
ament_export_dependencies(
    rosidl_default_runtime
    hardware_interface 
    pluginlib
    rclcpp
    rcl
    cpp_lifecycle
    i2c
)


ament_package()