cmake: fix builds with detected libidn2 lib but undetected header

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
This commit is contained in:
Viktor Szakats 2024-07-13 13:06:33 +02:00
parent 3765d75ce4
commit 764fbabf6e
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201

View 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)