[glib: 2/3] meson: Fix underlinking of static libintl by trying iconv and pthread



commit 56271ff27119f0b6b7dc6cc0c081d64bec06b473
Author: James Le Cuirot <chewi gentoo org>
Date:   Mon Apr 13 14:54:15 2020 +0100

    meson: Fix underlinking of static libintl by trying iconv and pthread
    
    I thought about checking for an intl pkg-config file but upstream are
    not interested in adding one so there seems little point.
    
    Closes #1851

 glib/meson.build |  6 +++---
 meson.build      | 27 +++++++++++++++++++++++++--
 2 files changed, 28 insertions(+), 5 deletions(-)
---
diff --git a/glib/meson.build b/glib/meson.build
index c1abbef62..383a4cacb 100644
--- a/glib/meson.build
+++ b/glib/meson.build
@@ -356,19 +356,19 @@ libglib = library('glib-2.0',
   # intl.lib is not compatible with SAFESEH
   link_args : [noseh_link_args, glib_link_flags, win32_ldflags],
   include_directories : configinc,
-  dependencies : pcre_deps + [thread_dep, libintl, librt] + libiconv + platform_deps + 
gnulib_libm_dependency,
+  dependencies : pcre_deps + [thread_dep, librt] + libintl_deps + libiconv + platform_deps + 
gnulib_libm_dependency,
   c_args : glib_c_args,
   objc_args : glib_c_args,
 )
 
 libglib_dep = declare_dependency(
   link_with : libglib,
-  dependencies : libintl,
+  dependencies : libintl_deps,
   # We sadly need to export configinc here because everyone includes <glib/*.h>
   include_directories : [configinc, glibinc])
 
 pkg.generate(libglib,
-  libraries : [libintl],
+  libraries : [libintl_deps],
   libraries_private : [osx_ldflags, win32_ldflags],
   subdirs : ['glib-2.0'],
   extra_cflags : ['-I${libdir}/glib-2.0/include'] + win32_cflags,
diff --git a/meson.build b/meson.build
index c9437aeb6..00f767ef9 100644
--- a/meson.build
+++ b/meson.build
@@ -1926,17 +1926,40 @@ endif
 # proxy-libintl subproject.
 # 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')
-  libintl = []
   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
   else
+    libintl_deps = [libintl] + libintl_deps
     have_bind_textdomain_codeset = cc.has_function('bind_textdomain_codeset',
-                                                   dependencies : libintl)
+                                                   dependencies : libintl_deps)
   endif
 endif
 


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