cmake_minimum_required(VERSION 3.8)
project(qr_detection)

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

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(origincar_msg REQUIRED)
find_package(OpenCV REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(ZBar REQUIRED zbar)

add_executable(qr_detect src/qr_detect.cpp)
target_include_directories(qr_detect PUBLIC
  ${OpenCV_INCLUDE_DIRS} ${ZBar_INCLUDE_DIRS})
target_link_libraries(qr_detect
  ${OpenCV_LIBS} ${ZBar_LIBRARIES})
ament_target_dependencies(qr_detect
  rclcpp std_msgs sensor_msgs origincar_msg)

add_executable(qr_dete_depth src/qr_dete_depth.cpp)
target_include_directories(qr_dete_depth PUBLIC
  ${OpenCV_INCLUDE_DIRS} ${ZBar_INCLUDE_DIRS})
target_link_libraries(qr_dete_depth
  ${OpenCV_LIBS} ${ZBar_LIBRARIES})
ament_target_dependencies(qr_dete_depth
  rclcpp std_msgs sensor_msgs origincar_msg)

install(TARGETS qr_detect qr_dete_depth
  DESTINATION lib/${PROJECT_NAME})

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

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

if(BUILD_TESTING)
  find_package(ament_cmake_gtest REQUIRED)
  find_package(ament_lint_auto REQUIRED)
  ament_add_gtest(test_qr_detect test/test_qr_detect.cpp)
  if(TARGET test_qr_detect)
    target_include_directories(test_qr_detect PUBLIC
      ${OpenCV_INCLUDE_DIRS} ${ZBar_INCLUDE_DIRS})
    target_link_libraries(test_qr_detect
      ${OpenCV_LIBS} ${ZBar_LIBRARIES})
    ament_target_dependencies(test_qr_detect
      rclcpp std_msgs sensor_msgs origincar_msg)
  endif()
  ament_add_gtest(test_qr_dete_depth test/test_qr_dete_depth.cpp)
  if(TARGET test_qr_dete_depth)
    target_include_directories(test_qr_dete_depth PUBLIC
      ${OpenCV_INCLUDE_DIRS} ${ZBar_INCLUDE_DIRS})
    target_link_libraries(test_qr_dete_depth
      ${OpenCV_LIBS} ${ZBar_LIBRARIES})
    ament_target_dependencies(test_qr_dete_depth
      rclcpp std_msgs sensor_msgs origincar_msg)
  endif()
  set(ament_cmake_copyright_FOUND TRUE)
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
