From f38d56b6923f34a4344381f348726ee50694b98f Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Sat, 17 Aug 2024 17:54:12 +0200 Subject: [PATCH] Add back support for relocatable packages (#2431) --- CMakeLists.txt | 18 +++++++++++++++++- capstone-config.cmake.in | 4 ++-- capstone.pc.in | 4 ++-- cmake_uninstall.cmake.in | 8 ++++---- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 578aa603a..c6acc4988 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -837,11 +837,27 @@ source_group("Include\\LoongArch" FILES ${HEADERS_LOONGARCH}) ## installation if(CAPSTONE_INSTALL) - include("GNUInstallDirs") + include(GNUInstallDirs) install(FILES ${HEADERS_COMMON} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/capstone) install(FILES ${HEADERS_INC} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/capstone/inc) + # Support absolute installation paths (discussion: https://github.com/NixOS/nixpkgs/issues/144170) + if(IS_ABSOLUTE ${CMAKE_INSTALL_LIBDIR}) + set(CAPSTONE_PKGCONFIG_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}) + set(CAPSTONE_CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR}) + else() + set(CAPSTONE_PKGCONFIG_INSTALL_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}") + set(CAPSTONE_CMAKE_INSTALL_LIBDIR "\${PACKAGE_PREFIX_DIR}/${CMAKE_INSTALL_LIBDIR}") + endif() + if(IS_ABSOLUTE ${CMAKE_INSTALL_INCLUDEDIR}) + set(CAPSTONE_PKGCONFIG_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}) + set(CAPSTONE_CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}) + else() + set(CAPSTONE_PKGCONFIG_INSTALL_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") + set(CAPSTONE_CMAKE_INSTALL_INCLUDEDIR "\${PACKAGE_PREFIX_DIR}/${CMAKE_INSTALL_INCLUDEDIR}") + endif() + configure_file(capstone.pc.in ${CMAKE_BINARY_DIR}/capstone.pc @ONLY) install(FILES ${CMAKE_BINARY_DIR}/capstone.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/capstone-config.cmake.in b/capstone-config.cmake.in index 445ecda0e..007a7edac 100644 --- a/capstone-config.cmake.in +++ b/capstone-config.cmake.in @@ -1,6 +1,6 @@ @PACKAGE_INIT@ -set_and_check(capstone_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@") -set_and_check(capstone_LIB_DIR "@CMAKE_INSTALL_FULL_LIBDIR@") +set_and_check(capstone_INCLUDE_DIR "@CAPSTONE_CMAKE_INSTALL_INCLUDEDIR@") +set_and_check(capstone_LIB_DIR "@CAPSTONE_CMAKE_INSTALL_LIBDIR@") include("${CMAKE_CURRENT_LIST_DIR}/capstone-targets.cmake") diff --git a/capstone.pc.in b/capstone.pc.in index b8cfebd0c..533a23493 100644 --- a/capstone.pc.in +++ b/capstone.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} -libdir=@CMAKE_INSTALL_FULL_LIBDIR@ -includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ +libdir=@CAPSTONE_PKGCONFIG_INSTALL_LIBDIR@ +includedir=@CAPSTONE_PKGCONFIG_INSTALL_INCLUDEDIR@ Name: capstone Description: Capstone disassembly engine diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in index a1cecefde..7bbdac871 100644 --- a/cmake_uninstall.cmake.in +++ b/cmake_uninstall.cmake.in @@ -13,8 +13,8 @@ foreach(file ${files}) endif() endforeach() -message(STATUS "Uninstalling @CMAKE_INSTALL_FULL_INCLUDEDIR@/capstone") -file(REMOVE_RECURSE @CMAKE_INSTALL_FULL_INCLUDEDIR@/capstone) +message(STATUS "Uninstalling @CAPSTONE_CMAKE_INSTALL_INCLUDEDIR@/capstone") +file(REMOVE_RECURSE @CAPSTONE_CMAKE_INSTALL_INCLUDEDIR@/capstone) -message(STATUS "Uninstalling @CMAKE_INSTALL_FULL_LIBDIR@/cmake/capstone") -file(REMOVE_RECURSE @CMAKE_INSTALL_FULL_LIBDIR@/cmake/capstone) +message(STATUS "Uninstalling @CAPSTONE_CMAKE_INSTALL_LIBDIR@/cmake/capstone") +file(REMOVE_RECURSE @CAPSTONE_CMAKE_INSTALL_LIBDIR@/cmake/capstone)