CMakeLists.txt 3.78 KB
Newer Older
1 2
cmake_minimum_required(VERSION 3.0)

Àlex Fiestas's avatar
Àlex Fiestas committed
3
project(kwrited)
4
set(PROJECT_VERSION "5.20.90")
5

6
set(QT_MIN_VERSION "5.15.0")
7
set(KF5_MIN_VERSION "5.78")
Àlex Fiestas's avatar
Àlex Fiestas committed
8

Nicolas Fella's avatar
Nicolas Fella committed
9 10 11
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

12
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
13
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} )
Àlex Fiestas's avatar
Àlex Fiestas committed
14

Hrvoje Senjan's avatar
Hrvoje Senjan committed
15
include(CMakeDependentOption)
Àlex Fiestas's avatar
Àlex Fiestas committed
16 17
include(KDEInstallDirs)
include(KDECMakeSettings)
18
include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE)
19
include(FeatureSummary)
20
include(KDEClangFormat)
Àlex Fiestas's avatar
Àlex Fiestas committed
21 22

find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
Nicolas Fella's avatar
Nicolas Fella committed
23
    Gui
Àlex Fiestas's avatar
Àlex Fiestas committed
24
)
25

26
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
Hrvoje Senjan's avatar
Hrvoje Senjan committed
27 28
    CoreAddons
    I18n
Àlex Fiestas's avatar
Àlex Fiestas committed
29
    Pty
Hrvoje Senjan's avatar
Hrvoje Senjan committed
30
    Notifications
Àlex Fiestas's avatar
Àlex Fiestas committed
31 32
)

Hrvoje Senjan's avatar
Hrvoje Senjan committed
33 34
cmake_dependent_option(BUILD_AS_EXECUTABLE "Whether to build kwrited as executable" OFF
                       "KPty_HAVE_UTEMPTER" ON)
35

36
if (NOT BUILD_AS_EXECUTABLE)
37
find_package(KF5DBusAddons ${KF5_MIN_VERSION})
38 39 40 41 42 43
set_package_properties(KF5DBusAddons PROPERTIES DESCRIPTION "Convenience classes for DBus"
                       TYPE REQUIRED
                       PURPOSE "Needed to build kwrited's KDED module"
                      )
endif ()

44 45 46
add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT)
add_definitions(-DQT_NO_URL_CAST_FROM_STRING)

47 48
if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
   add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000)
49
   add_definitions(-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x054200)
50 51
endif()

52 53 54 55 56
# If libutempter is not available on the system, we build
# kwrited as an executable that is installed with setuid root
# (or setgid utmp) in order to be able to login successfully
# (and thus be useful, as kwrited does not work at all if it
# cannot login to the terminal device that it opens).
57

58 59 60
configure_file(config-kwrited.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kwrited.h)

if (BUILD_AS_EXECUTABLE)
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
61
    add_executable(kwrited kwrited.cpp)
62
    target_compile_definitions(kwrited PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}")
Nicolas Fella's avatar
Nicolas Fella committed
63
    target_link_libraries(kwrited Qt5::Gui KF5::CoreAddons KF5::I18n KF5::Notifications KF5::Pty)
Laurent Montel's avatar
Laurent Montel committed
64
    install(TARGETS kwrited  ${INSTALL_TARGETS_DEFAULT_ARGS} )
65 66 67 68 69
    if(IS_ABSOLUTE BIN_INSTALL_DIR)
        set(ABS_BIN_INSTALL_DIR "${BIN_INSTALL_DIR}")
    else()
        set(ABS_BIN_INSTALL_DIR "\${CMAKE_INSTALL_PREFIX}/${BIN_INSTALL_DIR}")
    endif()
70
    install(CODE "
71
               set(KWRITED_PATH \"\$ENV{DESTDIR}${ABS_BIN_INSTALL_DIR}/kwrited\")
72 73 74 75 76 77

               # On Debian we setgid instead of setuid.
               # Feel free to add checks here for other distros as well, if needed.
               if (EXISTS /etc/debian_version)
                   set(SETGID 1)
                   set(SETGID_GROUP utmp)
78
               endif ()
79 80 81

               if (SETGID)
                   execute_process(COMMAND sh -c \"chgrp \${SETGID_GROUP} '\${KWRITED_PATH}' && chmod g+s '\${KWRITED_PATH}'\")
82
               else ()
83
                   execute_process(COMMAND sh -c \"chown root '\${KWRITED_PATH}' && chmod u+s '\${KWRITED_PATH}'\")
84
               endif()
85 86 87
           ")

    install(FILES kwrited-autostart.desktop DESTINATION ${AUTOSTART_INSTALL_DIR})
88
else ()
89 90 91 92 93 94
    kcoreaddons_add_plugin(kded_kwrited
        SOURCES kwrited.cpp
        JSON kwrited.json
        INSTALL_NAMESPACE "kf5/kded"
    )
    set_target_properties(kded_kwrited PROPERTIES OUTPUT_NAME kwrited)
95
    target_compile_definitions(kded_kwrited PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}")
Hrvoje Senjan's avatar
Hrvoje Senjan committed
96
    target_link_libraries(kded_kwrited KF5::CoreAddons KF5::DBusAddons KF5::I18n KF5::Notifications KF5::Pty)
97
endif ()
98 99

# The .notifyrc file is common
100
install(FILES kwrited.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR})
101

102 103 104 105
# add clang-format target for all our real source files
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h)
kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})

Xuetian Weng's avatar
Xuetian Weng committed
106
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)