llvm-project/cmake/Modules/FindLibcCommonUtils.cmake
William Huynh 0b1639581a
[libc] Change LIBC_THREAD_LOCAL to be dependent on LIBC_THREAD_MODE (#151527)
When single-threaded mode is selected, all instances of the keyword
`LIBC_THREAD_LOCAL` are stubbed out, similar to how it currently works
on the GPU. This allows baremetal builds to avoid using thread_local.

However, libcxx uses shared headers, so we need to be careful there.
Thankfully, there is already an option to disable multithreading in
libcxx, so a flag is added such that single-threaded mode is propagated
down to libc.
2025-08-06 15:04:26 +01:00

23 lines
1.1 KiB
CMake

#===--------------------------------------------------------------------===//
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for details.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===--------------------------------------------------------------------===//
if(NOT TARGET llvm-libc-common-utilities)
set(libc_path ${CMAKE_CURRENT_LIST_DIR}/../../libc)
if (EXISTS ${libc_path} AND IS_DIRECTORY ${libc_path})
add_library(llvm-libc-common-utilities INTERFACE)
# TODO: Reorganize the libc shared section so that it can be included without
# adding the root "libc" directory to the include path.
if (NOT(LIBCXX_ENABLE_THREADS))
target_compile_definitions(llvm-libc-common-utilities INTERFACE LIBC_THREAD_MODE=LIBC_THREAD_MODE_SINGLE)
endif()
target_include_directories(llvm-libc-common-utilities INTERFACE ${libc_path})
target_compile_definitions(llvm-libc-common-utilities INTERFACE LIBC_NAMESPACE=__llvm_libc_common_utils)
target_compile_features(llvm-libc-common-utilities INTERFACE cxx_std_17)
endif()
endif()