meson: Move libdl_dep to the top level

Instead of letting each directory to find its way to link with libdl,
it is easier to put the check in the top level, so its result can be
used by all directories.

It is a follow-up of https://gitlab.gnome.org/GNOME/glib/merge_requests/810.
This commit is contained in:
Ting-Wei Lan 2019-08-29 23:19:08 +08:00
parent e0e4968dca
commit fe3c16608a
3 changed files with 26 additions and 27 deletions

View File

@ -140,17 +140,13 @@ if host_machine.system() != 'windows'
}
if have_rtld_next
# FIXME: This list will probably grow; see
# https://gitlab.gnome.org/GNOME/glib/issues/1739
no_libdl_systems = ['freebsd', 'netbsd', 'openbsd']
gio_tests += {
'gsocketclient-slow' : {
'depends' : [
shared_library('slow-connect-preload',
'slow-connect-preload.c',
name_prefix : '',
dependencies: cc.find_library('dl', required: not no_libdl_systems.contains(host_machine.system())),
dependencies: libdl_dep,
install_dir : installed_tests_execdir,
install: installed_tests_enabled,
)

View File

@ -4,23 +4,8 @@ g_module_need_uscore = 0
g_module_broken_rtld_global = 0
g_module_have_dlerror = 0
libdl_dep = [ ]
g_module_lib_args = [ ]
g_module_impl = ''
dlopen_dlsym_test_code = '''
#include <dlfcn.h>
int glib_underscore_test (void) { return 42; }
int main (int argc, char ** argv) {
void *f1 = (void*)0, *f2 = (void*)0, *handle;
handle = dlopen ((void*)0, 0);
if (handle) {
f1 = dlsym (handle, "glib_underscore_test");
f2 = dlsym (handle, "_glib_underscore_test");
}
return (!f2 || f1);
}'''
# On Windows force native WIN32 shared lib loader
if host_system == 'windows'
g_module_impl = 'G_MODULE_IMPL_WIN32'
@ -28,16 +13,12 @@ if host_system == 'windows'
# dlopen() filepath must be of the form /path/libname.a(libname.so)
elif host_system == 'aix'
g_module_impl = 'G_MODULE_IMPL_AR'
elif cc.links(dlopen_dlsym_test_code, name : 'dlopen() and dlsym() in system libraries')
g_module_impl = 'G_MODULE_IMPL_DL'
# NSLinkModule (dyld) in system libraries (Darwin)
elif cc.has_function('NSLinkModule')
g_module_impl = 'G_MODULE_IMPL_DYLD'
g_module_need_uscore = 1
elif cc.links(dlopen_dlsym_test_code, args : '-ldl', name : 'dlopen() and dlsym() in libdl')
elif have_dlopen_dlsym
g_module_impl = 'G_MODULE_IMPL_DL'
libdl_dep = cc.find_library('dl')
g_module_lib_args = '-ldl'
endif
# additional checks for G_MODULE_IMPL_DL
@ -51,7 +32,7 @@ if g_module_impl == 'G_MODULE_IMPL_DL'
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,
args : g_module_lib_args,
dependencies : libdl_dep,
name : 'dlsym() preceding underscores')
if host_system == 'windows' or rres.returncode() == 0
g_module_need_uscore = 1
@ -61,7 +42,7 @@ if g_module_impl == 'G_MODULE_IMPL_DL'
g_module_need_uscore = 0
endif
if cc.has_function('dlerror', args : g_module_lib_args)
if cc.has_function('dlerror', dependencies : libdl_dep)
g_module_have_dlerror = 1
endif
endif

View File

@ -721,6 +721,28 @@ elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime in l
librt = cc.find_library('rt')
endif
dlopen_dlsym_test_code = '''
#include <dlfcn.h>
int glib_underscore_test (void) { return 42; }
int main (int argc, char ** argv) {
void *f1 = (void*)0, *f2 = (void*)0, *handle;
handle = dlopen ((void*)0, 0);
if (handle) {
f1 = dlsym (handle, "glib_underscore_test");
f2 = dlsym (handle, "_glib_underscore_test");
}
return (!f2 || f1);
}'''
libdl_dep = []
if cc.links(dlopen_dlsym_test_code, name : 'dlopen() and dlsym() in system libraries')
have_dlopen_dlsym = true
elif cc.links(dlopen_dlsym_test_code, args : '-ldl', name : 'dlopen() and dlsym() in libdl')
have_dlopen_dlsym = true
libdl_dep = cc.find_library('dl')
else
have_dlopen_dlsym = false
endif
# if statfs() takes 2 arguments (Posix) or 4 (Solaris)
if have_func_statfs
if cc.compiles(glib_conf_prefix + '''