From 97bdefd4e2598e6ea72337acb4230928594bda81 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 18 May 2020 12:44:37 +0200 Subject: cmake: Add support for systemd integration on Linux operating systems Previously, only the Autotools build system could do this. This commit includes most of the same features as in the Autotools build, although not the user-session semantics, which will be added separately. Systemd support is controlled by the cmake variable ENABLE_SYSTEMD, which can have the values OFF, ON and AUTO, the latter enabling support by default if the required libraries are available. With WITH_SYSTEMD_SYSTEMUNITDIR a custom installation location can be specified. If it is not specified, the related install path is determined from the installed systemd package, if present. --- CMakeLists.txt | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index a0095ebb..48cf9675 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,10 @@ set(BUILD_TIMESTAMP ${DBUS_BUILD_TIMESTAMP}) ########### basic vars ############### +if(UNIX AND CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(DBUS_LINUX 1) +endif() + include(GNUInstallDirs) if(DBUSDIR) @@ -135,6 +139,35 @@ option(DBUS_DISABLE_ASSERT "Disable assertion checking" OFF) option(DBUS_ENABLE_STATS "enable bus daemon usage statistics" OFF) option(DBUS_ENABLE_CONTAINERS "enable restricted servers for app-containers" OFF) +if(DBUS_LINUX) + add_auto_option(ENABLE_SYSTEMD "build with systemd at_console support" AUTO) + include(FindPkgConfig) + pkg_check_modules(SYSTEMD libsystemd>=209) + if(NOT SYSTEMD_FOUND) + pkg_check_modules(SYSTEMD libsystemd-login>=32 libsystemd-daemon>=32 libsystemd-journal>=32) + endif() + check_auto_option(ENABLE_SYSTEMD "systemd support" SYSTEMD_FOUND "systemd") + if(ENABLE_SYSTEMD AND SYSTEMD_FOUND) + set(DBUS_BUS_ENABLE_SYSTEMD ON) + set(HAVE_SYSTEMD ${SYSTEMD_FOUND}) + endif() + add_path_option(WITH_SYSTEMD_SYSTEMUNITDIR "Directory for systemd service files" "") + # get defaults + pkg_check_modules(_SYSTEMD systemd) + if(_SYSTEMD_FOUND) + pkg_get_variable(_SYSTEMD_PREFIX systemd prefix) + pkg_get_variable(_SYSTEMD_SYSTEMUNITDIR systemd systemdsystemunitdir) + pkg_get_variable(_SYSTEMD_USERUNITDIR systemd systemduserunitdir) + # remove install prefix, which may not match the current prefix + string(REPLACE "${_SYSTEMD_PREFIX}/" "" DBUS_SYSTEMD_SYSTEMUNITDIR ${_SYSTEMD_SYSTEMUNITDIR}) + else() + set(DBUS_SYSTEMD_SYSTEMUNITDIR lib/systemd/system) + endif() + if(WITH_SYSTEMD_SYSTEMUNITDIR) + set(DBUS_SYSTEMD_SYSTEMUNITDIR ${WITH_SYSTEMD_SYSTEMUNITDIR}) + endif() +endif() + if(WIN32) set(FD_SETSIZE "8192" CACHE STRING "The maximum number of connections that can be handled at once") endif() @@ -609,6 +642,8 @@ message(" Building bus stats API: ${DBUS_ENABLE_STATS} " message(" installing system libs: ${DBUS_INSTALL_SYSTEM_LIBS} ") message(" Building inotify support: ${DBUS_BUS_ENABLE_INOTIFY} ") message(" Building kqueue support: ${DBUS_BUS_ENABLE_KQUEUE} ") +message(" Building systemd support: ${DBUS_BUS_ENABLE_SYSTEMD} ") +message(" systemd system install dir:${DBUS_SYSTEMD_SYSTEMUNITDIR} ") message(" Building Doxygen docs: ${DBUS_ENABLE_DOXYGEN_DOCS} ") message(" Building Qt help docs: ${DBUS_ENABLE_QTHELP_DOCS} ") message(" Building XML docs: ${DBUS_ENABLE_XML_DOCS} ") @@ -679,7 +714,6 @@ add_custom_target(help-options # if(DBUS_ENABLE_PKGCONFIG) set(PLATFORM_LIBS pthread ${LIBRT}) - include(FindPkgConfig QUIET) if(PKG_CONFIG_FOUND) # convert lists of link libraries into -lstdc++ -lm etc.. foreach(LIB ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS}) -- cgit v1.2.1