From e5707b8f3fda72dffd383630362088864a26b911 Mon Sep 17 00:00:00 2001 From: Bart Ribbers Date: Tue, 31 Mar 2020 12:52:50 +0200 Subject: [PATCH] Fix linking to systemd when elogind is used instead This is mainly useful for non-glibc systems. Yes, systemd doesn't even run on non-glibc systems, but elogind does and this way it links to both systemd and elogind. However due to switching the way we link to systemd, we now also make sure systemd is actually installed on the system before we even try to compile, thus preventing compiler errors when systemd isn't present. --- src/launcherlib/CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/launcherlib/CMakeLists.txt b/src/launcherlib/CMakeLists.txt index 2e32d69..2c9fb4d 100644 --- a/src/launcherlib/CMakeLists.txt +++ b/src/launcherlib/CMakeLists.txt @@ -2,7 +2,12 @@ include(GNUInstallDirs) set(COMMON ${CMAKE_HOME_DIRECTORY}/src/common) -include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${COMMON}) +# Find systemd +find_package(PkgConfig REQUIRED) +pkg_check_modules(SYSTEMD "libsystemd" REQUIRED) + +# Set include dirs +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${SYSTEMD_INCLUDE_DIRS} ${COMMON}) # Hide all symbols except the ones explicitly exported in the code (like main()) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") @@ -16,12 +21,15 @@ set(HEADERS appdata.h booster.h connection.h daemon.h logger.h launcherlib.h # Set libraries to be linked. Shared libraries to be preloaded are not linked in anymore, # but dlopen():ed and listed in src/launcher/preload.h instead. -link_libraries(${LIBDL} "-L/lib -lsystemd -lcap") +link_libraries(${LIBDL} "-L/lib -lcap") # Set executable add_library(applauncherd MODULE ${SRC} ${MOC_SRC}) set_target_properties(applauncherd PROPERTIES VERSION 0.1 SOVERSION 0) +target_link_libraries(applauncherd ${SYSTEMD_LIBRARIES}) + + # Add install rule install(TARGETS applauncherd DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}) install(FILES ${HEADERS} DESTINATION /usr/include/applauncherd