# CMakeLists.txt for notificationsadaptor unit tests
cmake_minimum_required(VERSION 3.5.0)
project(test_notificationsadaptor)

# Set C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Enable Qt features
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

# Find required packages
find_package(Qt5 COMPONENTS Core Widgets Test DBus Sql REQUIRED)
find_package(KF5WindowSystem REQUIRED)

# Try to find QGSettings
#find_path(QGSETTINGS_INCLUDE_DIR NAMES qgsettings.h PATHS /usr/include/aarch64-linux-gnu/qt5/QGSettings)
#if(QGSETTINGS_INCLUDE_DIR)
#    include_directories(${QGSETTINGS_INCLUDE_DIR})
#endif()

# Find gsettings-qt
find_package(PkgConfig REQUIRED)
pkg_check_modules(Gsetting REQUIRED gsettings-qt)

# Include directories
include_directories(
    ../../../lunarcalendarwidget
    ${Qt5Core_INCLUDE_DIRS}
    ${Qt5Widgets_INCLUDE_DIRS}
    ${Qt5Test_INCLUDE_DIRS}
    ${Qt5DBus_INCLUDE_DIRS}
    ${Qt5Sql_INCLUDE_DIRS}
    ${Gsetting_INCLUDE_DIRS}
    /usr/include/kysdk/applications
    /usr/include/kysdk/kysdk-system
)

# Source files for test
set(TEST_SOURCES
    test_notificationsadaptor.cpp
    main.cpp
    ../../../lunarcalendarwidget/notificationsadaptor.cpp
    ../../../lunarcalendarwidget/lunarcalendarinfo.cpp
)

# Create test executable
add_executable(test_notificationsadaptor ${TEST_SOURCES})

# Link libraries
target_link_libraries(test_notificationsadaptor PRIVATE
    Qt5::Core
    Qt5::Widgets
    Qt5::Test
    Qt5::DBus
    Qt5::Sql
    KF5::WindowSystem
    ${Gsetting_LIBRARIES}
    ${GTEST_LIBRARIES}
    ${GMOCK_LIBRARIES}
    pthread
)

# Try to link QGSettings if found
#if(QGSETTINGS_INCLUDE_DIR)
#    find_library(QGSETTINGS_LIBRARY NAMES qgsettings PATHS /usr/lib/aarch64-linux-gnu)
#    if(QGSETTINGS_LIBRARY)
#        target_link_libraries(test_notificationsadaptor PRIVATE ${QGSETTINGS_LIBRARY})
#    endif()
#endif()

# Try to link kysdk-system if found
find_library(KYSDK_SYSTEM_LIBRARY NAMES kysdk-system)
if(KYSDK_SYSTEM_LIBRARY)
    target_link_libraries(test_notificationsadaptor PRIVATE ${KYSDK_SYSTEM_LIBRARY})
endif()

# Try to link kysdk-qtwidgets if found
find_library(KYSDK_QTWIDGETS_LIBRARY NAMES kysdk-qtwidgets)
if(KYSDK_QTWIDGETS_LIBRARY)
    target_link_libraries(test_notificationsadaptor PRIVATE ${KYSDK_QTWIDGETS_LIBRARY})
endif()

# Try to link kysdk-kabase if found
find_library(KYSDK_KABASE_LIBRARY NAMES kysdk-kabase)
if(KYSDK_KABASE_LIBRARY)
    target_link_libraries(test_notificationsadaptor PRIVATE ${KYSDK_KABASE_LIBRARY})
endif()

# Try to link kysdk-waylandhelper if found
find_library(KYSDK_WAYLANDHELPER_LIBRARY NAMES kysdk-waylandhelper)
if(KYSDK_WAYLANDHELPER_LIBRARY)
    target_link_libraries(test_notificationsadaptor PRIVATE ${KYSDK_WAYLANDHELPER_LIBRARY})
endif()


# Enable coverage flags
target_compile_options(test_notificationsadaptor PRIVATE --coverage)
target_link_libraries(test_notificationsadaptor PRIVATE --coverage -lgcov)
