cmake_minimum_required(VERSION 3.5...4.3)

project(HMI LANGUAGES CXX VERSION 1.0)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(ADS_VERSION 4.3.1)
add_subdirectory(QtADS)

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets REQUIRED)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
#默认ui文件要和.h头文件在一个目录，若不在一个目录，需要指定其所在目录
set(CMAKE_AUTOUIC_SEARCH_PATHS "ui")

if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
    set(pd_PlatformDir "x86")
else()
    if(DEFINED CMAKE_SYSTEM_PROCESSOR)
        if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
            set(pd_PlatformDir "x64")
        elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|ARM64")
            set(pd_PlatformDir "arm64")
        elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
            set(pd_PlatformDir "aarch64")
        else()
            set(pd_PlatformDir "x64")
        endif()
    else()
        set(pd_PlatformDir "x64")
    endif()
endif()

add_subdirectory(PropertyEditor)

set(H_HEADER_FILES
    include/global.h
    include/mainwindow.h
    include/graphicElementsPanel.h
    include/drawingPanel.h
    include/designerScene.h
    include/designerView.h
    include/operationCommand.h
    include/document.h

    include/propertyType/CustomGadget.h
    include/propertyType/CustomType.h
    include/propertyType/PropertyTypeCustomization_CustomType.h

    include/util/baseSelector.h
    include/util/creatingSelector.h
    include/util/movingSelector.h
    include/util/rotationSelector.h
    include/util/scalingSelector.h
    include/util/editingSelector.h
    include/util/selectorManager.h

    include/util/serializationUtils.h
    include/util/serializationRegistry.h

    include/graphicsItem/itemControlHandle.h
    include/graphicsItem/graphicsBaseItem.h
    include/graphicsItem/graphicsRectItem.h
    include/graphicsItem/graphicsPolygonItem.h
    include/graphicsItem/graphicsTextItem.h
    include/graphicsItem/graphicsItemGroup.h
)
set(CPP_SOURCE_FILES
    source/main.cpp
    source/mainwindow.cpp
    source/graphicElementsPanel.cpp
    source/drawingPanel.cpp
    source/designerScene.cpp
    source/designerView.cpp
    source/operationCommand.cpp
    source/document.cpp

    source/propertyType/PropertyTypeCustomization_CustomType.cpp

    source/util/baseSelector.cpp
    source/util/creatingSelector.cpp
    source/util/movingSelector.cpp
    source/util/rotationSelector.cpp
    source/util/scalingSelector.cpp
    source/util/editingSelector.cpp
    source/util/selectorManager.cpp
    source/util/serializationUtils.cpp
    source/util/serializationRegistry.cpp

    source/graphicsItem/itemControlHandle.cpp
    source/graphicsItem/graphicsBaseItem.cpp
    source/graphicsItem/graphicsRectItem.cpp
    source/graphicsItem/graphicsPolygonItem.cpp
    source/graphicsItem/graphicsTextItem.cpp
    source/graphicsItem/graphicsItemGroup.cpp
)
set(UI_FILES
    ui/mainwindow.ui
    ui/graphicElementsPanel.ui
    ui/drawingPanel.ui
)

# 包含源文件目录
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(HMI
        MANUAL_FINALIZATION
        ${H_HEADER_FILES}
        ${CPP_SOURCE_FILES}
        ${UI_FILES}
        resource/HMI.qrc
    )
else()
    if(ANDROID)
        add_library(HMI SHARED
            ${H_HEADER_FILES}
            ${CPP_SOURCE_FILES}
            ${UI_FILES}
            resource/HMI.qrc
        )
    else()
        add_executable(HMI WIN32
            ${H_HEADER_FILES}
            ${CPP_SOURCE_FILES}
            ${UI_FILES}
            resource/HMI.qrc
        )
    endif()
endif()

include_directories(include)

target_include_directories(HMI PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(HMI PRIVATE qt${QT_VERSION_MAJOR}advanceddocking)
target_link_libraries(HMI PRIVATE PropertyEditor)
target_link_libraries(HMI PUBLIC Qt${QT_VERSION_MAJOR}::Core 
                                 Qt${QT_VERSION_MAJOR}::Gui 
                                 Qt${QT_VERSION_MAJOR}::Widgets)
set_target_properties(HMI PROPERTIES 
    AUTOMOC ON
    AUTORCC ON
    AUTOUIC ON
    CXX_STANDARD 14
    CXX_STANDARD_REQUIRED ON
    CXX_EXTENSIONS OFF
    VERSION 1.0
    EXPORT_NAME "HMI System with Qt Advanced Docking System"
    ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${pd_PlatformDir}/lib"
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${pd_PlatformDir}/lib"
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${pd_PlatformDir}/bin"
)

