cmake_minimum_required(VERSION 3.5)
project(origincar_base)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# 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 dependencies
find_package(ament_cmake REQUIRED)
#find_package(actionlib REQUIRED)
#find_package(actionlib_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)

find_package(nav2_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(std_srvs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(ackermann_msgs REQUIRED)                         # CHANGE
find_package(origincar_msg REQUIRED)                         # CHANGE
find_package(serial REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(origincar_description REQUIRED)
find_package(robot_localization REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/Position.msg"
 )
if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # uncomment the line when a copyright and license is not present in all source files
  #set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # uncomment the line when this package is not in a git repo
  #set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

include_directories(
  include
  ${robot_localization_INCLUDE_DIRS}
)
set(origincar_base_node_SRCS
  src/origincar_base.cpp
)

add_executable(origincar_base_node src/origincar_base.cpp)
ament_target_dependencies(origincar_base_node tf2_ros tf2 tf2_geometry_msgs rclcpp std_msgs geometry_msgs robot_localization nav_msgs std_srvs sensor_msgs ackermann_msgs serial origincar_msg origincar_description)

add_library(wall_fit_core STATIC src/wall_fit_core.cpp)
target_include_directories(wall_fit_core PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
)

add_library(wall_kalman_filter STATIC src/wall_kalman_filter.cpp)
target_include_directories(wall_kalman_filter PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
)
target_link_libraries(wall_kalman_filter wall_fit_core)

target_link_libraries(origincar_base_node wall_kalman_filter wall_fit_core)

add_executable(wall_fit_calibrator src/wall_fit_calibrator.cpp)
target_link_libraries(wall_fit_calibrator wall_fit_core)
ament_target_dependencies(wall_fit_calibrator rclcpp sensor_msgs nav_msgs)

add_executable(wall_localization_node src/wall_localization_node.cpp)
target_link_libraries(wall_localization_node wall_fit_core)
ament_target_dependencies(wall_localization_node rclcpp sensor_msgs nav_msgs geometry_msgs tf2_ros)

add_executable(wall_preview_server src/wall_preview_server.cpp)
target_link_libraries(wall_preview_server wall_fit_core pthread)
ament_target_dependencies(wall_preview_server rclcpp sensor_msgs nav_msgs geometry_msgs)

if(BUILD_TESTING)
  add_executable(wall_fit_core_test test/wall_fit_core_test.cpp)
  target_link_libraries(wall_fit_core_test wall_fit_core)
  add_test(NAME wall_fit_core_test COMMAND wall_fit_core_test)

  add_executable(wall_kalman_filter_test test/wall_kalman_filter_test.cpp)
  target_link_libraries(wall_kalman_filter_test wall_kalman_filter)
  add_test(NAME wall_kalman_filter_test COMMAND wall_kalman_filter_test)
endif()

#add_executable(testNode src/test.cpp src/Quaternion_Solution.cpp)
#ament_target_dependencies(testNode rclcpp std_msgs nav_msgs std_srvs sensor_msgs ackermann_msgs serial origincar_msg)

install(PROGRAMS
  scripts/cmd_vel_to_ackermann_drive.py
  DESTINATION lib/${PROJECT_NAME}
)

install(TARGETS
origincar_base_node
wall_fit_calibrator
wall_localization_node
wall_preview_server

DESTINATION lib/${PROJECT_NAME}
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

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