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').
This commit is contained in:
Xavier Claessens 2020-04-05 00:34:04 -04:00
parent 1a3a1865eb
commit 10280deebd
5 changed files with 33 additions and 4 deletions

View File

@ -813,6 +813,10 @@ endif
schemas_subdir = join_paths('glib-2.0', 'schemas')
libgio_dep = declare_dependency(link_with : libgio,
dependencies : [libgmodule_dep, libgobject_dep, gioenumtypes_dep],
include_directories : [gioinc])
pkg.generate(libgio,
libraries_private : [osx_ldflags],
requires : ['glib-2.0', 'gobject-2.0'],
@ -835,6 +839,11 @@ pkg.generate(libgio,
description : 'glib I/O library',
)
if meson.version().version_compare('>=0.54.0')
meson.override_dependency('gio-2.0', libgio_dep)
endif
if host_system == 'windows'
pkg.generate(requires : ['gobject-2.0', 'gmodule-no-export-2.0', 'gio-2.0'],
subdirs : ['gio-win32-2.0'],
@ -844,6 +853,9 @@ if host_system == 'windows'
name : 'GIO Windows specific APIs',
description : 'Windows specific headers for glib I/O library',
)
if meson.version().version_compare('>=0.54.0')
meson.override_dependency('gio-win32-2.0', libgio_dep)
endif
else
pkg.generate(requires : ['gobject-2.0', 'gio-2.0'],
subdirs : ['gio-unix-2.0'],
@ -853,12 +865,11 @@ else
name : 'GIO unix specific APIs',
description : 'unix specific headers for glib I/O library',
)
if meson.version().version_compare('>=0.54.0')
meson.override_dependency('gio-unix-2.0', libgio_dep)
endif
endif
libgio_dep = declare_dependency(link_with : libgio,
dependencies : [libgmodule_dep, libgobject_dep, gioenumtypes_dep],
include_directories : [gioinc])
if host_system == 'windows'
# Hack till https://github.com/mesonbuild/meson/issues/2324 is fixed
libgiounix_dep = dependency('', required : false)

View File

@ -385,6 +385,10 @@ pkg.generate(libglib,
description : 'C Utility Library',
)
if meson.version().version_compare('>=0.54.0')
meson.override_dependency('glib-2.0', libglib_dep)
endif
# On Windows, glib needs a spawn helper for g_spawn* API
if host_system == 'windows'
if host_machine.cpu_family() == 'x86'

View File

@ -120,3 +120,9 @@ pkg.generate(libraries : [libgmodule, export_dynamic_ldflags],
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

View File

@ -143,6 +143,10 @@ libgobject_dep = declare_dependency(link_with : libgobject,
include_directories : [gobjectinc],
dependencies : [libglib_dep, glib_enumtypes_dep])
if meson.version().version_compare('>=0.54.0')
meson.override_dependency('gobject-2.0', libgobject_dep)
endif
executable('gobject-query', 'gobject-query.c',
install : true,
dependencies : [libglib_dep, libgobject_dep])

View File

@ -34,3 +34,7 @@ pkg.generate(libgthread,
)
libgthread_dep = declare_dependency(link_with : libgthread)
if meson.version().version_compare('>=0.54.0')
meson.override_dependency('gthread-2.0', libgthread_dep)
endif