From 7c8086b2a6939560b5639f658c331cb82dc70539 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Wed, 15 Feb 2017 16:02:32 +0100 Subject: [PATCH] cmake, autotools: create relocatable dbus-1.pc file Relocatable pkgconfig files are required to use installed packages from a non standard location. For simplicity, we're not relocatable if libdir (autotools) or CMAKE_INSTALL_LIBDIR (cmake) is something more complicated (e.g. Debian multiarch); we don't want to have to compute how many ../ to add. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99721 --- cmake/CMakeLists.txt | 32 +++++++++++++++++++++++++------- configure.ac | 6 ++++++ dbus-1.pc.in | 2 +- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 5eb9ed3..bc3d7a1 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -84,6 +84,17 @@ set(SYSCONFDIR_FROM_PKGDATADIR ${CMAKE_INSTALL_FULL_SYSCONFDIR}) set(DATADIR_FROM_PKGSYSCONFDIR ${CMAKE_INSTALL_FULL_DATADIR}) endif() +# For simplicity, we're not relocatable if CMAKE_INSTALL_LIBDIR +# is something more complicated (e.g. Debian multiarch); +# we don't want to have to compute how many ../ to add +if(CMAKE_INSTALL_LIBDIR STREQUAL "lib" OR CMAKE_INSTALL_LIBDIR STREQUAL "lib64") + # we know we can use ../ to get to the prefix + set(DBUS_RELOCATABLE_LIBDIR 1) +else() + # sorry, it's too hard to make this particular build relocatable + set(DBUS_RELOCATABLE_LIBDIR 0) +endif() + # used in the C code set(DBUS_LIBEXECDIR ${CMAKE_INSTALL_FULL_LIBEXECDIR}) set(DBUS_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}) @@ -638,13 +649,20 @@ if(UNIX) foreach(LIB ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS}) set(LIBDBUS_LIBS "${LIBDBUS_LIBS} -l${LIB}") endforeach() - set(bindir ${EXPANDED_BINDIR}) - set(libdir ${EXPANDED_LIBDIR}) - set(includedir ${EXPANDED_INCLUDEDIR}) - set(sysconfdir ${EXPANDED_SYSCONFDIR}) - set(datadir ${EXPANDED_DATADIR}) - set(datarootdir ${EXPANDED_DATADIR}) - set(dbus_daemondir ${DBUS_DAEMONDIR}) + if(DBUS_RELOCATABLE_LIBDIR) + set(pkgconfig_prefix "\${pcfiledir}/../../") + else() + message("Unusual CMAKE_INSTALL_PREFIX: the generated package will not be relocatable.") + set(pkgconfig_prefix "${CMAKE_INSTALL_PREFIX}") + endif() + set(exec_prefix "\${prefix}") + set(bindir "\${prefix}/${CMAKE_INSTALL_BINDIR}") + set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") + set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") + set(sysconfdir "\${prefix}/${CMAKE_INSTALL_SYSCONFDIR}") + set(datadir "\${prefix}/${CMAKE_INSTALL_DATADIR}") + set(datarootdir "\${prefix}/${CMAKE_INSTALL_DATADIR}") + set(dbus_daemondir "\${prefix}/${CMAKE_INSTALL_BINDIR}") configure_file(../dbus-1.pc.in ${CMAKE_BINARY_DIR}/dbus-1.pc @ONLY) install(FILES ${CMAKE_BINARY_DIR}/dbus-1.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endif() diff --git a/configure.ac b/configure.ac index c7c762e..7e3310c 100644 --- a/configure.ac +++ b/configure.ac @@ -1530,6 +1530,12 @@ AS_AC_EXPAND(EXPANDED_LIBDIR, "$libdir") AS_AC_EXPAND(EXPANDED_LIBEXECDIR, "$libexecdir") AS_AC_EXPAND(EXPANDED_DATADIR, "$datadir") +AS_IF([test "x$EXPANDED_LIBDIR" = "x$EXPANDED_PREFIX/lib" || + test "x$EXPANDED_LIBDIR" = "x$EXPANDED_PREFIX/lib64"], + [pkgconfig_prefix='${pcfiledir}/../..'], + [pkgconfig_prefix="$prefix"]) +AC_SUBST([pkgconfig_prefix]) + #### Check our operating system operating_system=unknown if test -f /etc/redhat-release || test -f $EXPANDED_SYSCONFDIR/redhat-release ; then diff --git a/dbus-1.pc.in b/dbus-1.pc.in index f93d156..26fc970 100644 --- a/dbus-1.pc.in +++ b/dbus-1.pc.in @@ -1,4 +1,4 @@ -prefix=@prefix@ +prefix=@pkgconfig_prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ libdir=@libdir@ -- 1.8.4.5