]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: pre-fill known type sizes for Windows OSes
authorViktor Szakats <commit@vsz.me>
Mon, 24 Feb 2025 23:01:35 +0000 (00:01 +0100)
committerViktor Szakats <commit@vsz.me>
Tue, 25 Feb 2025 15:57:13 +0000 (16:57 +0100)
To save configuration time.

After this patch, for mingw-w64 and MSVC curl's CMake builds pre-fill
almost all type sizes without auto-detection. In most cases this leaves
3 type size auto-detections. Those depend on 64/32-bitness, and `time_t`
also depends on CRT and custom options. Old mingw-w64 versions require
some extra detections. We recommend v3.0 or newer to avoid them.

For Windows CE, this patch pre-fills all type sizes.

If this is causing any issue, please report it and disable pre-filling
with `-D_CURL_PREFILL=OFF` in the meantime.

Cherry-picked from #16394
Closes #16464

CMake/Macros.cmake
CMake/win32-cache.cmake

index 8653f36b0a5a663b17c611113ca28d3a8bf13a43..fcc8f53e91012adc6a0bf21d7c89de76f0831dcf 100644 (file)
@@ -87,3 +87,10 @@ macro(curl_required_libpaths _libpaths_arg)
     list(APPEND CMAKE_REQUIRED_LINK_DIRECTORIES "${_libpaths_arg}")
   endif()
 endmacro()
+
+# Pre-fill variables set by a check_type_size() call.
+macro(curl_prefill_type_size _type _size)
+  set(HAVE_SIZEOF_${_type} TRUE)
+  set(SIZEOF_${_type} ${_size})
+  set(SIZEOF_${_type}_CODE "#define SIZEOF_${_type} ${_size}")
+endmacro()
index 05a209971d14da6385cd2a330e5c3d6c81b0f3fc..a7070dca2141afc6daa9191ef8efecb28532ccda 100644 (file)
@@ -44,10 +44,6 @@ if(MINGW)
   set(HAVE_UTIME_H 1)  # wrapper to sys/utime.h
   set(HAVE_DIRENT_H 1)
   set(HAVE_OPENDIR 1)
-  if(MINGW32CE)
-    set(HAVE_STRTOK_R 0)
-    set(HAVE_FILE_OFFSET_BITS 0)
-  endif()
 else()
   set(HAVE_LIBGEN_H 0)
   set(HAVE_FTRUNCATE 0)
@@ -78,7 +74,6 @@ else()
       set(HAVE_SNPRINTF 0)
     endif()
     set(HAVE_BASENAME 0)
-    set(HAVE_FILE_OFFSET_BITS 0)
   endif()
 endif()
 
@@ -196,6 +191,37 @@ set(STDC_HEADERS 1)
 set(HAVE_SIZEOF_SUSECONDS_T 0)
 set(HAVE_SIZEOF_SA_FAMILY_T 0)
 
+if(MINGW OR MSVC)
+  curl_prefill_type_size("INT" 4)
+  curl_prefill_type_size("LONG" 4)
+  curl_prefill_type_size("LONG_LONG" 8)
+  curl_prefill_type_size("__INT64" 8)
+  curl_prefill_type_size("CURL_OFF_T" 8)
+  # CURL_SOCKET_T, SIZE_T: 8 for _WIN64, 4 otherwise
+  # TIME_T: 8 for _WIN64 or UCRT or MSVC and not Windows CE, 4 otherwise
+  #   Also 4 for non-UCRT 32-bit when _USE_32BIT_TIME_T is set.
+  #   mingw-w64 sets _USE_32BIT_TIME_T unless __MINGW_USE_VC2005_COMPAT is explicit defined.
+  if(MSVC)
+    set(HAVE_SIZEOF_SSIZE_T 0)
+    set(HAVE_FILE_OFFSET_BITS 0)
+    curl_prefill_type_size("OFF_T" 4)
+    curl_prefill_type_size("ADDRESS_FAMILY" 2)
+  else()
+    # SSIZE_T: 8 for _WIN64, 4 otherwise
+    if(MINGW64_VERSION)
+      if(NOT MINGW64_VERSION VERSION_LESS 3.0)
+        set(HAVE_FILE_OFFSET_BITS 1)
+        curl_prefill_type_size("OFF_T" 8)
+      endif()
+      if(NOT MINGW64_VERSION VERSION_LESS 2.0)
+        curl_prefill_type_size("ADDRESS_FAMILY" 2)
+      else()
+        set(HAVE_SIZEOF_ADDRESS_FAMILY 0)
+      endif()
+    endif()
+  endif()
+endif()
+
 if(WINCE)  # Windows CE exceptions
   set(HAVE_LOCALE_H 0)
   set(HAVE_GETADDRINFO 0)
@@ -204,7 +230,15 @@ if(WINCE)  # Windows CE exceptions
   set(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 0)
   set(HAVE_SIGNAL 0)
   set(HAVE_SETMODE 0)
+  curl_prefill_type_size("CURL_SOCKET_T" 4)
+  curl_prefill_type_size("TIME_T" 4)
+  curl_prefill_type_size("SIZE_T" 4)
   if(MINGW32CE)
+    set(HAVE_STRTOK_R 0)
     set(HAVE__SETMODE 0)
+    set(HAVE_FILE_OFFSET_BITS 0)
+    set(HAVE_SIZEOF_ADDRESS_FAMILY 0)
+    curl_prefill_type_size("SSIZE_T" 4)
+    curl_prefill_type_size("OFF_T" 4)
   endif()
 endif()