From b41953d274d292ba61e1a86c86614305757827bf Mon Sep 17 00:00:00 2001 From: Frederik Seiffert Date: Fri, 6 Aug 2021 09:29:11 +0200 Subject: [PATCH] More robust check for Windows ICU Also ensure that we don't include both unicode/*.h and icu.h. --- Source/Additions/Unicode.m | 3 +- Source/GSICUString.h | 3 +- Source/NSDateFormatter.m | 7 ++--- Source/NSPredicate.m | 3 +- Source/NSRegularExpression.m | 3 +- Source/NSTimeZone.m | 3 +- configure | 54 +++++++++++++----------------------- configure.ac | 11 ++++++-- 8 files changed, 35 insertions(+), 52 deletions(-) diff --git a/Source/Additions/Unicode.m b/Source/Additions/Unicode.m index b426c55ea..7e87f76d2 100644 --- a/Source/Additions/Unicode.m +++ b/Source/Additions/Unicode.m @@ -55,8 +55,7 @@ #endif #if defined(HAVE_UNICODE_UCNV_H) #include -#endif -#if defined(HAVE_ICU_H) +#elif defined(HAVE_ICU_H) #include #endif diff --git a/Source/GSICUString.h b/Source/GSICUString.h index 0ef0604e9..ef24e0d29 100644 --- a/Source/GSICUString.h +++ b/Source/GSICUString.h @@ -3,8 +3,7 @@ #if defined(HAVE_UNICODE_UTEXT_H) #include -#endif -#if defined(HAVE_ICU_H) +#elif defined(HAVE_ICU_H) #include // icu.h in Windows 10 is missing a declaration of UTEXT_MAGIC #ifndef UTEXT_MAGIC diff --git a/Source/NSDateFormatter.m b/Source/NSDateFormatter.m index 6ff33a2d7..f79494209 100644 --- a/Source/NSDateFormatter.m +++ b/Source/NSDateFormatter.m @@ -46,15 +46,12 @@ #import "Foundation/NSDateFormatter.h" #import "Foundation/NSCoder.h" -#if defined(HAVE_UNICODE_UDAT_H) +#if defined(HAVE_UNICODE_UDAT_H) && defined(HAVE_UNICODE_UDATPG_H) #define id id_ucal #include #undef id -#endif -#if defined(HAVE_UNICODE_UDATPG_H) #include -#endif -#if defined(HAVE_ICU_H) +#elif defined(HAVE_ICU_H) #include #endif diff --git a/Source/NSPredicate.m b/Source/NSPredicate.m index 700838164..36d849c64 100644 --- a/Source/NSPredicate.m +++ b/Source/NSPredicate.m @@ -54,8 +54,7 @@ #if defined(HAVE_UNICODE_UREGEX_H) #include -#endif -#if defined(HAVE_ICU_H) +#elif defined(HAVE_ICU_H) #include #endif diff --git a/Source/NSRegularExpression.m b/Source/NSRegularExpression.m index fb6ac4c56..bfb3cb55a 100644 --- a/Source/NSRegularExpression.m +++ b/Source/NSRegularExpression.m @@ -29,8 +29,7 @@ #if GS_USE_ICU == 1 #if defined(HAVE_UNICODE_UREGEX_H) #include -#endif -#if defined(HAVE_ICU_H) +#elif defined(HAVE_ICU_H) #include #endif diff --git a/Source/NSTimeZone.m b/Source/NSTimeZone.m index 8f60528e0..d4b6e4124 100644 --- a/Source/NSTimeZone.m +++ b/Source/NSTimeZone.m @@ -120,8 +120,7 @@ #define id id_ucal #include #undef id -#endif -#if defined(HAVE_ICU_H) +#elif defined(HAVE_ICU_H) #include #endif diff --git a/configure b/configure index 3273f8961..fb66d9f96 100755 --- a/configure +++ b/configure @@ -13242,6 +13242,8 @@ if test "x$enable_icu" = "xyes"; then : case "$target_os" in mingw*|windows) # check for ICU bundled with Windows 10 + old_LIBS="$LIBS" + LIBS="-licu $LIBS" for ac_header in icu.h do : ac_fn_c_check_header_mongrel "$LINENO" "icu.h" "ac_cv_header_icu_h" "$ac_includes_default" @@ -13249,54 +13251,36 @@ if test "x$ac_cv_header_icu_h" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_ICU_H 1 _ACEOF - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for udat_open in -licu" >&5 -$as_echo_n "checking for udat_open in -licu... " >&6; } -if ${ac_cv_lib_icu_udat_open+:} false; then : - $as_echo_n "(cached) " >&6 + if test "$cross_compiling" = yes; then : + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot run test program while cross compiling +See \`config.log' for more details" "$LINENO" 5; } else - ac_check_lib_save_LIBS=$LIBS -LIBS="-licu $LIBS" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -/* Override any GCC internal prototype to avoid an error. - Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char udat_open (); -int -main () -{ -return udat_open (); - ; - return 0; -} + #include + int main () { + return udat_countAvailable() > 0 ? 0 : 1; + } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : - ac_cv_lib_icu_udat_open=yes -else - ac_cv_lib_icu_udat_open=no -fi -rm -f core conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_icu_udat_open" >&5 -$as_echo "$ac_cv_lib_icu_udat_open" >&6; } -if test "x$ac_cv_lib_icu_udat_open" = xyes; then : +if ac_fn_c_try_run "$LINENO"; then : HAVE_ICU=1 fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi fi done + LIBS="$old_LIBS" if test $HAVE_ICU = 1; then ICU_LIBS=-licu - { $as_echo "$as_me:${as_lineno-$LINENO}: Using ICU DLL from Windows 10 (requires version 1903 or later)" >&5 -$as_echo "$as_me: Using ICU DLL from Windows 10 (requires version 1903 or later)" >&6;} + { $as_echo "$as_me:${as_lineno-$LINENO}: Using system-provided ICU DLL (requires Windows 10 version 1903 or later)" >&5 +$as_echo "$as_me: Using system-provided ICU DLL (requires Windows 10 version 1903 or later)" >&6;} fi ;; esac diff --git a/configure.ac b/configure.ac index fcf80bc62..a20023dfe 100644 --- a/configure.ac +++ b/configure.ac @@ -3496,11 +3496,18 @@ AS_IF([test "x$enable_icu" = "xyes"], [ case "$target_os" in mingw*|windows) # check for ICU bundled with Windows 10 + old_LIBS="$LIBS" + LIBS="-licu $LIBS" AC_CHECK_HEADERS([icu.h], - AC_CHECK_LIB(icu, udat_open, HAVE_ICU=1)) + AC_RUN_IFELSE([AC_LANG_SOURCE([ + #include + int main () { + return udat_countAvailable() > 0 ? 0 : 1; + }])], HAVE_ICU=1)) + LIBS="$old_LIBS" if test $HAVE_ICU = 1; then ICU_LIBS=-licu - AC_MSG_NOTICE([Using ICU DLL from Windows 10 (requires version 1903 or later)]) + AC_MSG_NOTICE([Using system-provided ICU DLL (requires Windows 10 version 1903 or later)]) fi ;; esac