Warning, /frameworks/extra-cmake-modules/modules/ECMGenerateDBusServiceFile.cmake is written in an unsupported language. File is not indexed.

0001 # SPDX-FileCopyrightText: 2020 Kai Uwe Broulik <kde@broulik.de>
0002 # SPDX-FileCopyrightText: 2020 Henri Chain <henri.chain@enioka.com>
0003 #
0004 # SPDX-License-Identifier: BSD-3-Clause
0005 
0006 #[=======================================================================[.rst:
0007 ECMGenerateDBusServiceFile
0008 ---------------------------
0009 
0010 This module provides the ``ecm_generate_dbus_service_file`` function for
0011 generating and installing a D-Bus service file.
0012 
0013 ::
0014 
0015   ecm_generate_dbus_service_file(
0016       NAME <service name>
0017       EXECUTABLE <executable>
0018       [SYSTEMD_SERVICE <systemd service>]
0019       DESTINATION <install_path>
0020       [RENAME <dbus service filename>] # Since 5.75
0021   )
0022 
0023 A D-Bus service file ``<service name>.service`` will be generated and installed
0024 in the relevant D-Bus config location. This filename can be customized with RENAME.
0025 
0026 ``<executable>`` must be an absolute path to the installed service executable. When using it with
0027 :kde-module:`KDEInstallDirs` it needs to be the ``_FULL_`` variant of the path variable.
0028 
0029 .. note::
0030   On Windows, the macro will only use the file name part of ``<executable>`` since D-Bus
0031   service executables are to be installed in the same directory as the D-Bus daemon.
0032 
0033 Optionally, a ``<systemd service>`` can be specified to launch the corresponding
0034 systemd service instead of the ``<executable>`` if the D-Bus daemon is started by systemd.
0035 
0036 Example usage:
0037 
0038 .. code-block:: cmake
0039 
0040   ecm_generate_dbus_service_file(
0041       NAME org.kde.kded5
0042       EXECUTABLE ${KDE_INSTALL_FULL_BINDIR}/kded5
0043       DESTINATION ${KDE_INSTALL_DBUSSERVICEDIR}
0044   )
0045 
0046 .. code-block:: cmake
0047 
0048   ecm_generate_dbus_service_file(
0049       NAME org.kde.kded5
0050       EXECUTABLE ${KDE_INSTALL_FULL_BINDIR}/kded5
0051       SYSTEMD_SERVICE plasma-kded.service
0052       DESTINATION ${KDE_INSTALL_DBUSSERVICEDIR}
0053       RENAME org.kde.daemon.service
0054   )
0055 
0056 Since 5.73.0.
0057 #]=======================================================================]
0058 
0059 function(ecm_generate_dbus_service_file)
0060     set(options)
0061     set(oneValueArgs EXECUTABLE NAME SYSTEMD_SERVICE DESTINATION RENAME)
0062     set(multiValueArgs)
0063     cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
0064 
0065     if(ARG_UNPARSED_ARGUMENTS)
0066         message(FATAL_ERROR "Unexpected arguments to ecm_generate_dbus_service_file: ${ARG_UNPARSED_ARGUMENTS}")
0067     endif()
0068     if(NOT ARG_NAME)
0069         message(FATAL_ERROR "Missing NAME argument for ecm_generate_dbus_service_file")
0070     endif()
0071     if(NOT ARG_EXECUTABLE)
0072         message(FATAL_ERROR "Missing EXECUTABLE argument for ecm_generate_dbus_service_file")
0073     endif()
0074     if(NOT ARG_DESTINATION)
0075         message(FATAL_ERROR "Missing DESTINATION argument for ecm_generate_dbus_service_file")
0076     endif()
0077 
0078     if(WIN32)
0079         get_filename_component(_exec "${ARG_EXECUTABLE}" NAME)
0080     else()
0081         if (NOT IS_ABSOLUTE ${ARG_EXECUTABLE})
0082             message(FATAL_ERROR "EXECUTABLE must be an absolute path in ecm_generate_dbus_service_file")
0083         else()
0084             set(_exec ${ARG_EXECUTABLE})
0085         endif()
0086     endif()
0087 
0088     set(_service_file ${CMAKE_CURRENT_BINARY_DIR}/${ARG_NAME}.service)
0089 
0090     file(WRITE ${_service_file}
0091     "[D-BUS Service]
0092 Name=${ARG_NAME}
0093 Exec=${_exec}
0094 ")
0095 
0096     if (ARG_SYSTEMD_SERVICE)
0097         file(APPEND ${_service_file} "SystemdService=${ARG_SYSTEMD_SERVICE}\n")
0098     endif()
0099 
0100     if (ARG_RENAME)
0101         install(FILES ${_service_file} DESTINATION ${ARG_DESTINATION} RENAME ${ARG_RENAME})
0102     else()
0103         install(FILES ${_service_file} DESTINATION ${ARG_DESTINATION})
0104     endif()
0105 endfunction()