From: Viktor Szakats Date: Thu, 16 Jan 2025 17:10:31 +0000 (+0100) Subject: cmake: detect mingw-w64 version, pre-fill `HAVE_STRTOK_R` X-Git-Tag: curl-8_12_0~90 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e49797abc24b8e0ac652d7aa0ceec7d252f9a019;p=thirdparty%2Fcurl.git 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 --- diff --git a/CMake/CurlTests.c b/CMake/CurlTests.c index bf07aed63c..468426ef7a 100644 --- a/CMake/CurlTests.c +++ b/CMake/CurlTests.c @@ -162,7 +162,6 @@ int main(void) { return 0; } #endif #ifdef HAVE_IOCTLSOCKET -/* includes start */ #ifdef _WIN32 # include #endif @@ -178,7 +177,6 @@ int main(void) #endif #ifdef HAVE_IOCTLSOCKET_CAMEL -/* includes start */ #include int main(void) { @@ -191,7 +189,6 @@ int main(void) #endif #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO -/* includes start */ #include #ifdef HAVE_SYS_IOCTL_H # include @@ -208,7 +205,6 @@ int main(void) #endif #ifdef HAVE_IOCTLSOCKET_FIONBIO -/* includes start */ #ifdef _WIN32 # include #endif @@ -224,7 +220,6 @@ int main(void) #ifdef HAVE_IOCTL_FIONBIO /* headers for FIONBIO test */ -/* includes start */ #ifdef HAVE_SYS_TYPES_H # include #endif @@ -252,7 +247,6 @@ int main(void) #ifdef HAVE_IOCTL_SIOCGIFADDR /* headers for FIONBIO test */ -/* includes start */ #ifdef HAVE_SYS_TYPES_H # include #endif @@ -280,18 +274,15 @@ int main(void) #endif #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK -/* includes start */ #ifdef _WIN32 # include #endif -/* includes start */ #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_SOCKET_H # include #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 #endif @@ -379,8 +369,6 @@ int main(void) #ifdef HAVE_STDATOMIC_H # include #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 #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 diff --git a/CMake/win32-cache.cmake b/CMake/win32-cache.cmake index 25323fddfc..0cb0a12bd3 100644 --- a/CMake/win32-cache.cmake +++ b/CMake/win32-cache.cmake @@ -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) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7e6b04e16..16b4a57be5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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)