]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: fix original MinGW builds
authorViktor Szakats <commit@vsz.me>
Wed, 31 Aug 2022 11:57:24 +0000 (11:57 +0000)
committerViktor Szakats <commit@vsz.me>
Wed, 31 Aug 2022 11:57:24 +0000 (11:57 +0000)
1. Re-enable `HAVE_GETADDRINFO` detection on Windows

   Commit d08ee3c83d6bd416aef62ff844c98e47c4682429 (in 2013) added logic
   that automatically assumed `getaddrinfo()` to be present for builds
   with IPv6 enabled. As it turns out, certain toolchains (e.g. original
   MinGW) by default target older Windows versions, and thus do not
   support `getaddrinfo()` out of the box. The issue was masked for
   a while by CMake builds forcing a newer Windows version, but that
   logic got deleted in commit 8ba22ffb2030ed91312fc8634e29516cdf0a9761.
   Since then, some CI builds started failing due to IPv6 enabled,
   `HAVE_GETADDRINFO` set, but `getaddrinfo()` in fact missing.

   It also turns out that IPv6 works without `getaddrinfo()` since commit
   67a08dca27a6a07b36c7f97252e284ca957ff1a5 (from 2019, via #4662). So,
   to resolve all this, we can now revert the initial commit, thus
   restoring `getaddrinfo()` detection and support IPv6 regardless of its
   outcome.

Reported-by: Daniel Stenberg
2. Omit `bcrypt` with original MinGW

   Original (aka legacy/old) MinGW versions do not support `bcrypt`
   (introduced with Vista). We already have logic to handle that in
   `lib/rand.c` and autotools builds, where we do not call the
   unsupported API and do not link `bcrypt`, respectively, when using
   original MinGW.

   This patch ports that logic to CMake, fixing the link error:
   `c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -lbcrypt`

   Ref: https://ci.appveyor.com/project/curlorg/curl/builds/44624888/job/40vle84cn4vle7s0#L508
   Regression since 76172511e7adcf720f4c77bd91f49278300ec97e

Fixes #9214
Fixes #9393
Fixes #9395
Closes #9396

CMake/Platforms/WindowsCache.cmake
CMakeLists.txt

index dc589ca9192c58a067ef46083143df21588bbe44..ad468a8f153704f53ed65d0671ff7b20a9c00854 100644 (file)
@@ -88,11 +88,6 @@ if(NOT UNIX)
     set(TIME_WITH_SYS_TIME 0)
     set(HAVE_O_NONBLOCK 0)
     set(HAVE_IN_ADDR_T 0)
-    if(ENABLE_IPV6)
-      set(HAVE_GETADDRINFO 1)
-    else()
-      set(HAVE_GETADDRINFO 0)
-    endif()
     set(STDC_HEADERS 1)
 
     set(HAVE_SIGACTION 0)
index f8cdf1aab8ebcaec30b0ba0e3c230e7693f9d98f..cb597ca8ea1fb87aab8960169792c6503c28bf21 100644 (file)
@@ -1291,7 +1291,22 @@ if(WIN32)
     list(APPEND CURL_LIBS "advapi32" "crypt32")
   endif()
 
-  list(APPEND CURL_LIBS "bcrypt")
+  # Matching logic used for Curl_win32_random()
+  if(MINGW)
+    check_c_source_compiles("
+      #include <_mingw.h>
+      #if defined(__MINGW64_VERSION_MAJOR)
+      #error
+      #endif
+      int main(void) {
+        return 0;
+      }"
+      HAVE_MINGW_ORIGINAL)
+  endif()
+
+  if(NOT HAVE_MINGW_ORIGINAL)
+    list(APPEND CURL_LIBS "bcrypt")
+  endif()
 endif()
 
 if(MSVC)