From 1f151d81381106c15084280f1e11209d259ae45c Mon Sep 17 00:00:00 2001
From: John Zimmermann <me@johnnynator.dev>
Date: Sat, 19 Jun 2021 15:47:56 +0200
Subject: [PATCH] Change installed .cmake and .pc files to contain realtive
 paths

The LIB_DESTINATION and INCLUDE_DESTIONATION variables do hold little
value, since one can just override the normal CMAKE variables as needed.
Furthermore using CMAKE_INSTALL_FULL_LIBDIR is harmful, since this
prevents CMake to use it's logic to install relocatable .cmake files.
Also libdir and includedir in pkgconfig files need to be prefixed by
either ${exec_prefix} or ${prefix} for the same relocation reasons.
---
 CMakeLists.txt              | 27 +++++++++++----------------
 PolkitQt-1Config.cmake.in   |  4 ++--
 agent/CMakeLists.txt        |  6 +++---
 core/CMakeLists.txt         |  6 +++---
 gui/CMakeLists.txt          |  6 +++---
 polkit-qt-1.pc.cmake        |  4 ++--
 polkit-qt-agent-1.pc.cmake  |  4 ++--
 polkit-qt-core-1.pc.cmake   |  4 ++--
 polkit-qt-gui-1.pc.cmake    |  4 ++--
 polkit-qt5-1.pc.cmake       |  4 ++--
 polkit-qt5-agent-1.pc.cmake |  4 ++--
 polkit-qt5-core-1.pc.cmake  |  4 ++--
 polkit-qt5-gui-1.pc.cmake   |  4 ++--
 13 files changed, 38 insertions(+), 43 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 32eb737..a82f8cb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,11 +21,6 @@ include(GNUInstallDirs)

 include(FeatureSummary)

-# Set the different paths
-set(LIB_DESTINATION         "${CMAKE_INSTALL_FULL_LIBDIR}" CACHE PATH "Library directory name")
-set(INCLUDE_DESTINATION     "${CMAKE_INSTALL_FULL_INCLUDEDIR}" CACHE PATH "The subdirectory to the header prefix")
-
-
 set(REQUIRED_QT_VERSION 5.5.0)
 set(CMAKE_CXX_STANDARD 11)

@@ -103,7 +98,7 @@ install(FILES
     ${CMAKE_CURRENT_BINARY_DIR}/agent/polkitqt1-agent-export.h

     DESTINATION
-    ${INCLUDE_DESTINATION}/${POLKITQT-1_INCLUDE_PATH} COMPONENT Devel)
+    ${CMAKE_INSTALL_INCLUDEDIR}/${POLKITQT-1_INCLUDE_PATH} COMPONENT Devel)

 install(FILES
     includes/PolkitQt1/Authority
@@ -113,40 +108,40 @@ install(FILES
     includes/PolkitQt1/TemporaryAuthorization
     includes/PolkitQt1/ActionDescription
     DESTINATION
-    ${INCLUDE_DESTINATION}/${POLKITQT-1_INCLUDE_PATH}/PolkitQt1 COMPONENT Devel)
+    ${CMAKE_INSTALL_INCLUDEDIR}/${POLKITQT-1_INCLUDE_PATH}/PolkitQt1 COMPONENT Devel)

 install(FILES
     includes/PolkitQt1/Gui/Action
     includes/PolkitQt1/Gui/ActionButton
     includes/PolkitQt1/Gui/ActionButtons
     DESTINATION
-    ${INCLUDE_DESTINATION}/${POLKITQT-1_INCLUDE_PATH}/PolkitQt1/Gui COMPONENT Devel)
+    ${CMAKE_INSTALL_INCLUDEDIR}/${POLKITQT-1_INCLUDE_PATH}/PolkitQt1/Gui COMPONENT Devel)

 install(FILES
     includes/PolkitQt1/Agent/Listener
     includes/PolkitQt1/Agent/Session
     DESTINATION
-    ${INCLUDE_DESTINATION}/${POLKITQT-1_INCLUDE_PATH}/PolkitQt1/Agent COMPONENT Devel)
+    ${CMAKE_INSTALL_INCLUDEDIR}/${POLKITQT-1_INCLUDE_PATH}/PolkitQt1/Agent COMPONENT Devel)

 if(NOT WIN32)
     # Pkgconfig
     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${POLKITQT-1_PCNAME}.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/${POLKITQT-1_PCNAME}.pc @ONLY)
-    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${POLKITQT-1_PCNAME}.pc DESTINATION ${LIB_DESTINATION}/pkgconfig )
+    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${POLKITQT-1_PCNAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${POLKITQT-1_CORE_PCNAME}.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/${POLKITQT-1_CORE_PCNAME}.pc
                    @ONLY)
-    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${POLKITQT-1_CORE_PCNAME}.pc DESTINATION ${LIB_DESTINATION}/pkgconfig )
+    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${POLKITQT-1_CORE_PCNAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${POLKITQT-1_GUI_PCNAME}.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/${POLKITQT-1_GUI_PCNAME}.pc @ONLY)
-    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${POLKITQT-1_GUI_PCNAME}.pc DESTINATION ${LIB_DESTINATION}/pkgconfig )
+    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${POLKITQT-1_GUI_PCNAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${POLKITQT-1_AGENT_PCNAME}.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/${POLKITQT-1_AGENT_PCNAME}.pc
                    @ONLY)
-    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${POLKITQT-1_AGENT_PCNAME}.pc DESTINATION ${LIB_DESTINATION}/pkgconfig )
+    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${POLKITQT-1_AGENT_PCNAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
 endif(NOT WIN32)


 if(USE_COMMON_CMAKE_PACKAGE_CONFIG_DIR)
-   set(_PolkitQt-1Config_INSTALL_DIR ${LIB_DESTINATION}/cmake/${POLKITQT-1_CAMEL_NAME})
+   set(_PolkitQt-1Config_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${POLKITQT-1_CAMEL_NAME})
 else(USE_COMMON_CMAKE_PACKAGE_CONFIG_DIR)
-   set(_PolkitQt-1Config_INSTALL_DIR ${LIB_DESTINATION}/${POLKITQT-1_CAMEL_NAME}/cmake)
+   set(_PolkitQt-1Config_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/${POLKITQT-1_CAMEL_NAME}/cmake)
 endif(USE_COMMON_CMAKE_PACKAGE_CONFIG_DIR)


@@ -154,7 +149,7 @@ endif(USE_COMMON_CMAKE_PACKAGE_CONFIG_DIR)
 configure_package_config_file(PolkitQt-1Config.cmake.in
                               ${CMAKE_BINARY_DIR}/${POLKITQT-1_CAMEL_NAME}Config.cmake
                               INSTALL_DESTINATION ${_PolkitQt-1Config_INSTALL_DIR}
-                              PATH_VARS LIB_DESTINATION INCLUDE_DESTINATION
+                              PATH_VARS CMAKE_INSTALL_LIBDIR CMAKE_INSTALL_INCLUDEDIR
 )

 write_basic_package_version_file(${CMAKE_BINARY_DIR}/${POLKITQT-1_CAMEL_NAME}ConfigVersion.cmake
diff --git a/PolkitQt-1Config.cmake.in b/PolkitQt-1Config.cmake.in
index f39480c..e09678c 100644
--- a/PolkitQt-1Config.cmake.in
+++ b/PolkitQt-1Config.cmake.in
@@ -20,9 +20,9 @@ if(NOT POLKITQT-1_INSTALL_DIR)
    set(POLKITQT-1_INSTALL_DIR "@CMAKE_INSTALL_PREFIX@")
 endif(NOT POLKITQT-1_INSTALL_DIR)

-set_and_check(POLKITQT-1_INCLUDE_DIR "@PACKAGE_INCLUDE_DESTINATION@/@POLKITQT-1_INCLUDE_PATH@")
+set_and_check(POLKITQT-1_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@")
 set_and_check(POLKITQT-1_INCLUDE_DIRS "${POLKITQT-1_INCLUDE_DIR}")
-set_and_check(POLKITQT-1_LIB_DIR "@PACKAGE_LIB_DESTINATION@")
+set_and_check(POLKITQT-1_LIB_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@")
 set(POLKITQT-1_POLICY_FILES_INSTALL_DIR "${POLKITQT-1_INSTALL_DIR}/share/polkit-1/actions")
 ##################################

diff --git a/agent/CMakeLists.txt b/agent/CMakeLists.txt
index ccf2711..1a86cd8 100644
--- a/agent/CMakeLists.txt
+++ b/agent/CMakeLists.txt
@@ -29,11 +29,11 @@ set_target_properties(${POLKITQT-1_AGENT_PCNAME} PROPERTIES VERSION ${POLKITQT-1

 target_include_directories(${POLKITQT-1_AGENT_PCNAME}
     INTERFACE
-        $<INSTALL_INTERFACE:${INCLUDE_DESTINATION}/${POLKITQT-1_INCLUDE_PATH}>
+        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${POLKITQT-1_INCLUDE_PATH}>
         $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
         $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
 )

-install(TARGETS ${POLKITQT-1_AGENT_PCNAME} EXPORT ${POLKITQT-1_CAMEL_NAME}Export ARCHIVE DESTINATION ${LIB_DESTINATION}
-                               LIBRARY DESTINATION ${LIB_DESTINATION}
+install(TARGETS ${POLKITQT-1_AGENT_PCNAME} EXPORT ${POLKITQT-1_CAMEL_NAME}Export ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+                               LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
                                RUNTIME DESTINATION bin)
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 3a80adc..8225871 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -32,12 +32,12 @@ set_target_properties(${POLKITQT-1_CORE_PCNAME} PROPERTIES VERSION ${POLKITQT-1_

 target_include_directories(${POLKITQT-1_CORE_PCNAME}
     INTERFACE
-        $<INSTALL_INTERFACE:${INCLUDE_DESTINATION}/${POLKITQT-1_INCLUDE_PATH}>
+        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${POLKITQT-1_INCLUDE_PATH}>
         $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
         $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
 )

-install(TARGETS ${POLKITQT-1_CORE_PCNAME} EXPORT ${POLKITQT-1_CAMEL_NAME}Export ARCHIVE DESTINATION ${LIB_DESTINATION}
-                               LIBRARY DESTINATION ${LIB_DESTINATION}
+install(TARGETS ${POLKITQT-1_CORE_PCNAME} EXPORT ${POLKITQT-1_CAMEL_NAME}Export ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+                               LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
                                RUNTIME DESTINATION bin)

diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt
index d9d800d..c22deba 100644
--- a/gui/CMakeLists.txt
+++ b/gui/CMakeLists.txt
@@ -28,11 +28,11 @@ set_target_properties(${POLKITQT-1_GUI_PCNAME} PROPERTIES VERSION ${POLKITQT-1_L

 target_include_directories(${POLKITQT-1_GUI_PCNAME}
     INTERFACE
-        $<INSTALL_INTERFACE:${INCLUDE_DESTINATION}/${POLKITQT-1_INCLUDE_PATH}>
+        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${POLKITQT-1_INCLUDE_PATH}>
         $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
         $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
 )

-install(TARGETS ${POLKITQT-1_GUI_PCNAME} EXPORT ${POLKITQT-1_CAMEL_NAME}Export ARCHIVE DESTINATION ${LIB_DESTINATION}
-                               LIBRARY DESTINATION ${LIB_DESTINATION}
+install(TARGETS ${POLKITQT-1_GUI_PCNAME} EXPORT ${POLKITQT-1_CAMEL_NAME}Export ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+                               LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
                                RUNTIME DESTINATION bin)
diff --git a/polkit-qt-1.pc.cmake b/polkit-qt-1.pc.cmake
index 7cc55a9..ba8e46e 100644
--- a/polkit-qt-1.pc.cmake
+++ b/polkit-qt-1.pc.cmake
@@ -1,7 +1,7 @@
 prefix=@CMAKE_INSTALL_PREFIX@
 exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=@LIB_DESTINATION@
-includedir=@INCLUDE_DESTINATION@/@POLKITQT-1_INCLUDE_PATH@
+libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@

 Name: @POLKITQT-1_PCNAME@
 Description: Convenience library for using polkit with a Qt-styled API
diff --git a/polkit-qt-agent-1.pc.cmake b/polkit-qt-agent-1.pc.cmake
index 001925d..23b2cae 100644
--- a/polkit-qt-agent-1.pc.cmake
+++ b/polkit-qt-agent-1.pc.cmake
@@ -1,7 +1,7 @@
 prefix=@CMAKE_INSTALL_PREFIX@
 exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=@LIB_DESTINATION@
-includedir=@INCLUDE_DESTINATION@/@POLKITQT-1_INCLUDE_PATH@
+libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@

 Name: @POLKITQT-1_AGENT_PCNAME@
 Description: Convenience library for using polkit Agent with a Qt-styled API
diff --git a/polkit-qt-core-1.pc.cmake b/polkit-qt-core-1.pc.cmake
index ca435a6..fa501f0 100644
--- a/polkit-qt-core-1.pc.cmake
+++ b/polkit-qt-core-1.pc.cmake
@@ -1,7 +1,7 @@
 prefix=@CMAKE_INSTALL_PREFIX@
 exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=@LIB_DESTINATION@
-includedir=@INCLUDE_DESTINATION@/@POLKITQT-1_INCLUDE_PATH@
+libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@

 Name: @POLKITQT-1_CORE_PCNAME@
 Description: Convenience library for using polkit with a Qt-styled API, non-GUI classes
diff --git a/polkit-qt-gui-1.pc.cmake b/polkit-qt-gui-1.pc.cmake
index e7279d1..7261b0c 100644
--- a/polkit-qt-gui-1.pc.cmake
+++ b/polkit-qt-gui-1.pc.cmake
@@ -1,7 +1,7 @@
 prefix=@CMAKE_INSTALL_PREFIX@
 exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=@LIB_DESTINATION@
-includedir=@INCLUDE_DESTINATION@/@POLKITQT-1_INCLUDE_PATH@
+libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@

 Name: @POLKITQT-1_GUI_PCNAME@
 Description: Convenience library for using polkit with a Qt-styled API, GUI classes
diff --git a/polkit-qt5-1.pc.cmake b/polkit-qt5-1.pc.cmake
index 7cc55a9..ba8e46e 100644
--- a/polkit-qt5-1.pc.cmake
+++ b/polkit-qt5-1.pc.cmake
@@ -1,7 +1,7 @@
 prefix=@CMAKE_INSTALL_PREFIX@
 exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=@LIB_DESTINATION@
-includedir=@INCLUDE_DESTINATION@/@POLKITQT-1_INCLUDE_PATH@
+libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@

 Name: @POLKITQT-1_PCNAME@
 Description: Convenience library for using polkit with a Qt-styled API
diff --git a/polkit-qt5-agent-1.pc.cmake b/polkit-qt5-agent-1.pc.cmake
index fabc0db..709a24e 100644
--- a/polkit-qt5-agent-1.pc.cmake
+++ b/polkit-qt5-agent-1.pc.cmake
@@ -1,7 +1,7 @@
 prefix=@CMAKE_INSTALL_PREFIX@
 exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=@LIB_DESTINATION@
-includedir=@INCLUDE_DESTINATION@/@POLKITQT-1_INCLUDE_PATH@
+libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@

 Name: @POLKITQT-1_AGENT_PCNAME@
 Description: Convenience library for using polkit Agent with a Qt-styled API
diff --git a/polkit-qt5-core-1.pc.cmake b/polkit-qt5-core-1.pc.cmake
index 33687c2..588f267 100644
--- a/polkit-qt5-core-1.pc.cmake
+++ b/polkit-qt5-core-1.pc.cmake
@@ -1,7 +1,7 @@
 prefix=@CMAKE_INSTALL_PREFIX@
 exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=@LIB_DESTINATION@
-includedir=@INCLUDE_DESTINATION@/@POLKITQT-1_INCLUDE_PATH@
+libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@

 Name: @POLKITQT-1_CORE_PCNAME@
 Description: Convenience library for using polkit with a Qt-styled API, non-GUI classes
diff --git a/polkit-qt5-gui-1.pc.cmake b/polkit-qt5-gui-1.pc.cmake
index 4280226..1c012dd 100644
--- a/polkit-qt5-gui-1.pc.cmake
+++ b/polkit-qt5-gui-1.pc.cmake
@@ -1,7 +1,7 @@
 prefix=@CMAKE_INSTALL_PREFIX@
 exec_prefix=@CMAKE_INSTALL_PREFIX@
-libdir=@LIB_DESTINATION@
-includedir=@INCLUDE_DESTINATION@/@POLKITQT-1_INCLUDE_PATH@
+libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@POLKITQT-1_INCLUDE_PATH@

 Name: @POLKITQT-1_GUI_PCNAME@
 Description: Convenience library for using polkit with a Qt-styled API, GUI classes
--
GitLab

