]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: detect `HAVE_GETADDRINFO_THREADSAFE`
authorViktor Szakats <commit@vsz.me>
Fri, 29 Sep 2023 00:38:06 +0000 (00:38 +0000)
committerViktor Szakats <commit@vsz.me>
Fri, 29 Sep 2023 18:30:34 +0000 (18:30 +0000)
Based on existing autotools logic.

autotools checks for old versions of the allowlisted target OSes and
disables this feature when seeing them. In CMake we assume we're running
on newer systems and enable regardless of OS version.

autotools always runs all 3 probes for non-fast-tracked systems and
enables this feature if any one of them was successful. To save
configuration time,  CMake stops at the first successful check.

OpenBSD is not fast-tracked and then gets blocklisted as a generic BSD
system. I haven't double-checked if this is correct, but looks odd.

Ref: #11964 (effort to sync cmake detections with autotools)

Closes #11979

CMake/OtherTests.cmake
CMakeLists.txt

index 78d39404556ba656a940c0b9eb63f025c75eccdc..31bb026b720df1e8e185ff32797af35ae757625c 100644 (file)
@@ -22,6 +22,8 @@
 #
 ###########################################################################
 include(CheckCSourceCompiles)
+include(CheckCSourceRuns)
+
 # The begin of the sources (macros and includes)
 set(_source_epilogue "#undef inline")
 
@@ -89,7 +91,6 @@ if(NOT CMAKE_CROSSCOMPILING)
     # only try this on non-apple platforms
 
     # if not cross-compilation...
-    include(CheckCSourceRuns)
     set(CMAKE_REQUIRED_FLAGS "")
     if(HAVE_SYS_POLL_H)
       set(CMAKE_REQUIRED_FLAGS "-DHAVE_SYS_POLL_H")
@@ -132,3 +133,70 @@ if(NOT CMAKE_CROSSCOMPILING)
     }" HAVE_POLL_FINE)
   endif()
 endif()
+
+# Detect HAVE_GETADDRINFO_THREADSAFE
+
+if(WIN32)
+  set(HAVE_GETADDRINFO_THREADSAFE ${HAVE_GETADDRINFO})
+elseif(NOT HAVE_GETADDRINFO)
+  set(HAVE_GETADDRINFO_THREADSAFE FALSE)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "AIX" OR
+       CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
+       CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
+       CMAKE_SYSTEM_NAME STREQUAL "HP-UX" OR
+       CMAKE_SYSTEM_NAME STREQUAL "MidnightBSD" OR
+       CMAKE_SYSTEM_NAME STREQUAL "NetBSD" OR
+       CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+  set(HAVE_GETADDRINFO_THREADSAFE TRUE)
+elseif(CMAKE_SYSTEM_NAME MATCHES "BSD")
+  set(HAVE_GETADDRINFO_THREADSAFE FALSE)
+endif()
+
+if(NOT DEFINED HAVE_GETADDRINFO_THREADSAFE)
+
+  set(_save_epilogue "${_source_epilogue}")
+  set(_source_epilogue "#undef inline")
+
+  add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
+  add_header_include(HAVE_SYS_TIME_H "sys/time.h")
+  add_header_include(HAVE_NETDB_H "netdb.h")
+
+  check_c_source_compiles("${_source_epilogue}
+    int main(void)
+    {
+    #ifdef h_errno
+      return 0;
+    #else
+      force compilation error
+    #endif
+    }" HAVE_H_ERRNO)
+
+  if(NOT HAVE_H_ERRNO)
+    check_c_source_runs("${_source_epilogue}
+      int main(void)
+      {
+        h_errno = 2;
+        return h_errno != 0 ? 1 : 0;
+      }" HAVE_H_ERRNO_ASSIGNABLE)
+
+    if(NOT HAVE_H_ERRNO_ASSIGNABLE)
+      check_c_source_compiles("${_source_epilogue}
+        int main(void)
+        {
+        #if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
+          return 0;
+        #elif defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 700)
+          return 0;
+        #else
+          force compilation error
+        #endif
+        }" HAVE_H_ERRNO_SBS_ISSUE_7)
+    endif()
+  endif()
+
+  if(HAVE_H_ERRNO OR HAVE_H_ERRNO_ASSIGNABLE OR HAVE_H_ERRNO_SBS_ISSUE_7)
+    set(HAVE_GETADDRINFO_THREADSAFE TRUE)
+  endif()
+
+  set(_source_epilogue "${_save_epilogue}")
+endif()
index 36d23c82ea40e9e14f604f8198b9c2feeef12058..c08503114a78348b85721dafa6a7f14d98694806 100644 (file)
@@ -1141,9 +1141,6 @@ check_symbol_exists(strerror_r     "${CURL_INCLUDES};stdlib.h;string.h" HAVE_STR
 check_symbol_exists(siginterrupt   "${CURL_INCLUDES}" HAVE_SIGINTERRUPT)
 check_symbol_exists(getaddrinfo    "${CURL_INCLUDES};stdlib.h;string.h" HAVE_GETADDRINFO)
 check_symbol_exists(getifaddrs     "${CURL_INCLUDES};stdlib.h" HAVE_GETIFADDRS)
-if(WIN32)
-  set(HAVE_GETADDRINFO_THREADSAFE ${HAVE_GETADDRINFO})
-endif()
 check_symbol_exists(freeaddrinfo   "${CURL_INCLUDES}" HAVE_FREEADDRINFO)
 check_symbol_exists(pipe           "${CURL_INCLUDES}" HAVE_PIPE)
 check_symbol_exists(ftruncate      "${CURL_INCLUDES}" HAVE_FTRUNCATE)