[glib: 2/4] meson: simplify intl lookups using Meson's builtin dependency lookup




commit 26435b570f0f55620cc7048f8ee718cce5f90734
Author: Eli Schwartz <eschwartz archlinux org>
Date:   Tue May 24 15:26:04 2022 -0400

    meson: simplify intl lookups using Meson's builtin dependency lookup
    
    intl is complicated to look up. Some of that complexity now resides in
    Meson, since 0.59.0, via a `dependency('intl')` lookup, so use that
    instead.
    
    The Meson lookup doesn't include all the checks here, but likewise this
    meson.build doesn't include all the checks in Meson. Particularly, the
    following are different:
    
    - Meson accurately detects support built into libc, even if that
      conflicts with an external library version (which should be detected as
      broken and thus not-found, but glib does not do so).
    
      The problem here is that depending on which libintl.h header is first
      in the search path, the *gettext symbols may be the libc ABI, or they
      may be renamed to libintl_*gettext, then additionally take over the
      *gettext names via a macro, in order to invoke the external library
      version even on systems where there is a libc builtin. This means that
      checking for `cc.has_function()` correctly reports that there is such
      a function in libc, but that unfortunately does not mean it is usable,
      because source code referencing `ngettext` etc. will expect to be
      linked to `libintl_ngettext`.
    
    - glib checks whether the found intl requires pthread, rather than
      simply trusting the result of `cc.find_library()` for the external
      library case.
    
    Do the heavy lifting by using Meson to check for intl, and select the
    correct implementation, but do a post-discovery check if the symbol is
    linkable both with/without pthread.
    
    The logic is still a bit hairy, and eventually more of the logic could
    be moved into Meson. But it's better than before.
    
    Fixes incorrect detection of intl on musl-based systems (which have a
    less capable libc intl), when GNU libintl is installed as an external
    library.

 meson.build | 59 +++++++++++++++++++++++++++--------------------------------
 1 file changed, 27 insertions(+), 32 deletions(-)
---
diff --git a/meson.build b/meson.build
index 424aede80c..172a9a038f 100644
--- a/meson.build
+++ b/meson.build
@@ -2030,42 +2030,37 @@ libz_dep = dependency('zlib')
 # FIXME: glib-gettext.m4 has much more checks to detect broken/uncompatible
 # implementations. This could be extended if issues are found in some platforms.
 libintl_deps = []
-if cc.has_function('ngettext')
-  have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset')
-else
-  # First just find the bare library.
-  libintl = cc.find_library('intl', required : false)
-  # The bare library probably won't link without help if it's static.
-  if libintl.found() and not cc.has_function('ngettext', dependencies : libintl)
-     libintl_iconv = cc.find_library('iconv', required : false)
-     # libintl supports different threading APIs, which may not
-     # require additional flags, but it defaults to using pthreads if
-     # found. Meson's "threads" dependency does not allow you to
-     # prefer pthreads. We may not be using pthreads for glib itself
-     # either so just link the library to satisfy libintl rather than
-     # also defining the macros with the -pthread flag.
-     libintl_pthread = cc.find_library('pthread', required : false)
-     # Try linking with just libiconv.
-     if libintl_iconv.found() and cc.has_function('ngettext', dependencies : [libintl, libintl_iconv])
-       libintl_deps += [libintl_iconv]
-     # Then also try linking with pthreads.
-     elif libintl_iconv.found() and libintl_pthread.found() and cc.has_function('ngettext', dependencies : 
[libintl, libintl_iconv, libintl_pthread])
-       libintl_deps += [libintl_iconv, libintl_pthread]
-     else
-       libintl = disabler()
-     endif
-  endif
-  if not libintl.found()
-    libintl = subproject('proxy-libintl').get_variable('intl_dep')
-    libintl_deps = [libintl] + libintl_deps
-    have_bind_textdomain_codeset = true  # proxy-libintl supports it
+libintl = dependency('intl', required: false)
+if libintl.found()
+  # libintl supports different threading APIs, which may not
+  # require additional flags, but it defaults to using pthreads if
+  # found. Meson's "threads" dependency does not allow you to
+  # prefer pthreads. We may not be using pthreads for glib itself
+  # either so just link the library to satisfy libintl rather than
+  # also defining the macros with the -pthread flag.
+  #
+  # Meson's builtin dependency lookup as of 0.60.0 doesn't check for
+  # pthread, so we do this manually here.
+  if cc.has_function('ngettext', dependencies : libintl)
+    libintl_deps += [libintl]
   else
-    libintl_deps = [libintl] + libintl_deps
-    have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset', 
-                                                   dependencies : libintl_deps)
+    libintl_pthread = cc.find_library('pthread', required : false)
+    if libintl_pthread.found() and cc.has_function('ngettext', dependencies : [libintl, libintl_pthread])
+      libintl_deps += [libintl, libintl_pthread]
+    else
+      libintl = disabler()
+    endif
   endif
 endif
 
+if libintl.found()
+  have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset', dependencies: libintl_deps)
+else
+  libintl = subproject('proxy-libintl').get_variable('intl_dep')
+  libintl_deps = [libintl]
+  have_bind_textdomain_codeset = true  # proxy-libintl supports it
+endif
+
 glib_conf.set('HAVE_BIND_TEXTDOMAIN_CODESET', have_bind_textdomain_codeset)
 
 # We require gettext to always be present


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]