cmake: use Threads::Threads imported target for POSIX Threads

- use `Threads::Threads` imported target, replacing
  `CMAKE_THREAD_LIBS_INIT`. To use the modern form and to allow using
  `THREADS_PREFER_PTHREAD_FLAG` option.

- only add Threads library/options if POSIX Threads was detected (not
  any other threading backend FindThreads may detect, e.g. the HP one.)

- curl-config.in.cmake: detect and define `Threads::Threads`.

Refs:
https://cmake.org/cmake/help/v3.18/module/FindThreads.html
https://cmake.org/cmake/help/v4.3/module/FindThreads.html

Closes #21163
This commit is contained in:
Viktor Szakats 2026-03-28 23:23:01 +01:00
parent ce6c441cf2
commit 2d546d239e
No known key found for this signature in database
2 changed files with 9 additions and 2 deletions

View file

@ -645,8 +645,10 @@ endif()
if(NOT WIN32)
find_package(Threads)
set(HAVE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
list(APPEND CURL_NETWORK_AND_TIME_LIBS ${CMAKE_THREAD_LIBS_INIT})
if(CMAKE_USE_PTHREADS_INIT)
set(HAVE_THREADS_POSIX 1)
list(APPEND CURL_NETWORK_AND_TIME_LIBS Threads::Threads)
endif()
endif()
if(ENABLE_THREADED_RESOLVER)
@ -2342,6 +2344,7 @@ if(NOT CURL_DISABLE_INSTALL)
# HAVE_GSSAPI
# HAVE_LIBIDN2
# HAVE_LIBZ ZLIB_VERSION_MAJOR
# HAVE_THREADS_POSIX
# HAVE_ZSTD
# USE_ARES
# USE_BACKTRACE