From 02c781a35a844f0ef4434268fb0d7f9ea2d3f130 Mon Sep 17 00:00:00 2001
From: Andreas Sturmlechner <asturm@gentoo.org>
Date: Thu, 26 Mar 2020 13:07:37 +0100
Subject: [PATCH] Use GNUInstallDirs

Fix cmake module install path while at it.
Fix pkgconfig libdir path while at it.
---
 CMakeLists.txt          | 15 +++++++--------
 RinutilsConfig.cmake.in |  2 +-
 librinutils.pc.in       |  4 ++--
 3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9829c49..753a138 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,6 +9,7 @@ option (WITH_TEST_SUITE "Also build and run the test suite." ON)
 option (DISABLE_APPLYING_RPATH "Disable applying rpath")
 
 INCLUDE(FindPkgConfig)
+INCLUDE(GNUInstallDirs)
 
 # Introduces VERSION , CPACK_PACKAGE_VERSION_MAJOR,
 # CPACK_PACKAGE_VERSION_MAJOR, and CPACK_PACKAGE_VERSION_PATCH
@@ -54,7 +55,7 @@ IF (NOT DISABLE_APPLYING_RPATH)
     SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
 
     # the RPATH to be used when installing
-    SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
+    SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}")
 
     # add the automatically determined parts of the RPATH
     # which point to directories outside the build tree to the install RPATH
@@ -99,14 +100,14 @@ INSTALL(
         "rinutils/include/rinutils/typeof_wrap.h"
         "rinutils/include/rinutils/unused.h"
     DESTINATION
-        "include/rinutils"
+        "${CMAKE_INSTALL_INCLUDEDIR}/rinutils"
 )
 
 INSTALL(
     FILES
         "${CMAKE_CURRENT_BINARY_DIR}/lib${CPACK_PACKAGE_NAME}.pc"
     DESTINATION
-        "lib${LIB_SUFFIX}/pkgconfig"
+        "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
 )
 
 CONFIGURE_FILE(
@@ -128,20 +129,18 @@ ADD_CUSTOM_COMMAND(
     ARGS "config.h.in"
 )
 
-set(INCLUDE_INSTALL_DIR include)
-set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
 include(CMakePackageConfigHelpers)
 configure_package_config_file(RinutilsConfig.cmake.in
   ${CMAKE_CURRENT_BINARY_DIR}/RinutilsConfig.cmake
-  INSTALL_DESTINATION ${LIB_INSTALL_DIR}/Rinutils/cmake
-  PATH_VARS INCLUDE_INSTALL_DIR)
+  INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Rinutils
+  PATH_VARS CMAKE_INSTALL_INCLUDEDIR)
 write_basic_package_version_file(
   ${CMAKE_CURRENT_BINARY_DIR}/RinutilsConfigVersion.cmake
   VERSION 1.2.3
   COMPATIBILITY SameMajorVersion )
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/RinutilsConfig.cmake
               ${CMAKE_CURRENT_BINARY_DIR}/RinutilsConfigVersion.cmake
-        DESTINATION ${LIB_INSTALL_DIR}/Rinutils/cmake )
+        DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Rinutils )
 
 IF (WITH_TEST_SUITE)
 
diff --git a/RinutilsConfig.cmake.in b/RinutilsConfig.cmake.in
index 480fda0..f81f685 100644
--- a/RinutilsConfig.cmake.in
+++ b/RinutilsConfig.cmake.in
@@ -2,6 +2,6 @@ set(RINUTILS_VERSION x.y.z)
 
 @PACKAGE_INIT@
 
-set_and_check(RINUTILS_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
+set_and_check(RINUTILS_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
 
 check_required_components(Rinutils)
diff --git a/librinutils.pc.in b/librinutils.pc.in
index 6cdb514..1af6238 100644
--- a/librinutils.pc.in
+++ b/librinutils.pc.in
@@ -1,7 +1,7 @@
 prefix="@CMAKE_INSTALL_PREFIX@"
 exec_prefix=${prefix}
-libdir=${exec_prefix}/lib
-includedir=${prefix}/include
+libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
 
 Name:  rinutils
 Description: Ad hoc headers library for C
-- 
2.26.0

