From 50c5f0e772da02713dc3aa9abbc2ed90c833522c Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Wed, 15 Feb 2017 16:02:32 +0100 Subject: [PATCH 1/3] cmake: Optionally create relocatable dbus-1.pc file Relocatable pkgconfig files are necessary when using packages installed to a location that does not match the location for which they were compiled. However, using ${pcfiledir} is problematic for system installations in standard locations, because it interferes with pkg-config's ability to filter out -I, -L options that are redundant with compiler defaults (which is important if you are trying to use a newer version of a library than the system copy). In practice operating system vendors installing dbus to standard locations use Autotools, so we enable relocatable builds by default when building with CMake. For simplicity, we're also not relocatable if the library directory is something more complicated than lib or lib64 (e.g. under Debian multiarch); we don't want to have to compute how many ../ to add. This is non-trivial to determine in an Autotools build, so for now there is no support for relocation when built with Autotools, even as an opt-in feature. Going via the ${original_prefix} variable is because under Autotools, both ${prefix} and ${exec_prefix} technically default to NONE, with NONE replaced with their real defaults of /usr/local and '${prefix}' (respectively) later on. If we tried to expand ${prefix} at the time that we choose the value of ${pkgconfig_prefix}, that would cause a broken value "prefix=NONE" to be hard-coded. [smcv: no relocation on Autotools, make it optional in CMake, expand commit message] Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99721 --- cmake/CMakeLists.txt | 34 +++++++++++++++++++++++++++------- configure.ac | 3 +++ dbus-1.pc.in | 3 ++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 5eb9ed3a..b62ee656 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -84,6 +84,19 @@ set(SYSCONFDIR_FROM_PKGDATADIR ${CMAKE_INSTALL_FULL_SYSCONFDIR}) set(DATADIR_FROM_PKGSYSCONFDIR ${CMAKE_INSTALL_FULL_DATADIR}) endif() +option (DBUS_RELOCATABLE "Attempt to make metadata relocatable" ON) + +# 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. Do nothing. +elseif(DBUS_RELOCATABLE) + # Sorry, it's too hard to make this particular build relocatable + message("Unusual CMAKE_INSTALL_LIBDIR: the generated package will not be relocatable.") + set(DBUS_RELOCATABLE OFF) +endif() + # used in the C code set(DBUS_LIBEXECDIR ${CMAKE_INSTALL_FULL_LIBEXECDIR}) set(DBUS_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}) @@ -638,13 +651,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}) + set(original_prefix "${CMAKE_INSTALL_PREFIX}") + if(DBUS_RELOCATABLE) + set(pkgconfig_prefix "\${pcfiledir}/../../") + else() + set(pkgconfig_prefix "\${original_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 00c271cb..b0afc947 100644 --- a/configure.ac +++ b/configure.ac @@ -1530,6 +1530,9 @@ AS_AC_EXPAND(EXPANDED_LIBDIR, "$libdir") AS_AC_EXPAND(EXPANDED_LIBEXECDIR, "$libexecdir") AS_AC_EXPAND(EXPANDED_DATADIR, "$datadir") +# For the moment we don't support relocation when building with Autotools +AC_SUBST([pkgconfig_prefix], ['${original_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 f93d1563..3581be6e 100644 --- a/dbus-1.pc.in +++ b/dbus-1.pc.in @@ -1,4 +1,5 @@ -prefix=@prefix@ +original_prefix=@prefix@ +prefix=@pkgconfig_prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ libdir=@libdir@ -- 2.11.0