From 4107f2066764bb3a31d114852bc20722d582fd82 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Sun, 16 Jun 2024 19:18:56 +0300 Subject: [PATCH] CMake: Use relative paths in liblzma.pc if possible Now liblzma.pc can be relocatable only if using CMake >= 3.20 but that should be OK as now we shouldn't get broken liblzma.pc if CMAKE_INSTALL_LIBDIR or CMAKE_INSTALL_INCLUDEDIR contain an absolute path. Thanks to Eli Schwartz. (cherry picked from commit ebd155c3a1b87411edae06d3bdaa9659ec057522) --- CMakeLists.txt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cf1a2ab..b505c900 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1397,11 +1397,21 @@ endif() file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake" "${LZMA_CONFIG_CONTENTS}") -# Create liblzma.pc. +# Create liblzma.pc. If using CMake >= 3.20 and CMAKE_INSTALL_ paths +# are relative to CMAKE_INSTALL_PREFIX, the .pc file will be relocatable +# (that is, all paths will be relative to ${prefix}). Otherwise absolute +# paths will be used. set(prefix "${CMAKE_INSTALL_PREFIX}") -set(exec_prefix "${CMAKE_INSTALL_PREFIX}") -set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") -set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") +set(exec_prefix "\${prefix}") + +if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20") + cmake_path(APPEND libdir "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}") + cmake_path(APPEND includedir "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") +else() + set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") + set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") +endif() + set(PTHREAD_CFLAGS "${CMAKE_THREAD_LIBS_INIT}") configure_file(src/liblzma/liblzma.pc.in liblzma.pc @ONLY