build: check OS-native IDN first, then libidn2

If AppleIDN or WinIDN is selected, don't look for libidn2. Do this by
moving libidn2 detection after AppleIDN/WinIDN and skipping it if any
of them was selected.

Also:
- disable AppleIDN by default with autotools to sync behaviour with
  CMake.
- limit WinIDN checks to native Windows with autotools, as with CMake.

Before this patch libidn2 was detected by default even if AppleIDN or
WinIDN was explicitly selected. libidn2 wasn't used in the build, but
it was left enabled as a dependency and appeared in `libcurl.pc` and
`curl-config`.

Closes #14674
This commit is contained in:
Viktor Szakats 2024-08-24 21:14:02 +02:00
parent 3307b98139
commit 7673c12929
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
2 changed files with 156 additions and 148 deletions

View File

@ -1002,31 +1002,13 @@ if(CURL_DISABLE_LDAP)
endif()
endif()
# Check for libidn2
option(USE_LIBIDN2 "Use libidn2 for IDN support" ON)
if(USE_LIBIDN2)
find_package(Libidn2)
if(LIBIDN2_FOUND)
set(CURL_LIBS "${LIBIDN2_LIBRARIES};${CURL_LIBS}")
list(APPEND CURL_LIBDIRS ${LIBIDN2_LIBRARY_DIRS})
set(LIBCURL_PC_REQUIRES_PRIVATE "libidn2;${LIBCURL_PC_REQUIRES_PRIVATE}")
include_directories(${LIBIDN2_INCLUDE_DIRS})
link_directories(${LIBIDN2_LIBRARY_DIRS})
if(LIBIDN2_CFLAGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBIDN2_CFLAGS}")
endif()
set(HAVE_IDN2_H 1)
set(HAVE_LIBIDN2 1)
endif()
else()
set(HAVE_LIBIDN2 OFF)
endif()
if(WIN32)
option(USE_WIN32_IDN "Use WinIDN for IDN support" OFF)
if(USE_WIN32_IDN)
list(APPEND CURL_LIBS "normaliz")
endif()
else()
set(USE_WIN32_IDN OFF)
endif()
if(APPLE)
@ -1042,6 +1024,28 @@ if(APPLE)
set(USE_APPLE_IDN OFF)
endif()
endif()
else()
set(USE_APPLE_IDN OFF)
endif()
# Check for libidn2
option(USE_LIBIDN2 "Use libidn2 for IDN support" ON)
set(HAVE_IDN2_H OFF)
set(HAVE_LIBIDN2 OFF)
if(USE_LIBIDN2 AND NOT USE_APPLE_IDN AND NOT USE_WIN32_IDN)
find_package(Libidn2)
if(LIBIDN2_FOUND)
set(CURL_LIBS "${LIBIDN2_LIBRARIES};${CURL_LIBS}")
list(APPEND CURL_LIBDIRS ${LIBIDN2_LIBRARY_DIRS})
set(LIBCURL_PC_REQUIRES_PRIVATE "libidn2;${LIBCURL_PC_REQUIRES_PRIVATE}")
include_directories(${LIBIDN2_INCLUDE_DIRS})
link_directories(${LIBIDN2_LIBRARY_DIRS})
if(LIBIDN2_CFLAGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBIDN2_CFLAGS}")
endif()
set(HAVE_IDN2_H 1)
set(HAVE_LIBIDN2 1)
endif()
endif()
# libpsl

View File

@ -2584,102 +2584,141 @@ fi
AM_CONDITIONAL([USE_UNICODE], [test "$want_winuni" = "yes"])
dnl -------------------------------------------------
dnl check winidn option before other IDN libraries
dnl check WinIDN option before other IDN libraries
dnl -------------------------------------------------
AC_MSG_CHECKING([whether to enable Windows native IDN (Windows native builds only)])
OPT_WINIDN="default"
AC_ARG_WITH(winidn,
AS_HELP_STRING([--with-winidn=PATH],[enable Windows native IDN])
AS_HELP_STRING([--without-winidn], [disable Windows native IDN]),
OPT_WINIDN=$withval)
case "$OPT_WINIDN" in
no|default)
dnl --without-winidn option used or configure option not specified
want_winidn="no"
AC_MSG_RESULT([no])
;;
yes)
dnl --with-winidn option used without path
want_winidn="yes"
want_winidn_path="default"
AC_MSG_RESULT([yes])
;;
*)
dnl --with-winidn option used with path
want_winidn="yes"
want_winidn_path="$withval"
AC_MSG_RESULT([yes ($withval)])
;;
esac
tst_links_winidn='no'
if test "$curl_cv_native_windows" = 'yes'; then
AC_MSG_CHECKING([whether to enable Windows native IDN (Windows native builds only)])
OPT_WINIDN="default"
AC_ARG_WITH(winidn,
AS_HELP_STRING([--with-winidn=PATH],[enable Windows native IDN])
AS_HELP_STRING([--without-winidn], [disable Windows native IDN]),
OPT_WINIDN=$withval)
case "$OPT_WINIDN" in
no|default)
dnl --without-winidn option used or configure option not specified
want_winidn="no"
AC_MSG_RESULT([no])
;;
yes)
dnl --with-winidn option used without path
want_winidn="yes"
want_winidn_path="default"
AC_MSG_RESULT([yes])
;;
*)
dnl --with-winidn option used with path
want_winidn="yes"
want_winidn_path="$withval"
AC_MSG_RESULT([yes ($withval)])
;;
esac
if test "$want_winidn" = "yes"; then
dnl WinIDN library support has been requested
clean_CFLAGS="$CFLAGS"
clean_CPPFLAGS="$CPPFLAGS"
clean_LDFLAGS="$LDFLAGS"
clean_LIBS="$LIBS"
WINIDN_LIBS="-lnormaliz"
WINIDN_CPPFLAGS=""
#
if test "$want_winidn_path" != "default"; then
dnl path has been specified
dnl pkg-config not available or provides no info
WINIDN_LDFLAGS="-L$want_winidn_path/lib$libsuff"
WINIDN_CPPFLAGS="-I$want_winidn_path/include"
WINIDN_DIR="$want_winidn_path/lib$libsuff"
fi
#
dnl WinIDN requires a minimum supported OS version of at least Vista (0x0600)
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
#include <windows.h>
]],[[
#if (WINVER < 0x600) && (_WIN32_WINNT < 0x600)
#error
#endif
]])
],[
],[
CFLAGS=`echo $CFLAGS | $SED -e 's/-DWINVER=[[^ ]]*//g'`
CFLAGS=`echo $CFLAGS | $SED -e 's/-D_WIN32_WINNT=[[^ ]]*//g'`
CPPFLAGS=`echo $CPPFLAGS | $SED -e 's/-DWINVER=[[^ ]]*//g'`
CPPFLAGS=`echo $CPPFLAGS | $SED -e 's/-D_WIN32_WINNT=[[^ ]]*//g'`
WINIDN_CPPFLAGS="$WINIDN_CPPFLAGS -DWINVER=0x0600"
])
#
CPPFLAGS="$CPPFLAGS $WINIDN_CPPFLAGS"
LDFLAGS="$LDFLAGS $WINIDN_LDFLAGS"
LIBS="$WINIDN_LIBS $LIBS"
#
AC_MSG_CHECKING([if IdnToUnicode can be linked])
AC_LINK_IFELSE([
AC_LANG_PROGRAM([[
#include <windows.h>
]],[[
IdnToUnicode(0, NULL, 0, NULL, 0);
]])
],[
AC_MSG_RESULT([yes])
tst_links_winidn="yes"
],[
AC_MSG_RESULT([no])
tst_links_winidn="no"
])
#
if test "$tst_links_winidn" = "yes"; then
AC_DEFINE(USE_WIN32_IDN, 1, [Define to 1 if you have the `normaliz' (WinIDN) library (-lnormaliz).])
AC_SUBST([IDN_ENABLED], [1])
curl_idn_msg="enabled (Windows-native)"
else
AC_MSG_WARN([Cannot find libraries for IDN support: IDN disabled])
CFLAGS="$clean_CFLAGS"
CPPFLAGS="$clean_CPPFLAGS"
LDFLAGS="$clean_LDFLAGS"
LIBS="$clean_LIBS"
if test "$want_winidn" = "yes"; then
dnl WinIDN library support has been requested
clean_CFLAGS="$CFLAGS"
clean_CPPFLAGS="$CPPFLAGS"
clean_LDFLAGS="$LDFLAGS"
clean_LIBS="$LIBS"
WINIDN_LIBS="-lnormaliz"
WINIDN_CPPFLAGS=""
#
if test "$want_winidn_path" != "default"; then
dnl path has been specified
dnl pkg-config not available or provides no info
WINIDN_LDFLAGS="-L$want_winidn_path/lib$libsuff"
WINIDN_CPPFLAGS="-I$want_winidn_path/include"
WINIDN_DIR="$want_winidn_path/lib$libsuff"
fi
#
dnl WinIDN requires a minimum supported OS version of at least Vista (0x0600)
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
#include <windows.h>
]],[[
#if (WINVER < 0x600) && (_WIN32_WINNT < 0x600)
#error
#endif
]])
],[
],[
CFLAGS=`echo $CFLAGS | $SED -e 's/-DWINVER=[[^ ]]*//g'`
CFLAGS=`echo $CFLAGS | $SED -e 's/-D_WIN32_WINNT=[[^ ]]*//g'`
CPPFLAGS=`echo $CPPFLAGS | $SED -e 's/-DWINVER=[[^ ]]*//g'`
CPPFLAGS=`echo $CPPFLAGS | $SED -e 's/-D_WIN32_WINNT=[[^ ]]*//g'`
WINIDN_CPPFLAGS="$WINIDN_CPPFLAGS -DWINVER=0x0600"
])
#
CPPFLAGS="$CPPFLAGS $WINIDN_CPPFLAGS"
LDFLAGS="$LDFLAGS $WINIDN_LDFLAGS"
LIBS="$WINIDN_LIBS $LIBS"
#
AC_MSG_CHECKING([if IdnToUnicode can be linked])
AC_LINK_IFELSE([
AC_LANG_PROGRAM([[
#include <windows.h>
]],[[
IdnToUnicode(0, NULL, 0, NULL, 0);
]])
],[
AC_MSG_RESULT([yes])
tst_links_winidn="yes"
],[
AC_MSG_RESULT([no])
tst_links_winidn="no"
])
#
if test "$tst_links_winidn" = "yes"; then
AC_DEFINE(USE_WIN32_IDN, 1, [Define to 1 if you have the `normaliz' (WinIDN) library (-lnormaliz).])
AC_SUBST([IDN_ENABLED], [1])
curl_idn_msg="enabled (Windows-native)"
else
AC_MSG_WARN([Cannot find libraries for IDN support: IDN disabled])
CFLAGS="$clean_CFLAGS"
CPPFLAGS="$clean_CPPFLAGS"
LDFLAGS="$clean_LDFLAGS"
LIBS="$clean_LIBS"
fi
fi
fi
dnl **********************************************************************
dnl Check for the presence of AppleIDN
dnl **********************************************************************
tst_links_appleidn='no'
case $host_os in
darwin*)
AC_MSG_CHECKING([whether to build with Apple IDN])
OPT_IDN="default"
AC_ARG_WITH(apple-idn,
AS_HELP_STRING([--with-apple-idn],[Enable AppleIDN])
AS_HELP_STRING([--without-apple-idn],[Disable AppleIDN]),
[OPT_IDN=$withval])
case "$OPT_IDN" in
yes)
dnl --with-apple-idn option used
AC_MSG_RESULT([yes, check])
AC_CHECK_LIB(icucore, uidna_openUTS46,
[
AC_CHECK_HEADERS(unicode/uidna.h,
curl_idn_msg="enabled (AppleIDN)"
AC_DEFINE(USE_APPLE_IDN, 1, [if AppleIDN])
AC_SUBST(USE_APPLE_IDN, [1])
AC_SUBST([IDN_ENABLED], [1])
LIBS="-licucore -liconv $LIBS"
tst_links_appleidn='yes'
)
])
;;
*)
AC_MSG_RESULT([no])
;;
esac
;;
esac
dnl **********************************************************************
dnl Check for the presence of libidn2
dnl **********************************************************************
@ -2693,6 +2732,9 @@ AS_HELP_STRING([--without-libidn2],[Disable libidn2 usage]),
if test "x$tst_links_winidn" = "xyes"; then
want_idn="no"
AC_MSG_RESULT([no (using WinIDN instead)])
elif test "x$tst_links_appleidn" = "xyes"; then
want_idn="no"
AC_MSG_RESULT([no (using AppleIDN instead)])
else
case "$OPT_IDN" in
no)
@ -2811,44 +2853,6 @@ if test "$want_idn" = "yes"; then
fi
fi
dnl **********************************************************************
dnl Check for the presence of AppleIDN
dnl **********************************************************************
case $host_os in
darwin*)
AC_MSG_CHECKING([whether to build with Apple IDN])
OPT_IDN="default"
AC_ARG_WITH(apple-idn,
AS_HELP_STRING([--with-apple-idn],[Enable AppleIDN])
AS_HELP_STRING([--without-apple-idn],[Disable AppleIDN]),
[OPT_IDN=$withval])
if test "x$want_idn" != "xno" -a "x$OPT_IDN" != "xyes"; then
want_appleidn="no"
else
case "$OPT_IDN" in
no)
dnl --without-apple-idn option used
AC_MSG_RESULT([no])
;;
*)
AC_MSG_RESULT([yes, check])
AC_CHECK_LIB(icucore, uidna_openUTS46,
[
AC_CHECK_HEADERS(unicode/uidna.h,
curl_idn_msg="enabled (AppleIDN)"
AC_DEFINE(USE_APPLE_IDN, 1, [if AppleIDN])
AC_SUBST(USE_APPLE_IDN, [1])
AC_SUBST([IDN_ENABLED], [1])
LIBS="-licucore -liconv $LIBS"
)
])
;;
esac
fi
;;
esac
dnl **********************************************************************
dnl Check for nghttp2
dnl **********************************************************************