NetdataDetectSystemd.cmake 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # CMake Module to handle all the systemd-related checks for Netdata.
  2. #
  3. # Copyright (c) 2024 Netdata Inc.
  4. # SPDX-License-Identifier: GPL-3.0-or-later
  5. macro(detect_systemd)
  6. find_library(SYSTEMD_LIBRARY NAMES systemd)
  7. set(ENABLE_DSYSTEMD_DBUS NO)
  8. pkg_check_modules(SYSTEMD libsystemd)
  9. if(SYSTEMD_FOUND)
  10. set(CMAKE_REQUIRED_LIBRARIES_BEFORE_SYSTEMD "${CMAKE_REQUIRED_LIBRARIES}")
  11. set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};${SYSTEMD_LIBRARIES}")
  12. check_c_source_compiles("
  13. #include <systemd/sd-journal.h>
  14. int main() {
  15. int x = SD_JOURNAL_OS_ROOT;
  16. return 0;
  17. }" HAVE_SD_JOURNAL_OS_ROOT)
  18. check_symbol_exists(SD_JOURNAL_OS_ROOT "systemd/sd-journal.h" HAVE_SD_JOURNAL_OS_ROOT)
  19. check_symbol_exists(sd_journal_open_files_fd "systemd/sd-journal.h" HAVE_SD_JOURNAL_OPEN_FILES_FD)
  20. check_symbol_exists(sd_journal_restart_fields "systemd/sd-journal.h" HAVE_SD_JOURNAL_RESTART_FIELDS)
  21. check_symbol_exists(sd_journal_get_seqnum "systemd/sd-journal.h" HAVE_SD_JOURNAL_GET_SEQNUM)
  22. check_symbol_exists(sd_bus_default_system "systemd/sd-bus.h" HAVE_SD_BUS_DEFAULT_SYSTEM)
  23. check_symbol_exists(sd_bus_call_method "systemd/sd-bus.h" HAVE_SD_BUS_CALL_METHOD)
  24. check_symbol_exists(sd_bus_message_enter_container "systemd/sd-bus.h" HAVE_SD_BUS_MESSAGE_ENTER_CONTAINER)
  25. check_symbol_exists(sd_bus_message_read "systemd/sd-bus.h" HAVE_SD_BUS_MESSAGE_READ)
  26. check_symbol_exists(sd_bus_message_exit_container "systemd/sd-bus.h" HAVE_SD_BUS_MESSAGE_EXIT_CONTAINER)
  27. set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_BEFORE_SYSTEMD}")
  28. set(HAVE_SYSTEMD True)
  29. if(HAVE_SD_BUS_DEFAULT_SYSTEM AND HAVE_SD_BUS_CALL_METHOD AND HAVE_SD_BUS_MESSAGE_ENTER_CONTAINER AND HAVE_SD_BUS_MESSAGE_READ AND HAVE_SD_BUS_MESSAGE_EXIT_CONTAINER)
  30. set(ENABLE_SYSTEMD_DBUS YES)
  31. endif()
  32. endif()
  33. endmacro()