Skip to content

Commit

Permalink
cmake: Check for C11 atomics and set config
Browse files Browse the repository at this point in the history
Context curl#8973

- Also add `threadsafe-init` feature to list.
- Update the `AC_LANG_PROGRAM` to perform the same check as the CMake
  version
  • Loading branch information
cblichmann committed Jun 14, 2022
1 parent 4572489 commit 29d5da8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,31 @@ if(HAVE_SIZEOF_LONG_LONG)
set(HAVE_LL 1)
endif()

# Check for atomics support
check_c_source_compiles(
"
#include <stdatomic.h>
int main(void)
{
atomic_int i = 0;
return atomic_load(&i);
}" HAVE_ATOMIC
)

# Check for SRW lock support
if(WIN32)
check_c_source_compiles(
"
#include <windows.h>
#if (WINVER < 0x600) && (_WIN32_WINNT < 0x600)
#error
#endif
" HAVE_SRW_LOCK
)
endif()

find_file(RANDOM_FILE urandom /dev)
mark_as_advanced(RANDOM_FILE)

Expand Down Expand Up @@ -1464,6 +1489,7 @@ _add_if("HTTP3" USE_NGTCP2 OR USE_QUICHE)
_add_if("MultiSSL" CURL_WITH_MULTI_SSL)
_add_if("HTTPS-proxy" SSL_ENABLED AND (USE_OPENSSL OR USE_GNUTLS OR USE_NSS))
_add_if("unicode" ENABLE_UNICODE)
_add_if("threadsafe-init" (NOT WIN32 AND HAVE_ATOMIC) OR (HAVE_SRW_LOCK))
string(REPLACE ";" " " SUPPORT_FEATURES "${_items}")
message(STATUS "Enabled features: ${SUPPORT_FEATURES}")

Expand Down
3 changes: 3 additions & 0 deletions lib/curl_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@
/* Define to 1 if the compiler supports the 'long long' data type. */
#cmakedefine HAVE_LONGLONG 1

/* Define to 1 if the compiler supports C11 atomics. */
#cmakedefine HAVE_ATOMIC 1

/* Define to 1 if you have the malloc.h header file. */
#cmakedefine HAVE_MALLOC_H 1

Expand Down
4 changes: 3 additions & 1 deletion m4/curl-functions.m4
Original file line number Diff line number Diff line change
Expand Up @@ -6577,9 +6577,11 @@ AC_DEFUN([CURL_ATOMIC],[
AC_MSG_CHECKING([if _Atomic is available])
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
#include <stdatomic.h>
$curl_includes_unistd
]],[[
_Atomic int i = 0;
atomic_int i = 0;
(void) atomic_load(&i);
]])
],[
AC_MSG_RESULT([yes])
Expand Down

0 comments on commit 29d5da8

Please sign in to comment.