]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: fix builds with detected libidn2 lib but undetected header
authorViktor Szakats <commit@vsz.me>
Sat, 13 Jul 2024 11:06:33 +0000 (13:06 +0200)
committerViktor Szakats <commit@vsz.me>
Sun, 14 Jul 2024 07:42:34 +0000 (09:42 +0200)
It caused IDN to appear in `curl-config`, `libidn2` referenced from
`libcurl.pc`, fail to fallback to `pkg-config` detection. But libidn2
not actually used.

It came up in macOS CI builds after enabling cmake build tests. It
remained hidden for a while due to setting `-DUSE_APPLE_IDN=ON`.

(The half-detection of Homebrew libidn2 was the result of configuring
with `-DCMAKE_EXE_LINKER_FLAGS=-L$(brew --prefix)/lib`, to fix
linking GnuTLS that needs the `nettle` lib from the brew prefix.)

```
FAIL 1014: [Compare curl --version with curl-config --features] curl-config
```
Ref: https://github.com/curl/curl/actions/runs/9919357748/job/27405080722

Cherry-picked from #14097
Closes #14175

CMakeLists.txt

index 27a130c1519c2e2bc1c38c1277b55b8914e931a8..60279e04a0446d53bd945fefb7efd17073f75a21 100644 (file)
@@ -912,7 +912,8 @@ if(USE_LIBIDN2)
   if(HAVE_LIBIDN2)
     set(LIBIDN2_LINK_LIBRARIES "idn2")
     check_include_file_concat("idn2.h" HAVE_IDN2_H)
-  else()
+  endif()
+  if(NOT HAVE_LIBIDN2 OR NOT HAVE_IDN2_H)
     find_package(PkgConfig QUIET)
     pkg_check_modules(LIBIDN2 "libidn2")
     if(LIBIDN2_FOUND)
@@ -921,7 +922,7 @@ if(USE_LIBIDN2)
       set(HAVE_IDN2_H ON)
     endif()
   endif()
-  if(HAVE_LIBIDN2)
+  if(HAVE_LIBIDN2 AND HAVE_IDN2_H)
     set(CURL_LIBS "${LIBIDN2_LINK_LIBRARIES};${CURL_LIBS}")
     set(LIBCURL_PC_REQUIRES_PRIVATE "libidn2;${LIBCURL_PC_REQUIRES_PRIVATE}")
   endif()
@@ -1727,7 +1728,9 @@ if(NOT CURL_DISABLE_INSTALL)
   _add_if("gsasl"         USE_GSASL)
   _add_if("zstd"          HAVE_ZSTD)
   _add_if("AsynchDNS"     USE_ARES OR USE_THREADS_POSIX OR USE_THREADS_WIN32)
-  _add_if("IDN"           HAVE_LIBIDN2 OR USE_WIN32_IDN OR USE_APPLE_IDN)
+  _add_if("IDN"           (HAVE_LIBIDN2 AND HAVE_IDN2_H) OR
+                          USE_WIN32_IDN OR
+                          USE_APPLE_IDN)
   _add_if("Largefile"     (SIZEOF_CURL_OFF_T GREATER 4) AND
                           ((SIZEOF_OFF_T GREATER 4) OR USE_WIN32_LARGE_FILES))
   _add_if("SSPI"          USE_WINDOWS_SSPI)