project(ksmserver)

add_definitions(-DTRANSLATION_DOMAIN=\"ksmserver\")

add_subdirectory( tests )
#
if(NOT WIN32)
  add_subdirectory( screenlocker )
  set(COMPILE_SCREEN_LOCKER 1)
  set(SCREEN_LOCKER "screenlocker_static")
endif()

check_library_exists(ICE _IceTransNoListen "" HAVE__ICETRANSNOLISTEN)
configure_file(config-ksmserver.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-ksmserver.h)

########### next target ###############

set(ksmserver_KDEINIT_SRCS
    ksmserver_debug.cpp
    main.cpp
    server.cpp
    shutdowndlg.cpp
    legacy.cpp
    startup.cpp
    shutdown.cpp
    client.cpp
)

INCLUDE(CheckCCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-mmmx HAVE_MMMX)

if (HAVE_MMMX)
   SET_SOURCE_FILES_PROPERTIES(fadeeffect.cpp PROPERTIES COMPILE_FLAGS -mmmx)
endif (HAVE_MMMX)

set(kcminit_adaptor ${plasma-workspace_SOURCE_DIR}/startkde/kcminit/main.h)
set(kcminit_xml ${CMAKE_CURRENT_BINARY_DIR}/org.kde.KCMinit.xml)

qt5_generate_dbus_interface( ${kcminit_adaptor} ${kcminit_xml} )
qt5_add_dbus_interface( ksmserver_KDEINIT_SRCS ${kcminit_xml} kcminit_interface )

# FIXME: This is actually not disabled any more because OrgKDEKlauncherInterface isn't provided
# otherwise.
# # This is actually now disabled, because OrgKDEKlauncherInterface is also provided
# # by kdecore, it is not autogenerated and is not binary compatible with a currently
# # generated version, thus at certain circumstances leading to strange crashes.
# # This should be fixed for KDE5.
# # KLauchner.xml is installed by kdelibs, so it is in KDE4_DBUS_INTERFACES_DIR
set(klauncher_xml ${KINIT_DBUS_INTERFACES_DIR}/kf5_org.kde.KLauncher.xml)
qt5_add_dbus_interface( ksmserver_KDEINIT_SRCS ${klauncher_xml} klauncher_interface )

qt5_add_dbus_adaptor( ksmserver_KDEINIT_SRCS org.kde.KSMServerInterface.xml server.h KSMServer )

kf5_add_kdeinit_executable( ksmserver ${ksmserver_KDEINIT_SRCS})

set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/KSMServerDBusInterface")

ecm_configure_package_config_file(KSMServerDBusInterfaceConfig.cmake.in
    ${CMAKE_CURRENT_BINARY_DIR}/KSMServerDBusInterfaceConfig.cmake
    INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR})

target_link_libraries(kdeinit_ksmserver
    ${SCREEN_LOCKER}
    PW::KWorkspace
    KF5::XmlGui
    KF5::GlobalAccel
    KF5::KIOCore
    KF5::KIOWidgets
    ${X11_LIBRARIES}
    ${X11_Xrender_LIB}
    Qt5::X11Extras
    KF5::Solid
    Qt5::Quick
    KF5::Declarative
    KF5::DBusAddons
    KF5::Plasma
    KF5::PlasmaQuick
    KF5::KDELibs4Support # Solid/PowerManagement
)

install(TARGETS kdeinit_ksmserver ${INSTALL_TARGETS_DEFAULT_ARGS})

install(TARGETS ksmserver ${INSTALL_TARGETS_DEFAULT_ARGS})

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/KSMServerDBusInterfaceConfig.cmake
    DESTINATION ${CMAKECONFIG_INSTALL_DIR})
########### next target ###############

set(kcheckrunning_SRCS
    kcheckrunning.cpp)

kde4_add_executable( kcheckrunning ${kcheckrunning_SRCS})

target_link_libraries(kcheckrunning ${X11_LIBRARIES})

install(TARGETS kcheckrunning ${INSTALL_TARGETS_DEFAULT_ARGS})

########### install files ###############

install( FILES org.kde.KSMServerInterface.xml DESTINATION ${DBUS_INTERFACES_INSTALL_DIR})
install( DIRECTORY themes/ DESTINATION ${DATA_INSTALL_DIR}/ksmserver/themes )
