# CMake 最低版本要求
cmake_minimum_required(VERSION 3.10)

find_package(Qt5 COMPONENTS Core Widgets X11Extras Gui DBus REQUIRED)

# 包含 GTest 库和 pthread 库
find_package(GTest REQUIRED)
find_package(Threads REQUIRED)
find_package(X11 REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GIOUNIX2 REQUIRED gio-unix-2.0)
pkg_check_modules(GLIB2 REQUIRED glib-2.0 gio-2.0)
pkg_check_modules(XCB REQUIRED xcb)

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


# 开启代码覆盖率相关编译选项（对应QMAKE_LFLAGS和QMAKE_CXXFLAGS中代码覆盖率相关设置）

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")


# 定义源文件列表，对应原来的SOURCES变量
set(SOURCES
    ../../src/lock-dialog/lockdialogmodel.cpp
    ../../src/userinfo.cpp
    ../../src/agreementinfo.cpp
    ../../src/common/biodefines.cpp
    ../../src/common/global_utils.cpp
    ../..//src/widgets/screensavermode.cpp
    ../../src/common/utils.cpp
    unit_test_lock_dialog_model.cpp
    main.cpp
)

# 定义头文件列表，对应原来的HEADERS变量
set(HEADERS
    ../../src/lock-dialog/lockdialogmodel.h
    ../../src/common/definetypes.h
    ../../src/common/biodefines.h
    ../../src/userinfo.h
    ../../src/agreementinfo.h
    ../../src/common/global_utils.h
    ../..//src/widgets/screensavermode.h
    ../../src/common/utils.h
)

# 包含头文件的路径设置，对应原来的INCLUDEPATH变量
include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub
    ${CMAKE_CURRENT_SOURCE_DIR}/../kt-test-utils/cpp-stub-ext
    ${GIOUNIX2_INCLUDE_DIRS}
    ${X11_INCLUDE_DIRS}
    ${XCB_INCLUDE_DIRS}
)

# 使用qt5_wrap_cpp生成元对象代码相关的源文件
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})

# 添加可执行文件或库目标，将元对象代码源文件一起添加进去
add_executable(unit_test_lock_dialog_model ${SOURCES} ${MOC_SOURCES})

# 链接Qt相关的库
target_link_libraries(unit_test_lock_dialog_model
    Qt5::Core
    Qt5::Gui
    Qt5::DBus
    Qt5::Widgets
    Qt5::X11Extras
)

# 链接 GTest 库
target_link_libraries(unit_test_lock_dialog_model
    GTest::GTest
    GTest::Main
    Threads::Threads
    ${GIOUNIX2_LIBRARIES}
    ${X11_LIBRARIES}
    ${XCB_LIBRARIES}
)

