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