cmake_minimum_required(VERSION 3.10)
project(AGVPathTracking VERSION 1.0)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# MSVC 编译器选项：使用 UTF-8 编码
if(MSVC)
    add_compile_options(/utf-8)
endif()

# 包含目录
include_directories(${PROJECT_SOURCE_DIR}/include)

# 源文件
set(SOURCES
    src/agv_model.cpp
    src/path_curve.cpp
    src/path_curve_custom.cpp
    src/path_curve_custom.cpp
    src/path_curve_custom.cpp
    src/path_curve_custom.cpp
    src/path_curve_custom.cpp
    src/control_generator.cpp
    src/path_tracker.cpp
)

# 创建库
add_library(agv_tracking ${SOURCES})

# 示例程序
add_executable(agv_demo examples/demo.cpp)
target_link_libraries(agv_demo agv_tracking)

# 数据生成程序
add_executable(generate_data examples/generate_data.cpp)
target_link_libraries(generate_data agv_tracking)

# 平滑路径生成程序
add_executable(generate_smooth_path examples/generate_smooth_path.cpp)
target_link_libraries(generate_smooth_path agv_tracking)

# 控制台GUI演示程序
add_executable(agv_gui examples/gui_demo.cpp)
target_link_libraries(agv_gui agv_tracking)

# ==================== Curtis 电机控制器示例程序 ====================

# Curtis 键盘控制演示
add_executable(curtis_demo
    examples/curtis_demo.cpp
    src/can/CurtisMotorController.cpp
)
target_link_libraries(curtis_demo ${CMAKE_SOURCE_DIR}/lib/ControlCAN.lib)

# Curtis 路径跟踪演示
add_executable(curtis_path_tracking_demo
    examples/curtis_path_tracking_demo.cpp
    src/can/CurtisMotorController.cpp
)
target_link_libraries(curtis_path_tracking_demo agv_tracking ${CMAKE_SOURCE_DIR}/lib/ControlCAN.lib)

# Qt 图形界面GUI
find_package(Qt5 COMPONENTS Widgets REQUIRED)
if(Qt5_FOUND)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    set(CMAKE_AUTOUIC ON)

    add_executable(agv_qt_gui examples/qt_gui_demo.cpp)
    target_link_libraries(agv_qt_gui agv_tracking Qt5::Widgets)

    message(STATUS "Qt5 found - Building Qt GUI application")
else()
    message(WARNING "Qt5 not found - Qt GUI application will not be built")
endif()

# 安装规则
install(TARGETS agv_tracking DESTINATION lib)
install(DIRECTORY include/ DESTINATION include)
