Add find module for systemd

This commit is contained in:
Johannes Schmidt 2026-07-09 09:13:25 +02:00
parent 75839457ca
commit 674524441b
5 changed files with 42 additions and 11 deletions

View file

@ -42,8 +42,6 @@ option(ICINGA2_WITH_OPENTELEMETRY "Build the OpenTelemetry integration module" $
option (USE_SYSTEMD
"Configure icinga as native systemd service instead of a SysV initscript" OFF)
set(HAVE_SYSTEMD ${USE_SYSTEMD})
include(GNUInstallDirs)
include(InstallConfig)
include(SetFullDir)
@ -234,8 +232,11 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/lib
)
if(HAVE_SYSTEMD)
list(APPEND base_DEPS systemd)
if(USE_SYSTEMD)
find_package(Systemd REQUIRED)
list(APPEND base_DEPS Systemd)
include_directories(SYSTEM ${Systemd_INCLUDE_DIRS})
add_compile_definitions(HAVE_SYSTEMD)
endif()
if(EDITLINE_FOUND)

35
cmake/FindSystemd.cmake Normal file
View file

@ -0,0 +1,35 @@
# SPDX-FileCopyrightText: 2026 Icinga GmbH <https://icinga.com>
# SPDX-License-Identifier: GPL-2.0-or-later
find_path(Systemd_INCLUDE_DIRS
NAMES
systemd/sd-daemon.h
HINTS ${SYSTEMD_ROOT_DIR}
)
find_library(Systemd_LIBRARIES
NAMES systemd
HINTS ${SYSTEMD_LIBRARY_DIR}
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Systemd
REQUIRED_VARS Systemd_LIBRARIES Systemd_INCLUDE_DIRS
)
if(Systemd_FOUND)
message(STATUS "Systemd_LIBRARIES: ${Systemd_LIBRARIES}")
message(STATUS "Systemd_INCLUDE_DIRS: ${Systemd_INCLUDE_DIRS}")
add_library(Systemd UNKNOWN IMPORTED)
set_target_properties(Systemd PROPERTIES
IMPORTED_LOCATION "${Systemd_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${Systemd_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "HAVE_SYSTEMD"
INTERFACE_LINK_LIBRARIES "${Systemd_LIBRARIES}"
)
else()
set(SYSTEMD_LIBRARIES)
set(SYSTEMD_INCLUDE_DIRS)
endif()
mark_as_advanced(Systemd_LIBRARIES Systemd_INCLUDE_DIRS)

View file

@ -13,7 +13,6 @@
#cmakedefine HAVE_PTHREAD_SET_NAME_NP
#cmakedefine HAVE_PTHREAD_SETNAME_NP
#cmakedefine HAVE_EDITLINE
#cmakedefine HAVE_SYSTEMD
#cmakedefine ICINGA2_UNITY_BUILD
#cmakedefine ICINGA2_STACKTRACE_USE_BACKTRACE_SYMBOLS

View file

@ -40,7 +40,7 @@ install_if_not_exists(icinga2/features-available/debuglog.conf ${ICINGA2_CONFIGD
install_if_not_exists(icinga2/features-available/mainlog.conf ${ICINGA2_CONFIGDIR}/features-available)
if(NOT WIN32)
install_if_not_exists(icinga2/features-available/syslog.conf ${ICINGA2_CONFIGDIR}/features-available)
if(HAVE_SYSTEMD)
if(USE_SYSTEMD)
install_if_not_exists(icinga2/features-available/journald.conf ${ICINGA2_CONFIGDIR}/features-available)
endif()
else()

View file

@ -133,11 +133,7 @@ if(ICINGA2_UNITY_BUILD)
mkunity_target(base base base_SOURCES)
endif()
if(HAVE_SYSTEMD)
find_path(SYSTEMD_INCLUDE_DIR
NAMES systemd/sd-daemon.h
HINTS ${SYSTEMD_ROOT_DIR})
include_directories(SYSTEM ${SYSTEMD_INCLUDE_DIR})
if(USE_SYSTEMD)
set_property(
SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/journaldlogger.cpp
APPEND PROPERTY COMPILE_DEFINITIONS