1#   BAREOS® - Backup Archiving REcovery Open Sourced
2#
3#   Copyright (C) 2017-2017 Bareos GmbH & Co. KG
4#
5#   This program is Free Software; you can redistribute it and/or
6#   modify it under the terms of version three of the GNU Affero General Public
7#   License as published by the Free Software Foundation and included
8#   in the file LICENSE.
9#
10#   This program is distributed in the hope that it will be useful, but
11#   WITHOUT ANY WARRANTY; without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13#   Affero General Public License for more details.
14#
15#   You should have received a copy of the GNU Affero General Public License
16#   along with this program; if not, write to the Free Software
17#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18#   02110-1301, USA.
19
20# taken from
21# https://raw.githubusercontent.com/ximion/limba/master/data/cmake/systemdservice.cmake
22#
23# Find systemd service dir
24
25include(FindPkgConfig)
26
27pkg_check_modules(SYSTEMD "systemd")
28if(SYSTEMD_FOUND AND "${SYSTEMD_UNITDIR}" STREQUAL "")
29  execute_process(
30    COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=systemdsystemunitdir systemd
31    OUTPUT_VARIABLE SYSTEMD_UNITDIR
32  )
33  string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_UNITDIR "${SYSTEMD_UNITDIR}")
34elseif(NOT SYSTEMD_FOUND AND SYSTEMD_UNITDIR)
35  message(FATAL_ERROR "Variable SYSTEMD_UNITDIR is\
36		defined, but we can't find systemd using pkg-config"
37  )
38endif()
39
40if(SYSTEMD_FOUND)
41  set(WITH_SYSTEMD "ON")
42  message(STATUS "systemd services install dir: ${SYSTEMD_UNITDIR}")
43else()
44  set(WITH_SYSTEMD "OFF")
45endif(SYSTEMD_FOUND)
46