cmake_minimum_required(VERSION 3.5)

project(PowerMaster VERSION 0.1 LANGUAGES CXX)

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

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS PrintSupport)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Concurrent)

set(ADS_VERSION 4.3.1)
add_subdirectory(QtADS)

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

set(H_HEADER_FILES
    include/global.h
    include/mainWindow.h
    include/customBorderContainer.h
    include/customMenu.h
    include/customTab.h
    include/customTabBar.h
    include/functionNavigationBar.h
    include/dvieMainWindow.h
    include/dvieSecondaryWindow.h
    include/tccMainWindow.h
    include/tccToolBox.h
    include/transparentMask.h
    include/messageDialog.h
    include/dashboard.h
    include/dashboardFrame.h
    include/dashboardNamingDialog.h
    include/dataPanel.h
    include/dataLoader.h
    include/dataManager.h
    include/panelSelectionDialog.h
    include/panelConfigurationWidget.h
    include/dateTimeWidget.h
    include/customCalendarWidget.h
    include/dateTimeSelectionPanel.h
    include/httpRequestManager.h
)

set(CPP_SOURCE_FILES
    source/global.cpp
    source/main.cpp
    source/mainWindow.cpp
    source/customBorderContainer.cpp
    source/customMenu.cpp
    source/customTab.cpp
    source/customTabBar.cpp
    source/functionNavigationBar.cpp
    source/dvieMainWindow.cpp
    source/dvieSecondaryWindow.cpp
    source/tccMainWindow.cpp
    source/tccToolBox.cpp
    source/transparentMask.cpp
    source/messageDialog.cpp
    source/dashboard.cpp
    source/dashboardFrame.cpp
    source/dashboardNamingDialog.cpp
    source/dataPanel.cpp
    source/dataLoader.cpp
    source/dataManager.cpp
    source/panelSelectionDialog.cpp
    source/panelConfigurationWidget.cpp
    source/dateTimeWidget.cpp
    source/customCalendarWidget.cpp
    source/dateTimeSelectionPanel.cpp
    source/httpRequestManager.cpp
)

set(UI_FILES
    ui/mainWindow.ui
    ui/functionNavigationBar.ui
    ui/dvieMainWindow.ui
    ui/dvieSecondaryWindow.ui
    ui/tccToolBox.ui
    ui/transparentMask.ui
    ui/messageDialog.ui
    ui/dashboardFrame.ui
    ui/dashboardNamingDialog.ui
    ui/panelSelectionDialog.ui
    ui/panelConfigurationWidget.ui
    ui/panelToolWidget.ui
    ui/dateTimeWidget.ui
    ui/dateTimeSelectionPanel.ui
    ui/dpConfigurationDialog.ui
)

set(UTIL_FILES
    util/TimeLine/timeLine_globals.h
    util/TimeLine/timeLineWidget.h
    util/TimeLine/timeLineWidget.cpp
    util/TimeLine/timeLineItem.h
    util/TimeLine/timeLineItem.cpp
    util/TimeLine/timeStampItem.h
    util/TimeLine/timeStampItem.cpp
    util/TimeLine/eventItem.h
    util/TimeLine/eventItem.cpp
    util/Chart/qcustomplot.h
    util/Chart/qcustomplot.cpp
)

set(DATAPANEL_FILES
    dataPanel/dpGlobals.h
    dataPanel/dpConfigurationDialog.h
    dataPanel/dpConfigurationDialog.cpp
    dataPanel/dpBaseWidget.h
    dataPanel/dpBaseWidget.cpp
    dataPanel/dpLineChart.h
    dataPanel/dpLineChart.cpp
)

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

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(PowerMaster
        MANUAL_FINALIZATION
        ${H_HEADER_FILES}
        ${CPP_SOURCE_FILES}
        ${UI_FILES}
        ${UTIL_FILES}
        ${DATAPANEL_FILES}
        resource/PowerMaster.qrc
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET PowerMaster APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(PowerMaster SHARED
            ${H_HEADER_FILES}
            ${CPP_SOURCE_FILES}
            ${UI_FILES}
            ${UTIL_FILES}
            resource/PowerMaster.qrc
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(PowerMaster
            ${H_HEADER_FILES}
            ${CPP_SOURCE_FILES}
            ${UI_FILES}
            ${UTIL_FILES}
            resource/PowerMaster.qrc
        )
    endif()
endif()

target_include_directories(PowerMaster PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(PowerMaster PRIVATE Qt${QT_VERSION_MAJOR}::PrintSupport)
target_link_libraries(PowerMaster PRIVATE Qt${QT_VERSION_MAJOR}::Network)
target_link_libraries(PowerMaster PRIVATE Qt${QT_VERSION_MAJOR}::Concurrent)
target_link_libraries(PowerMaster PRIVATE qt${QT_VERSION_MAJOR}advanceddocking)
target_link_libraries(PowerMaster PUBLIC Qt${QT_VERSION_MAJOR}::Core
                                                  Qt${QT_VERSION_MAJOR}::Gui
                                                  Qt${QT_VERSION_MAJOR}::Widgets)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.PowerMaster)
endif()
set_target_properties(PowerMaster PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS PowerMaster
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(PowerMaster)
endif()
