cmake_minimum_required(VERSION 3.22)
project(moveit_setup_framework LANGUAGES CXX)

# Common cmake code applied to all moveit packages
find_package(moveit_common REQUIRED)
moveit_package()

find_package(ament_cmake REQUIRED)
find_package(ament_cmake_ros REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(fmt REQUIRED)
# rviz switched to Qt6 in 15.1.14: https://github.com/ros2/rviz/pull/1635
# (merged 2025-12-08, first released in the 15.1.14 tag on 2025-12-17 -- 15.1.0
# through 15.1.13 are still Qt5)
find_package(rviz2 QUIET)
if(rviz2_VERSION VERSION_GREATER_EQUAL 15.1.14)
  find_package(Qt6 REQUIRED COMPONENTS Core Widgets)
  set(QT_VERSION_MAJOR 6)
  # Hint for transitive deps that use find_package(QT NAMES Qt6 Qt5 ...) which
  # may incorrectly resolve to Qt5 due to CMake's ascending path order
  set(QT_DIR "${Qt6_DIR}")
else()
  find_package(Qt5 REQUIRED COMPONENTS Core Widgets)
  set(QT_VERSION_MAJOR 5)
endif()
find_package(moveit_core REQUIRED)
find_package(moveit_ros_planning REQUIRED)
find_package(moveit_ros_visualization REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rviz_common REQUIRED)
find_package(rviz_rendering REQUIRED)
find_package(srdfdom REQUIRED)
find_package(urdf REQUIRED)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

add_library(
  moveit_setup_framework
  src/helper_widgets.cpp
  src/double_list_widget.cpp
  src/urdf_config.cpp
  src/package_settings_config.cpp
  src/srdf_config.cpp
  src/rviz_panel.cpp
  src/data_warehouse.cpp
  src/templates.cpp
  src/utilities.cpp
  src/xml_syntax_highlighter.cpp
  include/moveit_setup_framework/qt/helper_widgets.hpp
  include/moveit_setup_framework/qt/setup_step_widget.hpp
  include/moveit_setup_framework/qt/rviz_panel.hpp
  include/moveit_setup_framework/qt/double_list_widget.hpp)
target_include_directories(
  moveit_setup_framework
  PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
         $<INSTALL_INTERFACE:include/moveit_setup_framework>)
target_link_libraries(
  moveit_setup_framework
  PUBLIC ament_index_cpp::ament_index_cpp
         fmt::fmt
         moveit_core::moveit_core
         moveit_ros_planning::moveit_ros_planning
         moveit_ros_visualization::moveit_ros_visualization
         pluginlib::pluginlib
         Qt${QT_VERSION_MAJOR}::Core
         Qt${QT_VERSION_MAJOR}::Widgets
         rclcpp::rclcpp
         rviz_common::rviz_common
         rviz_rendering::rviz_rendering
         srdfdom::srdfdom
         urdf::urdf)

install(DIRECTORY include/ DESTINATION include/moveit_setup_framework)
install(FILES moveit_setup_framework_plugins.xml
        DESTINATION share/moveit_setup_framework)

install(DIRECTORY templates DESTINATION share/moveit_setup_framework)

ament_export_targets(moveit_setup_frameworkTargets HAS_LIBRARY_TARGET)
install(
  TARGETS moveit_setup_framework
  EXPORT moveit_setup_frameworkTargets
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib
  RUNTIME DESTINATION bin
  INCLUDES
  DESTINATION include/moveit_setup_framework)

ament_export_dependencies(fmt)
ament_export_dependencies(rclcpp)
ament_export_dependencies(Qt${QT_VERSION_MAJOR}Core
                          Qt${QT_VERSION_MAJOR}Widgets)
ament_export_dependencies(moveit_common)
ament_export_dependencies(moveit_core)
ament_export_dependencies(moveit_ros_planning)
ament_export_dependencies(moveit_ros_visualization)
ament_export_dependencies(rviz_common)
ament_export_dependencies(rviz_rendering)
pluginlib_export_plugin_description_file(moveit_setup_framework
                                         moveit_setup_framework_plugins.xml)

ament_package()
