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
This commit is contained in:
James Le Cuirot 2020-04-13 14:54:15 +01:00 committed by Philip Withnall
parent 842dccfce7
commit 56271ff271
2 changed files with 28 additions and 5 deletions

View File

@ -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,

View File

@ -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