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 ebd155c3a1)
This commit is contained in:
Lasse Collin 2024-06-16 19:18:56 +03:00
parent ff697eb154
commit 4107f20667
No known key found for this signature in database
GPG Key ID: 38EE757D69184620
1 changed files with 14 additions and 4 deletions

View File

@ -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_<dir> 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(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