add_library(krdc_rdpplugin MODULE)

target_sources(krdc_rdpplugin PRIVATE
    rdpcliprdr.cpp
    rdpdisp.cpp
    rdpgraphics.cpp
    rdpmonitorview.cpp
    rdphostpreferences.cpp
    rdpviewfactory.cpp
    rdpview.cpp
    rdpsession.cpp
    sharedfolderfield.cpp
    smartcardreaderfield.cpp
)

ki18n_wrap_ui(krdc_rdpplugin
    rdppreferences.ui
)

ecm_qt_declare_logging_category(krdc_rdpplugin
    HEADER krdc_debug.h
    IDENTIFIER KRDC
    CATEGORY_NAME KRDC
)

target_include_directories(krdc_rdpplugin PUBLIC ${FreeRDP_INCLUDE_DIR} ${WinPR_INCLUDE_DIR})

target_link_libraries(krdc_rdpplugin
    Qt::Core
    Qt::Gui
    KF6::ConfigCore
    KF6::CoreAddons
    KF6::KCMUtils
    KF6::WindowSystem
    KF6::XmlGui
    KF6::KIOWidgets
    Threads::Threads
    krdccore
    freerdp
    freerdp-client
    winpr
)

find_package(PkgConfig QUIET)
set(KRDC_HAVE_KRB5 FALSE)
if(PkgConfig_FOUND)
    pkg_check_modules(KRB5 QUIET IMPORTED_TARGET krb5)
    if(KRB5_FOUND)
        set(KRDC_HAVE_KRB5 TRUE)
        target_link_libraries(krdc_rdpplugin PkgConfig::KRB5)
        target_compile_definitions(krdc_rdpplugin PRIVATE HAVE_KRB5)
    endif()
endif()
add_feature_info("Kerberos realm mappings" KRDC_HAVE_KRB5 "Preserve configured Kerberos domain-to-realm mappings for RDP logins")

if(KF6Screen_FOUND)
    target_link_libraries(krdc_rdpplugin KF6::Screen)
    target_compile_definitions(krdc_rdpplugin PRIVATE HAVE_KSCREEN)
endif()

if(Qt6DBus_FOUND)
    target_link_libraries(krdc_rdpplugin Qt::DBus)
    target_compile_definitions(krdc_rdpplugin PRIVATE HAVE_DBUS)
endif()

add_library(kcm_krdc_rdpplugin)

target_sources(kcm_krdc_rdpplugin PRIVATE
    rdppreferences.cpp
    sharedfolderfield.cpp
    smartcardreaderfield.cpp
)

target_link_libraries(kcm_krdc_rdpplugin
    Qt::Core
    Qt::Gui
    KF6::ConfigCore
    KF6::CoreAddons
    KF6::KCMUtils
    KF6::XmlGui
    KF6::KIOWidgets
    krdccore
    winpr
)
target_include_directories(kcm_krdc_rdpplugin PRIVATE ${WinPR_INCLUDE_DIR})

if(HAIKU)
    target_link_libraries(kcm_krdc_rdpplugin network)
endif()

# Sharing removable drives as they are plugged in replaces the drive check of FreeRDP 3.16.
if(KF6Solid_FOUND AND FreeRDP_VERSION VERSION_GREATER_EQUAL 3.16)
    target_sources(krdc_rdpplugin PRIVATE rdpremovabledrives.cpp)
    target_link_libraries(krdc_rdpplugin KF6::Solid)
    target_compile_definitions(krdc_rdpplugin PRIVATE HAVE_RDPDR_HOTPLUG)
    target_compile_definitions(kcm_krdc_rdpplugin PRIVATE HAVE_RDPDR_HOTPLUG)
endif()

add_dependencies(kcm_krdc_rdpplugin krdc_rdpplugin)

install(TARGETS kcm_krdc_rdpplugin DESTINATION ${KDE_INSTALL_PLUGINDIR}/krdc/kcms)
install(TARGETS krdc_rdpplugin DESTINATION ${KDE_INSTALL_PLUGINDIR}/krdc)

# install(FILES smb2rdc.desktop DESTINATION ${KDE_INSTALL_DATADIR}/kio/servicemenus)
