cmake_minimum_required(VERSION 3.5)

project(AnalysisTool VERSION 1.0.0 LANGUAGES CXX)

# Set C++11 as the minimum standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Find Qt libraries
find_package(Qt5 REQUIRED COMPONENTS Core Gui SerialPort PrintSupport Widgets)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)

# 定义搜索的文件夹
set(SEARCH_FOLDERS
    ${CMAKE_SOURCE_DIR}
    serialport
    ui
    thirdparty/qcustomplot
    data
)

# 初始化空的源文件列表
set(SOURCES "")
set(HEADERS "")

# 分别搜索 .cpp 和 .h 文件
foreach(FOLDER ${SEARCH_FOLDERS})
    file(GLOB_RECURSE TEMP_CPP ${FOLDER}/*.cpp)
    file(GLOB_RECURSE TEMP_H ${FOLDER}/*.h)
    list(APPEND SOURCES ${TEMP_CPP})
    list(APPEND HEADERS ${TEMP_H})
endforeach()


set(FORMS
    mainwindow.ui
    ui/experimentsettingform.ui
    ui/realtimedataform.ui
)

# Resources
set(RESOURCES
    images.qrc
)

# Add UI files to the project and automatically run uic
qt5_wrap_ui(UI_HEADERS ${FORMS})

# Add resources to the project and automatically run rcc
qt5_add_resources(RESOURCES_RCC ${RESOURCES})

# Create the executable
add_executable(${PROJECT_NAME}
    ${SOURCES}
    ${HEADERS}
    ${UI_HEADERS}
    ${RESOURCES_RCC}
)

target_include_directories(${PROJECT_NAME} PRIVATE
    ${SEARCH_FOLDERS}
    ${CMAKE_CURRENT_BINARY_DIR})

# Link against Qt5 libraries
target_link_libraries(${PROJECT_NAME}
    Qt5::Core
    Qt5::Gui
    Qt5::SerialPort
    Qt5::PrintSupport
    Qt5::Widgets
)

