cmake_minimum_required(VERSION 3.25)
set(PROJECT_NAME Train_RFID)
project(${PROJECT_NAME} VERSION 1.0 DESCRIPTION "火车车号识别 RFID版")

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

# 设置项目生成目录
set(EXECUTABLE_OUTPUT_PATH ../../app)

set(CMAKE_PREFIX_PATH "D:/Qt/5.15.2/mingw81_64")

include_directories(../include)
# 添加动态库目录
link_directories(../lib)

link_libraries(ws2_32 wsock32)


find_package(Qt5 COMPONENTS
        Core
        Gui
        Widgets
        Network
        SerialPort
        REQUIRED)

#导入Qt的Network配置和在pro文件里面添加QT+=network是一样的
#find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core Network SerialPort )
#find_package(Qt${QT_VERSION_MAJOR} REQUIRED Network  COMPONENTS Core)
#find_package(Qt5Core  COMPONENTS Qt5SerialPort REQUIRED)

#moc编译在这里进行，请把含有Q_OBJECT宏定义的头文件放到这里来
QT5_WRAP_CPP(MOC_Files
        qt_source/mainwindow.h
        interface/TcpClient.h
        )

include_directories(
        common
        # qt_source qt_source
        qt_source
        # json库
        util/json
        # http库
        util/http
        # com口工具
        util/comPort
        # Log日志
        util/Log
        # 文件目录处理工具
        util/FileManager
        # 通用数据类型
        util/CommonDataType
        # 错误类型
        util/ErrorCode
        # 字符串工具类
        util/StringUtil
        # ini文件读写工具类
        util/ini
        # 队列信息
        util/MQueue
        # 配置文件读取工具类
        ConfigUtil
        # interface
        interface
        # 串口信息处理逻辑
        serial


)

file(GLOB_RECURSE COMMON_SRCS_LISTS
        # UI
        qt_source/mainwindow.ui
        # 公共数据
        common/common.cpp
        # qt_source qt_source
        qt_source/mainwindow.cpp
        # JSON库
        util/json/jsoncpp.cpp
        # http库
        util/http/httplib.cc
        # com口工具
        util/comPort/*.cpp
        # Log日志
        util/Log/*.cpp
        # 文件目录处理工具
        util/FileManager/*.cpp
        # 通用数据类型
        src/util/CommonDataType/*.cpp
        # 错误类型
        util/ErrorCode/*.cpp
        # 字符串工具类
        util/StringUtil/*.cpp
        # ini文件读写工具类
        util/ini/*.cpp
        # 配置文件读取工具类
        ConfigUtil/*.cpp
        # interface
        interface/*.cpp
        # 串口信息处理逻辑
        serial/*.cpp
)

add_executable(Train_RFID
        WIN32
        main.cpp
        ${COMMON_SRCS_LISTS}
        ${MOC_Files}
        ico.rc
)

target_link_libraries(Train_RFID
        -pthread

        -lyaml-cpp
        Qt5::Core
        Qt5::Gui
        Qt5::Widgets
        Qt5::Network
        Qt5::SerialPort
        )

if (WIN32 AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
    set(DEBUG_SUFFIX)
    if (MSVC AND CMAKE_BUILD_TYPE MATCHES "Debug")
        set(DEBUG_SUFFIX "d")
    endif ()
    set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}")
    if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
        set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
            set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
        endif ()
    endif ()
    if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E make_directory
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
    endif ()
    foreach (QT_LIB Core Gui Widgets Network SerialPort)
        add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
                COMMAND ${CMAKE_COMMAND} -E copy
                "${QT_INSTALL_PATH}/bin/Qt5${QT_LIB}${DEBUG_SUFFIX}.dll"
                "$<TARGET_FILE_DIR:${PROJECT_NAME}>")
    endforeach (QT_LIB)
endif ()
