cmake_minimum_required(VERSION 3.16)

project(winTools VERSION 0.1 LANGUAGES CXX)
include(FetchContent) # FetchContent 支持

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

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# sqlite_orm库
FetchContent_Declare(sqliteOrm
  GIT_REPOSITORY https://github.com/fnc12/sqlite_orm
  GIT_TAG        v1.9.1
)
FetchContent_MakeAvailable(sqliteOrm)

# 在这里配置QT路径
SET(QT_SDK_DIR E:/Programs/Qt/6.9.2/mingw_64 CACHE PATH "QT SDK DIR" FORCE)
message("在CMAKE中配置 QT_SDK_DIR 选项指定QT路径; 当前路径: ${QT_SDK_DIR}")
SET(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/Install CACHE PATH "Installation path" FORCE)
list(APPEND CMAKE_PREFIX_PATH ${QT_SDK_DIR})

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Core Gui)
find_package(Qt6 REQUIRED COMPONENTS Widgets Core Gui)

# 依赖库
add_subdirectory(ElaWidgetTools)

# 导出src下的cpp文件
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS src/*.cpp src/UI/*.cpp)

qt_add_executable(${PROJECT_NAME}
    MANUAL_FINALIZATION
    ${SRC_FILES}
)

# 添加宏定义，输出日志所处文件位置
target_compile_definitions(${PROJECT_NAME} PRIVATE QT_MESSAGELOGCONTEXT)

target_link_libraries(${PROJECT_NAME} PRIVATE
    Qt6::Widgets
    Qt6::Core
    Qt6::Gui
    ElaWidgetTools
    sqlite_orm::sqlite_orm
)

# 添加资源文件
set(cbh_resource_files
    "assets/icon.png"
)

qt_add_resources(${PROJECT_NAME} "cbh"
    PREFIX
        "/"
    FILES
        ${cbh_resource_files}
)

# 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.cbh)
endif()
set_target_properties(${PROJECT_NAME} 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 FALSE
)

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

qt_finalize_executable(${PROJECT_NAME})
