cmake: detect mingw-w64 version, pre-fill HAVE_STRTOK_R

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
This commit is contained in:
Viktor Szakats 2025-01-16 18:10:31 +01:00
parent d5fb2b29d5
commit e49797abc2
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
3 changed files with 34 additions and 15 deletions

View File

@ -162,7 +162,6 @@ int main(void) { return 0; }
#endif #endif
#ifdef HAVE_IOCTLSOCKET #ifdef HAVE_IOCTLSOCKET
/* includes start */
#ifdef _WIN32 #ifdef _WIN32
# include <winsock2.h> # include <winsock2.h>
#endif #endif
@ -178,7 +177,6 @@ int main(void)
#endif #endif
#ifdef HAVE_IOCTLSOCKET_CAMEL #ifdef HAVE_IOCTLSOCKET_CAMEL
/* includes start */
#include <proto/bsdsocket.h> #include <proto/bsdsocket.h>
int main(void) int main(void)
{ {
@ -191,7 +189,6 @@ int main(void)
#endif #endif
#ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
/* includes start */
#include <proto/bsdsocket.h> #include <proto/bsdsocket.h>
#ifdef HAVE_SYS_IOCTL_H #ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h> # include <sys/ioctl.h>
@ -208,7 +205,6 @@ int main(void)
#endif #endif
#ifdef HAVE_IOCTLSOCKET_FIONBIO #ifdef HAVE_IOCTLSOCKET_FIONBIO
/* includes start */
#ifdef _WIN32 #ifdef _WIN32
# include <winsock2.h> # include <winsock2.h>
#endif #endif
@ -224,7 +220,6 @@ int main(void)
#ifdef HAVE_IOCTL_FIONBIO #ifdef HAVE_IOCTL_FIONBIO
/* headers for FIONBIO test */ /* headers for FIONBIO test */
/* includes start */
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
#endif #endif
@ -252,7 +247,6 @@ int main(void)
#ifdef HAVE_IOCTL_SIOCGIFADDR #ifdef HAVE_IOCTL_SIOCGIFADDR
/* headers for FIONBIO test */ /* headers for FIONBIO test */
/* includes start */
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
#endif #endif
@ -280,18 +274,15 @@ int main(void)
#endif #endif
#ifdef HAVE_SETSOCKOPT_SO_NONBLOCK #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK
/* includes start */
#ifdef _WIN32 #ifdef _WIN32
# include <winsock2.h> # include <winsock2.h>
#endif #endif
/* includes start */
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
#endif #endif
#ifdef HAVE_SYS_SOCKET_H #ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h> # include <sys/socket.h>
#endif #endif
/* includes end */
int main(void) int main(void)
{ {
if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0)) if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0))
@ -369,7 +360,6 @@ int main(void)
#endif #endif
#ifdef HAVE_ATOMIC #ifdef HAVE_ATOMIC
/* includes start */
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
#endif #endif
@ -379,8 +369,6 @@ int main(void)
#ifdef HAVE_STDATOMIC_H #ifdef HAVE_STDATOMIC_H
# include <stdatomic.h> # include <stdatomic.h>
#endif #endif
/* includes end */
int main(void) int main(void)
{ {
_Atomic int i = 1; _Atomic int i = 1;
@ -390,14 +378,12 @@ int main(void)
#endif #endif
#ifdef HAVE_WIN32_WINNT #ifdef HAVE_WIN32_WINNT
/* includes start */
#ifdef _WIN32 #ifdef _WIN32
# ifndef NOGDI # ifndef NOGDI
# define NOGDI # define NOGDI
# endif # endif
# include <windows.h> # include <windows.h>
#endif #endif
/* includes end */
#define enquote(x) #x #define enquote(x) #x
#define expand(x) enquote(x) #define expand(x) enquote(x)
@ -408,3 +394,20 @@ int main(void)
return 0; return 0;
} }
#endif #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

View File

@ -45,6 +45,13 @@ if(MINGW)
set(HAVE_UTIME_H 1) # wrapper to sys/utime.h set(HAVE_UTIME_H 1) # wrapper to sys/utime.h
set(HAVE_DIRENT_H 1) set(HAVE_DIRENT_H 1)
set(HAVE_OPENDIR 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 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)) (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.6))
set(HAVE_STDATOMIC_H 1) set(HAVE_STDATOMIC_H 1)

View File

@ -227,6 +227,15 @@ if(WIN32)
endif() endif()
# Avoid storing HAVE_WIN32_WINNT in CMake cache # Avoid storing HAVE_WIN32_WINNT in CMake cache
unset(HAVE_WIN32_WINNT 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) elseif(DOS OR AMIGA)
set(BUILD_SHARED_LIBS OFF) set(BUILD_SHARED_LIBS OFF)
set(BUILD_STATIC_LIBS ON) set(BUILD_STATIC_LIBS ON)