Skip to content

Commit 05b3716

Browse files
committed
[libcxxabi] Add LIBCXXABI_HAS_WIN32_THREAD_API build option
A few files in libc++abi make use of libc++ headers and a few of those use threading primitives provided by libc++. Since libc++ has multiple threading APIs it may be necessary to override auto-detection. This patch adds the LIBCXXABI_HAS_WIN32_THREAD_API which does roughly the same as LIBCXXABI_HAS_PTHREAD_API and the similarly named LIBCXX_HAS_WIN32_THREAD_API from libc++. Instead of using autodetection it will force the use of win32 threads instead of pthreads in headers included from libc++. Without this patch, libc++abi may depend on pthreads if present on the users build environment, even if win32 threading was selected for libc++. Differential revision: https://reviews.llvm.org/D98021
1 parent afa76fe commit 05b3716

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

libcxxabi/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF
8989
option(LIBCXXABI_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
9090
option(LIBCXXABI_ENABLE_THREADS "Build with threads enabled" ON)
9191
option(LIBCXXABI_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
92+
option(LIBCXXABI_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
9293
option(LIBCXXABI_HAS_EXTERNAL_THREAD_API
9394
"Build libc++abi with an externalized threading API.
9495
This option may only be set to ON when LIBCXXABI_ENABLE_THREADS=ON." OFF)
@@ -374,6 +375,11 @@ if (NOT LIBCXXABI_ENABLE_THREADS)
374375
" be set to ON when LIBCXXABI_ENABLE_THREADS"
375376
" is also set to ON.")
376377
endif()
378+
if (LIBCXXABI_HAS_WIN32_THREAD_API)
379+
message(FATAL_ERROR "LIBCXXABI_HAS_WIN32_THREAD_API can only"
380+
" be set to ON when LIBCXXABI_ENABLE_THREADS"
381+
" is also set to ON.")
382+
endif()
377383
if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
378384
message(FATAL_ERROR "LIBCXXABI_HAS_EXTERNAL_THREAD_API can only"
379385
" be set to ON when LIBCXXABI_ENABLE_THREADS"
@@ -394,13 +400,26 @@ if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
394400
" and LIBCXXABI_HAS_PTHREAD_API cannot be both"
395401
" set to ON at the same time.")
396402
endif()
403+
if (LIBCXXABI_HAS_WIN32_THREAD_API)
404+
message(FATAL_ERROR "The options LIBCXXABI_HAS_EXTERNAL_THREAD_API"
405+
" and LIBCXXABI_HAS_WIN32_THREAD_API cannot be both"
406+
" set to ON at the same time.")
407+
endif()
397408
if (LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
398409
message(FATAL_ERROR "The options LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY"
399410
" and LIBCXXABI_HAS_EXTERNAL_THREAD_API cannot be both"
400411
" set to ON at the same time.")
401412
endif()
402413
endif()
403414

415+
if (LIBCXXABI_HAS_PTHREAD_API)
416+
if (LIBCXXABI_HAS_WIN32_THREAD_API)
417+
message(FATAL_ERROR "The options LIBCXXABI_HAS_PTHREAD_API"
418+
"and LIBCXXABI_HAS_WIN32_THREAD_API cannot be both"
419+
"set to ON at the same time.")
420+
endif()
421+
endif()
422+
404423
if (LLVM_ENABLE_MODULES)
405424
# Ignore that the rest of the modules flags are now unused.
406425
add_compile_flags_if_supported(-Wno-unused-command-line-argument)
@@ -428,6 +447,10 @@ if (LIBCXXABI_HAS_PTHREAD_API)
428447
add_definitions(-D_LIBCPP_HAS_THREAD_API_PTHREAD)
429448
endif()
430449

450+
if (LIBCXXABI_HAS_WIN32_THREAD_API)
451+
add_definitions(-D_LIBCPP_HAS_THREAD_API_WIN32)
452+
endif()
453+
431454
if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
432455
add_definitions(-D_LIBCPP_HAS_THREAD_API_EXTERNAL)
433456
endif()

0 commit comments

Comments
 (0)