summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJia Tan <jiat0218@gmail.com>2023-03-28 22:32:40 +0800
committerJia Tan <jiat0218@gmail.com>2023-03-29 23:46:38 +0800
commit2cb6028fc31de082b7f927632363bb1426b61aaa (patch)
treec40ee8704c25e2ef4827e7ce28dd8b503ebc70c0
parent4d7fac0b07cc722825ba8d7838c558827e635611 (diff)
downloadxz-2cb6028fc31de082b7f927632363bb1426b61aaa.tar.gz
CMake: Update liblzma-config.cmake generation.
Now that the threading is configurable, the liblzma CMake package only needs the threading library when using POSIX threads.
-rw-r--r--CMakeLists.txt33
1 files changed, 22 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 44be745..55cd358 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -870,10 +870,7 @@ set_target_properties(liblzma PROPERTIES
PREFIX ""
)
-# Create liblzma-config-version.cmake. We use this spelling instead of
-# liblzmaConfig.cmake to make find_package work in case insensitive manner
-# even with case sensitive file systems. This gives more consistent behavior
-# between operating systems.
+# Create liblzma-config-version.cmake.
#
# FIXME: SameMajorVersion is correct for stable releases but it is wrong
# for development releases where each release may have incompatible changes.
@@ -883,13 +880,14 @@ write_basic_package_version_file(
VERSION "${liblzma_VERSION}"
COMPATIBILITY SameMajorVersion)
-# Create liblzma-config.cmake.
-file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake"
-"include(CMakeFindDependencyMacro)
-set(THREADS_PREFER_PTHREAD_FLAG TRUE)
-find_dependency(Threads)
-
-include(\"\${CMAKE_CURRENT_LIST_DIR}/liblzma-targets.cmake\")
+# Create liblzma-config.cmake. We use this spelling instead of
+# liblzmaConfig.cmake to make find_package work in case insensitive
+# manner even with case sensitive file systems. This gives more consistent
+# behavior between operating systems. This optionally includes a dependency
+# on a threading library, so the contents are created in two separate parts.
+# The "second half" is always needed, so create it first.
+set(LZMA_CONFIG_CONTENTS
+"include(\"\${CMAKE_CURRENT_LIST_DIR}/liblzma-targets.cmake\")
# Be compatible with the spelling used by the FindLibLZMA module. This
# doesn't use ALIAS because it would make CMake resolve LibLZMA::LibLZMA
@@ -900,6 +898,19 @@ set_target_properties(LibLZMA::LibLZMA PROPERTIES
INTERFACE_LINK_LIBRARIES liblzma::liblzma)
")
+if(ENABLE_THREADS STREQUAL "posix")
+ set(LZMA_CONFIG_CONTENTS
+"include(CMakeFindDependencyMacro)
+set(THREADS_PREFER_PTHREAD_FLAG TRUE)
+find_dependency(Threads)
+
+${LZMA_CONFIG_CONTENTS}
+")
+endif()
+
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake"
+ "${LZMA_CONFIG_CONTENTS}")
+
# Set CMAKE_INSTALL_LIBDIR and friends.
include(GNUInstallDirs)