]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: detect mingw-w64 version, pre-fill `HAVE_STRTOK_R`
authorViktor Szakats <commit@vsz.me>
Thu, 16 Jan 2025 17:10:31 +0000 (18:10 +0100)
committerViktor Szakats <commit@vsz.me>
Fri, 17 Jan 2025 22:31:57 +0000 (23:31 +0100)
Replace `strtok_r()` detection with detection mingw-w64 version.
The use this version to pre-fill `HAVE_STRTOK_R`.

This gives use mingw-w64 version information for free.

Closes #16022

CMake/CurlTests.c
CMake/win32-cache.cmake
CMakeLists.txt

index bf07aed63cef8d0d3cf057a23b716d0f644c18f9..468426ef7aab8993914baeb933486815ccc3f4ea 100644 (file)
@@ -162,7 +162,6 @@ int main(void) { return 0; }
 #endif
 
 #ifdef HAVE_IOCTLSOCKET
-/* includes start */
 #ifdef _WIN32
 #  include <winsock2.h>
 #endif
@@ -178,7 +177,6 @@ int main(void)
 #endif
 
 #ifdef HAVE_IOCTLSOCKET_CAMEL
-/* includes start */
 #include <proto/bsdsocket.h>
 int main(void)
 {
@@ -191,7 +189,6 @@ int main(void)
 #endif
 
 #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
-/* includes start */
 #include <proto/bsdsocket.h>
 #ifdef HAVE_SYS_IOCTL_H
 #  include <sys/ioctl.h>
@@ -208,7 +205,6 @@ int main(void)
 #endif
 
 #ifdef HAVE_IOCTLSOCKET_FIONBIO
-/* includes start */
 #ifdef _WIN32
 #  include <winsock2.h>
 #endif
@@ -224,7 +220,6 @@ int main(void)
 
 #ifdef HAVE_IOCTL_FIONBIO
 /* headers for FIONBIO test */
-/* includes start */
 #ifdef HAVE_SYS_TYPES_H
 #  include <sys/types.h>
 #endif
@@ -252,7 +247,6 @@ int main(void)
 
 #ifdef HAVE_IOCTL_SIOCGIFADDR
 /* headers for FIONBIO test */
-/* includes start */
 #ifdef HAVE_SYS_TYPES_H
 #  include <sys/types.h>
 #endif
@@ -280,18 +274,15 @@ int main(void)
 #endif
 
 #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK
-/* includes start */
 #ifdef _WIN32
 #  include <winsock2.h>
 #endif
-/* includes start */
 #ifdef HAVE_SYS_TYPES_H
 #  include <sys/types.h>
 #endif
 #ifdef HAVE_SYS_SOCKET_H
 #  include <sys/socket.h>
 #endif
-/* includes end */
 int main(void)
 {
   if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0))
@@ -369,7 +360,6 @@ int main(void)
 #endif
 
 #ifdef HAVE_ATOMIC
-/* includes start */
 #ifdef HAVE_SYS_TYPES_H
 #  include <sys/types.h>
 #endif
@@ -379,8 +369,6 @@ int main(void)
 #ifdef HAVE_STDATOMIC_H
 #  include <stdatomic.h>
 #endif
-/* includes end */
-
 int main(void)
 {
   _Atomic int i = 1;
@@ -390,14 +378,12 @@ int main(void)
 #endif
 
 #ifdef HAVE_WIN32_WINNT
-/* includes start */
 #ifdef _WIN32
 #  ifndef NOGDI
-#    define NOGDI
+#  define NOGDI
 #  endif
 #  include <windows.h>
 #endif
-/* includes end */
 
 #define enquote(x) #x
 #define expand(x) enquote(x)
@@ -408,3 +394,20 @@ int main(void)
   return 0;
 }
 #endif
+
+#ifdef MINGW64_VERSION
+#ifdef __MINGW32__
+#  include <_mingw.h>
+#endif
+
+#define enquote(x) #x
+#define expand(x) enquote(x)
+#pragma message("MINGW64_VERSION=" \
+  expand(__MINGW64_VERSION_MAJOR) "." \
+  expand(__MINGW64_VERSION_MINOR))
+
+int main(void)
+{
+  return 0;
+}
+#endif
index 25323fddfcd8f8f02a0bc71c0df57bef880cdbed..0cb0a12bd3a842322a92a429e8c7a7b398abac87 100644 (file)
@@ -45,6 +45,13 @@ if(MINGW)
   set(HAVE_UTIME_H 1)  # wrapper to sys/utime.h
   set(HAVE_DIRENT_H 1)
   set(HAVE_OPENDIR 1)
+  if(MINGW64_VERSION)
+    if(NOT MINGW64_VERSION VERSION_LESS 4.0)
+      set(HAVE_STRTOK_R 1)
+    else()
+      set(HAVE_STRTOK_R 0)
+    endif()
+  endif()
   if((CMAKE_COMPILER_IS_GNUCC              AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9) OR
      (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.6))
     set(HAVE_STDATOMIC_H 1)
index c7e6b04e16d669c17d00061a846c9567f0142204..16b4a57be54cd12b273ba131dc464b729ebc0c13 100644 (file)
@@ -227,6 +227,15 @@ if(WIN32)
   endif()
   # Avoid storing HAVE_WIN32_WINNT in CMake cache
   unset(HAVE_WIN32_WINNT CACHE)
+
+  if(MINGW)
+    curl_internal_test(MINGW64_VERSION)
+    if(MINGW64_VERSION)
+      string(REGEX MATCH "MINGW64_VERSION=[0-9]+\.[0-9]+" CURL_TEST_OUTPUT "${CURL_TEST_OUTPUT}")
+      string(REGEX REPLACE "MINGW64_VERSION=" "" MINGW64_VERSION "${CURL_TEST_OUTPUT}")
+      message(STATUS "Found MINGW64_VERSION=${MINGW64_VERSION}")
+    endif()
+  endif()
 elseif(DOS OR AMIGA)
   set(BUILD_SHARED_LIBS OFF)
   set(BUILD_STATIC_LIBS ON)