# ============================================================
# vqt6 CMakeLists.txt — 构建 vqt6 C 桥接层
#
# 默认产物: libvqt6_bridge.a (静态库)
# 可选产物: vqt6_bridge.dll (动态库)
#
# 使用:
#   cmake -B build -S .
#   cmake --build build --config Release
# ============================================================

cmake_minimum_required(VERSION 3.16)
project(vqt6_bridge CXX C)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)

# 构建选项
option(VQT6_BUILD_SHARED "Build vqt6 as shared library (DLL)" OFF)
option(VQT6_BUILD_STATIC "Build vqt6 as static library" ON)
option(VQT6_BUILD_EXAMPLES "Build example programs" OFF)

# Qt6 依赖
find_package(Qt6 6.5 REQUIRED COMPONENTS
    Core
    Gui
    Widgets
    Network
)

# Win32 GUI 应用不需要控制台
if(WIN32)
    set(CMAKE_WIN32_EXECUTABLE OFF)
endif()

# 公共源文件
set(VQT6_SOURCES
    _bridge_core.cpp
    _bridge_widgets.cpp
    _bridge_gui.cpp
    _bridge_network.cpp
)

set(VQT6_HEADERS
    _bridge.h
    _bridge_widgets.h
    _bridge_gui.h
    _bridge_network.h
)

# Qt 模块
set(VQT6_QT_MODULES
    Qt6::Core
    Qt6::Gui
    Qt6::Widgets
    Qt6::Network
)

# ============================================================
# 静态库
# ============================================================
if(VQT6_BUILD_STATIC)
    add_library(vqt6_bridge_static STATIC ${VQT6_SOURCES} ${VQT6_HEADERS})
    target_link_libraries(vqt6_bridge_static PUBLIC ${VQT6_QT_MODULES})
    target_compile_definitions(vqt6_bridge_static PUBLIC VQT6_BRIDGE_STATIC)
    target_include_directories(vqt6_bridge_static PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}
    )
    set_target_properties(vqt6_bridge_static PROPERTIES
        OUTPUT_NAME vqt6_bridge
        ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
    )
endif()

# ============================================================
# 动态库
# ============================================================
if(VQT6_BUILD_SHARED)
    add_library(vqt6_bridge SHARED ${VQT6_SOURCES} ${VQT6_HEADERS})
    target_link_libraries(vqt6_bridge PUBLIC ${VQT6_QT_MODULES})
    target_compile_definitions(vqt6_bridge PRIVATE VQT6_BRIDGE_BUILD)
    target_include_directories(vqt6_bridge PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}
    )
    set_target_properties(vqt6_bridge PROPERTIES
        ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
        RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
    )
endif()

# ============================================================
# 安装
# ============================================================
install(TARGETS vqt6_bridge_static vqt6_bridge
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION bin
)

install(FILES ${VQT6_HEADERS}
    DESTINATION include/vqt6
)

# ============================================================
# 示例
# ============================================================
if(VQT6_BUILD_EXAMPLES)
    add_subdirectory(examples)
endif()
