blob: 9d4d950d15cc768ea3a63e8036c1bf2cb21ae184 [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
11Upstream Status: Pending [1]
12[1] https://github.com/fluent/fluent-bit/pull/5818
13
14---
15 cmake/FindJournald.cmake | 4 ++++
16 src/CMakeLists.txt | 4 ++--
17 2 files changed, 6 insertions(+), 2 deletions(-)
18
19diff --git a/cmake/FindJournald.cmake b/cmake/FindJournald.cmake
20index f5a3a832b..9e6657a29 100644
21--- a/cmake/FindJournald.cmake
22+++ b/cmake/FindJournald.cmake
23@@ -5,6 +5,8 @@
24 # JOURNALD_INCLUDE_DIR - the Journald include directory
25 # JOURNALD_LIBRARIES - Link these to use Journald
26 # JOURNALD_DEFINITIONS - Compiler switches required for using Journald
27+# SYSTEMD_UNITDIR - The systemd units' directory
28+#
29 # Redistribution and use is allowed according to the terms of the BSD license.
30 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
31 #
32@@ -16,7 +18,9 @@
33 # in the FIND_PATH() and FIND_LIBRARY() calls
34 find_package(PkgConfig)
35 pkg_check_modules(PC_JOURNALD QUIET systemd)
36+pkg_get_variable(PC_SYSTEMD_UNITDIR systemd "systemdsystemunitdir")
37
38+set(SYSTEMD_UNITDIR ${PC_SYSTEMD_UNITDIR})
39 set(JOURNALD_FOUND ${PC_JOURNALD_FOUND})
40 set(JOURNALD_DEFINITIONS ${PC_JOURNALD_CFLAGS_OTHER})
41
42diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
43index 522bbf9bd..30743d8d6 100644
44--- a/src/CMakeLists.txt
45+++ b/src/CMakeLists.txt
46@@ -480,13 +480,13 @@ if(FLB_BINARY)
47 endif()
48
49 # Detect init system, install upstart, systemd or init.d script
50- if(IS_DIRECTORY /lib/systemd/system)
51+ if(DEFINED SYSTEMD_UNITDIR)
52 set(FLB_SYSTEMD_SCRIPT "${PROJECT_SOURCE_DIR}/init/${FLB_OUT_NAME}.service")
53 configure_file(
54 "${PROJECT_SOURCE_DIR}/init/systemd.in"
55 ${FLB_SYSTEMD_SCRIPT}
56 )
57- install(FILES ${FLB_SYSTEMD_SCRIPT} COMPONENT binary DESTINATION /lib/systemd/system)
58+ install(FILES ${FLB_SYSTEMD_SCRIPT} COMPONENT binary DESTINATION ${SYSTEMD_UNITDIR})
59 install(DIRECTORY DESTINATION ${FLB_INSTALL_CONFDIR} COMPONENT binary)
60 elseif(IS_DIRECTORY /usr/share/upstart)
61 set(FLB_UPSTART_SCRIPT "${PROJECT_SOURCE_DIR}/init/${FLB_OUT_NAME}.conf")
62--
632.25.1
64