blob: f6e3dce2f34cfe833e23ce9ac4cf97ca93a619a3 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001From 7a792624925d46690c1f07fe4b194b5f4c510db6 Mon Sep 17 00:00:00 2001
2From: Paulo Neves <ptsneves@gmail.com>
3Date: Tue, 2 Aug 2022 09:57:05 +0200
4Subject: [PATCH 1/1] build: Make systemd init systemd detection contingent on
5 pkgconfig
6
7Use pkg-config to get systemd.pc variables and systemdunitdir. Those
8variable ensure that .service files are installed in the correct paths
9and only when systemd is detected.
10
Patrick Williamsb9af8752023-01-30 13:28:01 -060011Upstream-Status: Pending [https://github.com/fluent/fluent-bit/pull/5818]
Patrick Williams92b42cb2022-09-03 06:53:57 -050012
13---
14 cmake/FindJournald.cmake | 4 ++++
15 src/CMakeLists.txt | 4 ++--
16 2 files changed, 6 insertions(+), 2 deletions(-)
17
18diff --git a/cmake/FindJournald.cmake b/cmake/FindJournald.cmake
19index f5a3a832b..9e6657a29 100644
20--- a/cmake/FindJournald.cmake
21+++ b/cmake/FindJournald.cmake
22@@ -5,6 +5,8 @@
23 # JOURNALD_INCLUDE_DIR - the Journald include directory
24 # JOURNALD_LIBRARIES - Link these to use Journald
25 # JOURNALD_DEFINITIONS - Compiler switches required for using Journald
26+# SYSTEMD_UNITDIR - The systemd units' directory
27+#
28 # Redistribution and use is allowed according to the terms of the BSD license.
29 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
30 #
31@@ -16,7 +18,9 @@
32 # in the FIND_PATH() and FIND_LIBRARY() calls
33 find_package(PkgConfig)
34 pkg_check_modules(PC_JOURNALD QUIET systemd)
35+pkg_get_variable(PC_SYSTEMD_UNITDIR systemd "systemdsystemunitdir")
36
37+set(SYSTEMD_UNITDIR ${PC_SYSTEMD_UNITDIR})
38 set(JOURNALD_FOUND ${PC_JOURNALD_FOUND})
39 set(JOURNALD_DEFINITIONS ${PC_JOURNALD_CFLAGS_OTHER})
40
41diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
42index 522bbf9bd..30743d8d6 100644
43--- a/src/CMakeLists.txt
44+++ b/src/CMakeLists.txt
45@@ -480,13 +480,13 @@ if(FLB_BINARY)
46 endif()
47
48 # Detect init system, install upstart, systemd or init.d script
49- if(IS_DIRECTORY /lib/systemd/system)
50+ if(DEFINED SYSTEMD_UNITDIR)
51 set(FLB_SYSTEMD_SCRIPT "${PROJECT_SOURCE_DIR}/init/${FLB_OUT_NAME}.service")
52 configure_file(
53 "${PROJECT_SOURCE_DIR}/init/systemd.in"
54 ${FLB_SYSTEMD_SCRIPT}
55 )
56- install(FILES ${FLB_SYSTEMD_SCRIPT} COMPONENT binary DESTINATION /lib/systemd/system)
57+ install(FILES ${FLB_SYSTEMD_SCRIPT} COMPONENT binary DESTINATION ${SYSTEMD_UNITDIR})
58 install(DIRECTORY DESTINATION ${FLB_INSTALL_CONFDIR} COMPONENT binary)
59 elseif(IS_DIRECTORY /usr/share/upstart)
60 set(FLB_UPSTART_SCRIPT "${PROJECT_SOURCE_DIR}/init/${FLB_OUT_NAME}.conf")
61--
622.25.1
63