Commit 927a5f4d authored by Ralf Habacker's avatar Ralf Habacker Committed by Simon McVittie
Browse files

cmake: add support for user session semantic on Linux operating systems

Systemd user support is controlled by the cmake variable ENABLE_USER_SESSION,
which and WITH_SYSTEMD_USERUNITDIR to specify a custom installation
location. If WITH_SYSTEMD_USERUNITDIR is not specified, the related install
path is determined from an installed systemd package, if present.

This was added to the Autotools build system as part of fd.o#61301,
but until now was not possible to enable when building with CMake.
parent 97bdefd4
......@@ -151,7 +151,11 @@ if(DBUS_LINUX)
set(DBUS_BUS_ENABLE_SYSTEMD ON)
set(HAVE_SYSTEMD ${SYSTEMD_FOUND})
endif()
option(ENABLE_USER_SESSION "enable user-session semantics for session bus under systemd" OFF)
set(DBUS_ENABLE_USER_SESSION ${ENABLE_USER_SESSION})
add_path_option(WITH_SYSTEMD_SYSTEMUNITDIR "Directory for systemd service files" "")
add_path_option(WITH_SYSTEMD_USERUNITDIR "Directory for systemd user service files" "")
# get defaults
pkg_check_modules(_SYSTEMD systemd)
if(_SYSTEMD_FOUND)
......@@ -160,12 +164,17 @@ if(DBUS_LINUX)
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})
string(REPLACE "${_SYSTEMD_PREFIX}/" "" DBUS_SYSTEMD_USERUNITDIR ${_SYSTEMD_USERUNITDIR})
else()
set(DBUS_SYSTEMD_SYSTEMUNITDIR lib/systemd/system)
set(DBUS_SYSTEMD_USERUNITDIR lib/systemd/user)
endif()
if(WITH_SYSTEMD_SYSTEMUNITDIR)
set(DBUS_SYSTEMD_SYSTEMUNITDIR ${WITH_SYSTEMD_SYSTEMUNITDIR})
endif()
if(WITH_SYSTEMD_USERUNITDIR)
set(DBUS_SYSTEMD_USERUNITDIR ${WITH_SYSTEMD_USERUNITDIR})
endif()
endif()
if(WIN32)
......@@ -644,6 +653,7 @@ 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(" systemd user install dir: ${DBUS_SYSTEMD_USERUNITDIR} ")
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} ")
......
......@@ -155,6 +155,12 @@ ENABLE_SYSTEMD:STRING=AUTO
// Directory for systemd service files
WITH_SYSTEMD_SYSTEMUNITDIR:STRING=
// enable user-session semantics for session bus under systemd
ENABLE_USER_SESSION:BOOL=ON
// Directory for systemd user service files
WITH_SYSTEMD_USERUNITDIR:STRING=
// support verbose debug mode
DBUS_ENABLE_VERBOSE_MODE:BOOL=ON
......
......@@ -176,6 +176,13 @@ if(DBUS_BUS_ENABLE_SYSTEMD)
add_systemd_service(${CMAKE_CURRENT_BINARY_DIR}/dbus.service PATH ${DBUS_SYSTEMD_SYSTEMUNITDIR} LINKS multi-user.target.wants)
endif()
if(DBUS_ENABLE_USER_SESSION)
configure_file(systemd-user/dbus.socket.in ${CMAKE_CURRENT_BINARY_DIR}/systemd-user/dbus.socket)
configure_file(systemd-user/dbus.service.in ${CMAKE_CURRENT_BINARY_DIR}/systemd-user/dbus.service)
add_systemd_service(${CMAKE_CURRENT_BINARY_DIR}/systemd-user/dbus.socket PATH ${DBUS_SYSTEMD_USERUNITDIR} LINKS sockets.target.wants)
add_systemd_service(${CMAKE_CURRENT_BINARY_DIR}/systemd-user/dbus.service PATH ${DBUS_SYSTEMD_USERUNITDIR})
endif()
## mop up the gcov files
#clean-local:
# /bin/rm *.bb *.bbg *.da *.gcov || true
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment