From 32980d1562bc031013306be1c787761fa63da87d Mon Sep 17 00:00:00 2001 From: Jia Tan Date: Tue, 28 Mar 2023 22:32:40 +0800 Subject: 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. --- CMakeLists.txt | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44be745a..55cd358c 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) -- cgit v1.2.3