# Include common directory for MessageHandler
include_directories(
    "${CMAKE_SOURCE_DIR}/src/common"
    "${CMAKE_BINARY_DIR}/src/common"
)

add_executable(plasma-login-wallpaper)

# Only define HAVE_SYSTEMD when systemd is found - on non-systemd systems, don't define it at all
# This allows using #ifdef HAVE_SYSTEMD in the source code
if(SYSTEMD_FOUND)
    target_compile_definitions(plasma-login-wallpaper PRIVATE HAVE_SYSTEMD)
endif()

ecm_add_qml_module(plasma-login-wallpaper URI "org.kde.plasma.login.wallpaper" GENERATE_PLUGIN_SOURCE)

target_sources(plasma-login-wallpaper PRIVATE
    main.cpp
    wallpaperapp.cpp
    wallpaperwindow.cpp
)

ecm_target_qml_sources(plasma-login-wallpaper PRIVATE
    SOURCES
    main.qml
    WallpaperFader.qml
)

target_link_libraries(plasma-login-wallpaper PRIVATE
    settings
    Qt::Core
    Qt::Gui
    Qt::DBus
    Qt::Quick
    KF6::WindowSystem
    KF6::Package
    Plasma::PlasmaQuick
)

if(LIBSYSTEMD_FOUND)
    target_link_libraries(plasma-login-wallpaper PRIVATE PkgConfig::LIBSYSTEMD)
endif()

qt_add_shaders(plasma-login-wallpaper "wallpaper_shaders"
    PRECOMPILE
    BATCHABLE
    OPTIMIZED
    PREFIX "/qt/qml/org/kde/plasma/login/wallpaper/shaders"
    FILES
        WallpaperFader.frag
    OUTPUTS
        WallpaperFader.frag.qsb
)

ecm_finalize_qml_module(plasma-login-wallpaper)

install(TARGETS plasma-login-wallpaper DESTINATION ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
if(SYSTEMD_FOUND)
    ecm_install_configured_files(INPUT plasma-wallpaper.service.in DESTINATION ${KDE_INSTALL_SYSTEMDUSERUNITDIR})
endif()
