glib/gmodule/meson.build
Xavier Claessens 10280deebd Meson: Override every dependency glib provides
Meson 0.54.0 added a new method meson.override_dependency() that must be
used to ensure dependency consistency. This patch ensures a project that
depends on glib will never link to a mix of system and subproject
libraries. It would happen in such cases:

The system has glib 2.40 installed, and a project does:
dependency('glib-2.0', version: '>=2.60',
  fallback: ['glib', 'glib_dep'])
dependency('gobject-2.0')

The first call will configure glib subproject because the system libglib
is too old, but the 2nd call will return system libgobject.

By overriding 'gobject-2.0' dependency while configuring glib subproject
during the first call, meson knows that on the 2nd call it must return
the subproject dependency instead of system dependency.

This also has the nice side effect that with Meson >0.54.0 an
application depending on glib can declare the fallback without knowing
the dependency variable name: dependency('glib-2.0', fallback: 'glib').
2020-04-05 00:34:04 -04:00

129 lines
4.1 KiB
Meson

gmoduleconf_conf = configuration_data()
g_module_need_uscore = 0
g_module_broken_rtld_global = 0
g_module_have_dlerror = 0
g_module_impl = ''
# On Windows force native WIN32 shared lib loader
if host_system == 'windows'
g_module_impl = 'G_MODULE_IMPL_WIN32'
# Force native AIX library loader
# dlopen() filepath must be of the form /path/libname.a(libname.so)
elif host_system == 'aix'
g_module_impl = 'G_MODULE_IMPL_AR'
elif have_dlopen_dlsym
g_module_impl = 'G_MODULE_IMPL_DL'
endif
# additional checks for G_MODULE_IMPL_DL
if g_module_impl == 'G_MODULE_IMPL_DL'
# FIXME: check for OSF1/5.0 RTLD_GLOBAL brokenness (is this still relevant?)
# Check whether we need preceding underscores
if cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl'
message('Building for MSVC: assuming that symbols are prefixed with underscore')
g_module_need_uscore = 1
elif meson.has_exe_wrapper()
# FIXME: communicate result via stdout instead of return value, so non-0 return is not printed in bold red
rres = cc.run(dlopen_dlsym_test_code,
dependencies : libdl_dep,
name : 'dlsym() preceding underscores')
if host_system == 'windows' or rres.returncode() == 0
g_module_need_uscore = 1
endif
else
message('Cross-compiling: assuming that symbols aren\'t prefixed with underscore')
g_module_need_uscore = 0
endif
if cc.has_function('dlerror', dependencies : libdl_dep)
g_module_have_dlerror = 1
endif
endif
# Done, have we got an implementation?
if g_module_impl == ''
g_module_impl = '0'
message('WARNING: No suitable GModule implementation found!')
endif
gmoduleconf_conf.set('G_MODULE_IMPL', g_module_impl)
gmoduleconf_conf.set('G_MODULE_SUPPORTED', g_module_impl != '0')
gmoduleconf_conf.set('G_MODULE_HAVE_DLERROR', g_module_have_dlerror)
gmoduleconf_conf.set('G_MODULE_NEED_USCORE', g_module_need_uscore)
gmoduleconf_conf.set('G_MODULE_BROKEN_RTLD_GLOBAL', g_module_broken_rtld_global)
gmoduleconf_h = configure_file(input : 'gmoduleconf.h.in',
output : 'gmoduleconf.h',
configuration : gmoduleconf_conf)
install_headers(['gmodule.h'], subdir : 'glib-2.0')
gmodule_sources = ['gmodule.c']
if host_system == 'windows'
gmodule_win_rc = configure_file(
input: 'gmodule.rc.in',
output: 'gmodule.rc',
configuration: glibconfig_conf,
)
gmodule_win_res = windows.compile_resources(gmodule_win_rc)
gmodule_sources += [gmodule_win_res]
endif
libgmodule = library('gmodule-2.0',
sources : gmodule_sources,
version : library_version,
soversion : soversion,
darwin_versions : darwin_versions,
install : true,
include_directories : [configinc, gmoduleinc],
dependencies : [libdl_dep, libglib_dep],
c_args : ['-DG_LOG_DOMAIN="GModule"'] + glib_hidden_visibility_args,
link_args : [glib_link_flags],
)
supported_var = 'gmodule_supported=@0@'.format(g_module_impl != '0')
pkg.generate(libgmodule,
libraries : [thread_dep],
requires : ['glib-2.0'],
version : glib_version,
variables : [supported_var],
install_dir : glib_pkgconfigreldir,
filebase : 'gmodule-no-export-2.0',
name : 'GModule',
description : 'Dynamic module loader for GLib',
)
pkg.generate(libraries : [libgmodule, export_dynamic_ldflags],
requires : ['glib-2.0'],
version : glib_version,
variables : [supported_var],
install_dir : glib_pkgconfigreldir,
filebase : 'gmodule-export-2.0',
name : 'GModule',
description : 'Dynamic module loader for GLib',
)
pkg.generate(libraries : [libgmodule, export_dynamic_ldflags],
requires : ['glib-2.0'],
version : glib_version,
variables : [supported_var],
install_dir : glib_pkgconfigreldir,
filebase : 'gmodule-2.0',
name : 'GModule',
description : 'Dynamic module loader for GLib',
)
libgmodule_dep = declare_dependency(link_with : libgmodule,
include_directories : [gmoduleinc],
dependencies : [libglib_dep])
if meson.version().version_compare('>=0.54.0')
meson.override_dependency('gmodule-no-export-2.0', libgmodule_dep)
meson.override_dependency('gmodule-export-2.0', libgmodule_dep)
meson.override_dependency('gmodule-2.0', libgmodule_dep)
endif