mirror of
https://github.com/json-c/json-c.git
synced 2026-04-08 06:49:07 +08:00
CMake: Add an option to disable the use of thread-local storage.
Using thread-local storage may not be desired in all environments and/or use-cases, thus there should be an option to disable its use on purpose. Fixes #451.
This commit is contained in:
@@ -87,6 +87,7 @@ option(ENABLE_RDRAND "Enable RDRAND Hardware RNG Hash Seed"
|
|||||||
option(ENABLE_THREADING "Enable partial threading support." OFF)
|
option(ENABLE_THREADING "Enable partial threading support." OFF)
|
||||||
option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors" OFF)
|
option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors" OFF)
|
||||||
option(DISABLE_BSYMBOLIC "Avoid linking with -Bsymbolic-function" OFF)
|
option(DISABLE_BSYMBOLIC "Avoid linking with -Bsymbolic-function" OFF)
|
||||||
|
option(DISABLE_THREAD_LOCAL_STORAGE "Disable Thread-Local Storage (HAVE___THREAD)" OFF)
|
||||||
|
|
||||||
if (UNIX OR MINGW OR CYGWIN)
|
if (UNIX OR MINGW OR CYGWIN)
|
||||||
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
|
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
|
||||||
@@ -217,14 +218,16 @@ check_c_source_compiles(
|
|||||||
"int main() { int i, x = 0; i = __sync_add_and_fetch(&x,1); return x; }"
|
"int main() { int i, x = 0; i = __sync_add_and_fetch(&x,1); return x; }"
|
||||||
HAVE_ATOMIC_BUILTINS)
|
HAVE_ATOMIC_BUILTINS)
|
||||||
|
|
||||||
check_c_source_compiles(
|
if (NOT DISABLE_THREAD_LOCAL_STORAGE)
|
||||||
"__thread int x = 0; int main() { return 0; }"
|
check_c_source_compiles(
|
||||||
HAVE___THREAD)
|
"__thread int x = 0; int main() { return 0; }"
|
||||||
|
HAVE___THREAD)
|
||||||
|
|
||||||
if (HAVE___THREAD)
|
if (HAVE___THREAD)
|
||||||
set(SPEC___THREAD __thread)
|
set(SPEC___THREAD __thread)
|
||||||
elseif (MSVC)
|
elseif (MSVC)
|
||||||
set(SPEC___THREAD __declspec(thread))
|
set(SPEC___THREAD __declspec(thread))
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Hardware random number is not available on Windows? Says, config.h.win32. Best to preserve compatibility.
|
# Hardware random number is not available on Windows? Says, config.h.win32. Best to preserve compatibility.
|
||||||
|
|||||||
Reference in New Issue
Block a user