From 35bffd0f259d2e3fbdaaac1553ac1201936c0e7d Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Sat, 3 Sep 2022 21:54:06 +0100 Subject: [PATCH] build: don't include libsystemd as shared pkg-config dep when statically linked (#283) This works whether `BUILD_LIBSYSTEMD` is `ON` or the separate build of libsystemd picked up by pkg-config is static. The Gentoo Linux package requires the latter. This change also handles `BUILD_SHARED_LIBS` being `OFF`. In this case, the libsystemd dependency does need to be included, even though it is static. CMake does not allow you to build shared and static libraries simultaneously (with a single `add_library` call), but this change declares the libsystemd dependency as `Requires.private` rather than omitting it entirely. This is in case someone builds and installs both a static and shared build and then calls `pkg-config --static sdbus-c++`. The static build needs to be installed first so that the pkg-config file from the shared build takes precedence. --- CMakeLists.txt | 5 +++++ pkgconfig/sdbus-c++.pc.in | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0733b41..c5a8a03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -210,6 +210,11 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/sdbus-c++-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/sdbus-c++ COMPONENT dev) +if(BUILD_SHARED_LIBS AND (BUILD_LIBSYSTEMD OR Systemd_LINK_LIBRARIES MATCHES "/libsystemd\.a(;|$)")) + set(PKGCONFIG_REQS ".private") +else() + set(PKGCONFIG_REQS "") +endif() configure_file(pkgconfig/sdbus-c++.pc.in pkgconfig/sdbus-c++.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/sdbus-c++.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT dev) diff --git a/pkgconfig/sdbus-c++.pc.in b/pkgconfig/sdbus-c++.pc.in index 21e0f0b..6ad010a 100644 --- a/pkgconfig/sdbus-c++.pc.in +++ b/pkgconfig/sdbus-c++.pc.in @@ -5,7 +5,7 @@ includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ Name: @PROJECT_NAME@ Description: C++ library on top of sd-bus, a systemd D-Bus library -Requires: libsystemd +Requires@PKGCONFIG_REQS@: libsystemd Version: @SDBUSCPP_VERSION@ Libs: -L${libdir} -l@PROJECT_NAME@ Cflags: -I${includedir}