[libc++] Add CMake plumbing for _LIBCPP_HAS_THREAD_API_C11 mode. (#188414)

Introduce CMake option `LIBCXX_HAS_C11_THREAD_API` that explicitly
instructs libc++ to use C11 threads. Make sure
`_LIBCPP_HAS_THREAD_API_C11` is defined properly in the
`<__config_site>` and interacts correctly with platform-based
auto-selection of thread API when it's not explicitly set.
This commit is contained in:
Alexey Samsonov 2026-03-25 10:51:31 -07:00 committed by GitHub
parent a3260f6582
commit 0eb8f018a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 2 deletions

View file

@ -310,6 +310,7 @@ option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32
option(LIBCXX_HAS_EXTERNAL_THREAD_API
"Build libc++ with an externalized threading API.
This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
option(LIBCXX_HAS_C11_THREAD_API "Ignore auto-detection and force use of C11 thread API" OFF)
if (LIBCXX_ENABLE_THREADS)
set(LIBCXX_PSTL_BACKEND "std_thread" CACHE STRING "Which PSTL backend to use")
@ -354,6 +355,10 @@ if(NOT LIBCXX_ENABLE_THREADS)
message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON"
" when LIBCXX_ENABLE_THREADS is also set to ON.")
endif()
if (LIBCXX_HAS_C11_THREAD_API)
message(FATAL_ERROR "LIBCXX_HAS_C11_THREAD_API can only be set to ON"
" when LIBCXX_ENABLE_THREADS is also set to ON.")
endif()
endif()
@ -368,6 +373,11 @@ if (LIBCXX_HAS_EXTERNAL_THREAD_API)
" and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
" set to ON at the same time.")
endif()
if (LIBCXX_HAS_C11_THREAD_API)
message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
" and LIBCXX_HAS_C11_THREAD_API cannot be both"
" set to ON at the same time.")
endif()
endif()
if (LIBCXX_HAS_PTHREAD_API)
@ -376,6 +386,19 @@ if (LIBCXX_HAS_PTHREAD_API)
" and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
" set to ON at the same time.")
endif()
if (LIBCXX_HAS_C11_THREAD_API)
message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API"
" and LIBCXX_HAS_C11_THREAD_API cannot be both"
" set to ON at the same time.")
endif()
endif()
if (LIBCXX_HAS_WIN32_THREAD_API)
if (LIBCXX_HAS_C11_THREAD_API)
message(FATAL_ERROR "The options LIBCXX_HAS_WIN32_THREAD_API"
" and LIBCXX_HAS_C11_THREAD_API cannot be both"
" set to ON at the same time.")
endif()
endif()
if (NOT LIBCXX_ENABLE_RTTI AND LIBCXX_ENABLE_EXCEPTIONS)
@ -762,6 +785,7 @@ endif()
config_define(${LIBCXX_HAS_PTHREAD_API} _LIBCPP_HAS_THREAD_API_PTHREAD)
config_define(${LIBCXX_HAS_EXTERNAL_THREAD_API} _LIBCPP_HAS_THREAD_API_EXTERNAL)
config_define(${LIBCXX_HAS_WIN32_THREAD_API} _LIBCPP_HAS_THREAD_API_WIN32)
config_define(${LIBCXX_HAS_C11_THREAD_API} _LIBCPP_HAS_THREAD_API_C11)
config_define(${LIBCXX_HAS_MUSL_LIBC} _LIBCPP_HAS_MUSL_LIBC)
config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)
config_define(${LIBCXX_ENABLE_FILESYSTEM} _LIBCPP_HAS_FILESYSTEM)

View file

@ -370,7 +370,8 @@ typedef __char32_t char32_t;
# if _LIBCPP_HAS_THREADS && \
!_LIBCPP_HAS_THREAD_API_PTHREAD && \
!_LIBCPP_HAS_THREAD_API_WIN32 && \
!_LIBCPP_HAS_THREAD_API_EXTERNAL
!_LIBCPP_HAS_THREAD_API_EXTERNAL && \
!_LIBCPP_HAS_THREAD_API_C11
# if defined(__FreeBSD__) || \
defined(__wasi__) || \
@ -414,6 +415,10 @@ typedef __char32_t char32_t;
# error _LIBCPP_HAS_THREAD_API_EXTERNAL may only be true when _LIBCPP_HAS_THREADS is true.
# endif
# if !_LIBCPP_HAS_THREADS && _LIBCPP_HAS_THREAD_API_C11
# error _LIBCPP_HAS_THREAD_API_C11 may only be true when _LIBCPP_HAS_THREADS is true.
# endif
# if !_LIBCPP_HAS_MONOTONIC_CLOCK && _LIBCPP_HAS_THREADS
# error _LIBCPP_HAS_MONOTONIC_CLOCK may only be false when _LIBCPP_HAS_THREADS is false.
# endif

View file

@ -19,7 +19,7 @@
#cmakedefine01 _LIBCPP_HAS_THREAD_API_PTHREAD
#cmakedefine01 _LIBCPP_HAS_THREAD_API_EXTERNAL
#cmakedefine01 _LIBCPP_HAS_THREAD_API_WIN32
#define _LIBCPP_HAS_THREAD_API_C11 0 // FIXME: Is this guarding dead code?
#cmakedefine01 _LIBCPP_HAS_THREAD_API_C11
#cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
#cmakedefine01 _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS
#cmakedefine _LIBCPP_NO_VCRUNTIME