From 07f52c3528e43c4a925a3fc59a933c89f5604d92 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Wed, 3 Jul 2024 20:45:48 +0300 Subject: [PATCH] CMake: Link xz against Threads::Threads if using pthreads The liblzma target was recently changed to link against Threads::Threads with the PRIVATE keyword. I had forgotten that xz itself depends on pthreads too due to pthread_sigmask(). Thus, the build broke when building shared liblzma and pthread_sigmask() wasn't in libc. Thanks to Peter Seiderer for the bug report. Fixes: ac05f1b0d7cda1e7ae79775a8dfecc54601d7f1c Fixes: https://github.com/tukaani-project/xz/issues/129#issuecomment-2204522994 (cherry picked from commit b3e53122f42796aaebd767bab920cf7bedf69966) --- CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 70435bac..75108c12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1776,6 +1776,19 @@ if(NOT MSVC OR MSVC_VERSION GREATER_EQUAL 1900) target_link_libraries(xz PRIVATE liblzma libgnu) + if(USE_POSIX_THREADS) + # src/xz/signals.c uses mythread_sigmask() which with POSIX + # threads calls pthread_sigmask(). Thus, we need the threading + # library as a dependency for xz. The liblzma target links against + # Threads::Threads PRIVATEly, thus that won't provide the pthreads + # symbols for xz. + # + # NOTE: The build may work without this if the symbol is in libc + # but it is mandatory to have this here to keep it working with + # all pthread implementations. + target_link_libraries(xz PRIVATE Threads::Threads) + endif() + target_compile_definitions(xz PRIVATE ASSUME_RAM=128) if(WIN32)