]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
CMake: Link xz against Threads::Threads if using pthreads
authorLasse Collin <lasse.collin@tukaani.org>
Wed, 3 Jul 2024 17:45:48 +0000 (20:45 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Wed, 3 Jul 2024 17:45:48 +0000 (20:45 +0300)
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
CMakeLists.txt

index 5e2945303edb5fa59a5115dee3582abe5f1312e5..457954bb4a4c2b2af937b565ddb0a322e51e4f39 100644 (file)
@@ -2029,6 +2029,19 @@ if(XZ_TOOL_XZ)
 
     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()
+
     set(XZ_ASSUME_RAM "128" CACHE STRING "Assume that the system has \
 this many MiB of RAM if xz cannot determine the amount at runtime")
     target_compile_definitions(xz PRIVATE "ASSUME_RAM=${XZ_ASSUME_RAM}")