summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2020-05-18 12:47:51 +0200
committerSimon McVittie <smcv@collabora.com>2020-06-10 18:13:47 +0000
commit927a5f4d757e9eacb6f133ebd45b69db01e9e2f3 (patch)
tree7b022f56b45be246fc4e6333322134f082d2a39b
parent97bdefd4e2598e6ea72337acb4230928594bda81 (diff)
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.
-rw-r--r--CMakeLists.txt10
-rw-r--r--README.cmake6
-rw-r--r--bus/CMakeLists.txt7
3 files changed, 23 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 48cf9675..caef7384 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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} ")
diff --git a/README.cmake b/README.cmake
index 0b32fdca..7c984430 100644
--- a/README.cmake
+++ b/README.cmake
@@ -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
diff --git a/bus/CMakeLists.txt b/bus/CMakeLists.txt
index 2aa6068d..09503966 100644
--- a/bus/CMakeLists.txt
+++ b/bus/CMakeLists.txt
@@ -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