cmake_minimum_required(VERSION 3.21)
project(TactileIpc3D LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)


find_package(Qt6 COMPONENTS
        Core
        Gui
        Widgets
        QuickWidgets
        OpenGLWidgets
        SerialPort
        REQUIRED
        Quick
        QuickControls2
        QuickLayouts
        QuickDialogs2
        LinguistTools
)

set(QT_VERSION_MAJOR 6)
add_subdirectory(3rdpart/QXlsx/QXlsx)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)

qt_standard_project_setup()

add_executable(TactileIpc3D
        main.cpp
        resources.qrc
        src/translation_manager.h
        src/translation_manager.cpp
        src/backend.h
        src/backend.cpp
        src/data_backend.h
        src/data_backend.cpp
        src/data_frame.h
        src/glwidget.cpp
        src/glwidget.h
        src/serial/serial_backend.h
        src/serial/serial_backend.cpp
        src/serial/serial_codec.h
        src/serial/serial_decoder.h
        src/serial/serial_format.h
        src/serial/serial_manager.h
        src/serial/serial_manager.cpp
        src/serial/serial_queue.h
        src/serial/serial_threads.h
        src/serial/serial_threads.cpp
        src/serial/serial_transport.h
        src/serial/serial_qt_transport.h
        src/serial/serial_qt_transport.cpp
        src/serial/serial_types.h
        src/serial/piezoresistive_a_protocol.h
        src/serial/piezoresistive_a_protocol.cpp
        src/ringbuffer.h
        src/ringbuffer.cpp
        src/sparkline_plotitem.h
        src/sparkling_plotitem.cpp
        src/globalhelper.h
        src/globalhelper.h
)
target_link_libraries(TactileIpc3D PRIVATE
        Qt6::Core
        Qt6::Gui
        Qt6::Widgets
        Qt6::QuickWidgets
        Qt6::OpenGLWidgets
        Qt6::SerialPort
        Qt6::Quick
        Qt6::QuickControls2
        Qt6::QuickLayouts
        Qt6::QuickDialogs2
        QXlsx::QXlsx
)
target_include_directories(TactileIpc3D PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/3rdpart/OpenCV/include
)
if (WIN32)
    target_link_directories(TactileIpc3D PRIVATE
            ${CMAKE_CURRENT_SOURCE_DIR}/3rdpart/OpenCV/x64/mingw/lib
    )
    target_link_libraries(TactileIpc3D PRIVATE
            opencv_core4140
            opencv_imgproc4140
    )
endif()
set(TS_FILES
        ${CMAKE_CURRENT_SOURCE_DIR}/i18n/app_zh_CN.ts
        ${CMAKE_CURRENT_SOURCE_DIR}/i18n/app_en_US.ts
)

file(GLOB_RECURSE I18N_CPP_SOURCES CONFIGURE_DEPENDS
        ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h
        ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
)

file(GLOB_RECURSE I18N_QML_FILES CONFIGURE_DEPENDS
        ${CMAKE_CURRENT_SOURCE_DIR}/qml/*.qml
)

qt_add_translations(TactileIpc3D
        TS_FILES ${TS_FILES}
        SOURCES ${I18N_CPP_SOURCES}
        QML_FILES ${I18N_QML_FILES}
        QM_FILES_OUTPUT_VARIABLE QM_FILES
)

foreach(qm_file IN LISTS QM_FILES)
    get_filename_component(qm_name "${qm_file}" NAME)
    set_source_files_properties("${qm_file}" PROPERTIES QT_RESOURCE_ALIAS "${qm_name}")
endforeach()

qt_add_resources(TactileIpc3D i18n_resources
        PREFIX "/i18n"
        FILES ${QM_FILES}
)

set(runtime_out_dir "${CMAKE_BINARY_DIR}/out")
set_target_properties(TactileIpc3D PROPERTIES
        RUNTIME_OUTPUT_DIRECTORY "${runtime_out_dir}"
        RUNTIME_OUTPUT_DIRECTORY_DEBUG "${runtime_out_dir}/Debug"
        RUNTIME_OUTPUT_DIRECTORY_RELEASE "${runtime_out_dir}/Release"
        RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${runtime_out_dir}/RelWithDebInfo"
        RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${runtime_out_dir}/MinSizeRel"
)

include(GNUInstallDirs)
install(TARGETS TactileIpc3D
        RUNTIME DESTINATION bin
)

