cmake_minimum_required(VERSION 3.16)
project(ARCDesktopProject LANGUAGES CXX)

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

add_compile_definitions(QT_MESSAGELOGCONTEXT)

if (WIN32)
    # Укажи путь к Qt6
    set(CMAKE_PREFIX_PATH "C:/Qt/6.9.0/msvc2022_arm64")
    list(APPEND CMAKE_PREFIX_PATH "C:/Users/User/.vcpkg-clion/vcpkg/installed/arm64-windows")
    #vcpkg install tesseract:arm64-windows
    set(Tesseract_DIR "C:/Users/User/.vcpkg-clion/vcpkg/installed/arm64-windows/share/tesseract")

    find_package(Tesseract CONFIG REQUIRED)
elseif (APPLE)
    # Укажи путь к Qt6
    set(CMAKE_PREFIX_PATH "/opt/homebrew/opt/qt")
    include_directories("/opt/homebrew/opt/tesseract/include")
    link_directories("/opt/homebrew/opt/tesseract/lib")
endif ()

find_package(Qt6 REQUIRED COMPONENTS
        Network
        Widgets
        Sql
        Xml
)

file(GLOB_RECURSE DB_SOURCES
        "${CMAKE_CURRENT_SOURCE_DIR}/database/*.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/database/*.h"
)

file(GLOB_RECURSE VIEW_SOURCES
        "${CMAKE_CURRENT_SOURCE_DIR}/views/*.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/views/*.h"
)

file(GLOB_RECURSE SERVICES_SOURCES
        "${CMAKE_CURRENT_SOURCE_DIR}/services/*.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/services/*.h"
)

file(GLOB_RECURSE MODELS_SOURCES
        "${CMAKE_CURRENT_SOURCE_DIR}/models/*.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/models/*.h"
)

file(GLOB_RECURSE ANDROID_SOURCES
        "${CMAKE_CURRENT_SOURCE_DIR}/android/*.cpp"
        "${CMAKE_CURRENT_SOURCE_DIR}/android/*.h"
)

add_executable(ARCDesktopProject
        main.cpp
        ${VIEW_SOURCES}
        ${SERVICES_SOURCES}
        ${DB_SOURCES}
        ${MODELS_SOURCES}
        ${ANDROID_SOURCES}
        views/bank/BankSettingsWindow.cpp
        views/bank/BankSettingsWindow.h
)

if (WIN32)
    target_link_libraries(ARCDesktopProject
            Qt6::Widgets
            Qt6::Xml
            Qt6::Sql
            Qt6::Network
            Tesseract::libtesseract
    )

    # Копирование изображений в директорию сборки
    file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/database/app_data.db" DESTINATION "${CMAKE_BINARY_DIR}/database")
    file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tutorials" DESTINATION "${CMAKE_BINARY_DIR}")
    file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/images" DESTINATION "${CMAKE_BINARY_DIR}")
    file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/rus.traineddata" DESTINATION "${CMAKE_BINARY_DIR}")
    file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/config.ini" DESTINATION "${CMAKE_BINARY_DIR}")

elseif (APPLE)
    target_link_libraries(ARCDesktopProject
            Qt6::Widgets
            Qt6::Sql
            Qt6::Xml
            Qt6::Network
            tesseract
    )
endif ()

target_include_directories(ARCDesktopProject PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/views
        ${CMAKE_CURRENT_SOURCE_DIR}/database
        ${CMAKE_CURRENT_SOURCE_DIR}/services
        ${CMAKE_CURRENT_SOURCE_DIR}/models
        ${CMAKE_CURRENT_SOURCE_DIR}/android
)