1 gmoduleconf_conf = configuration_data()
3 g_module_need_uscore = 0
4 g_module_broken_rtld_global = 0
5 g_module_have_dlerror = 0
8 g_module_lib_args = [ ]
11 dlopen_dlsym_test_code = '''
13 int glib_underscore_test (void) { return 42; }
14 int main (int argc, char ** argv) {
15 void *f1 = (void*)0, *f2 = (void*)0, *handle;
16 handle = dlopen ((void*)0, 0);
18 f1 = dlsym (handle, "glib_underscore_test");
19 f2 = dlsym (handle, "_glib_underscore_test");
24 # On Windows force native WIN32 shared lib loader
25 if host_system == 'windows'
26 g_module_impl = 'G_MODULE_IMPL_WIN32'
27 # Force native AIX library loader
28 # dlopen() filepath must be of the form /path/libname.a(libname.so)
29 elif host_system == 'aix'
30 g_module_impl = 'G_MODULE_IMPL_AR'
31 elif cc.links(dlopen_dlsym_test_code, name : 'dlopen() and dlsym() in system libraries')
32 g_module_impl = 'G_MODULE_IMPL_DL'
33 # NSLinkModule (dyld) in system libraries (Darwin)
34 elif cc.has_function('NSLinkModule')
35 g_module_impl = 'G_MODULE_IMPL_DYLD'
36 g_module_need_uscore = 1
37 elif cc.links(dlopen_dlsym_test_code, args : '-ldl', name : 'dlopen() and dlsym() in libdl')
38 g_module_impl = 'G_MODULE_IMPL_DL'
39 libdl_dep = cc.find_library('dl')
40 g_module_lib_args = '-ldl'
43 # additional checks for G_MODULE_IMPL_DL
44 if g_module_impl == 'G_MODULE_IMPL_DL'
45 # FIXME: check for OSF1/5.0 RTLD_GLOBAL brokenness (is this still relevant?)
47 # Check whether we need preceding underscores
48 if cc.get_id() == 'msvc'
49 message('Building for MSVC: assuming that symbols are prefixed with underscore')
50 g_module_need_uscore = 1
51 elif meson.has_exe_wrapper()
52 # FIXME: communicate result via stdout instead of return value, so non-0 return is not printed in bold red
53 rres = cc.run(dlopen_dlsym_test_code,
54 args : g_module_lib_args,
55 name : 'dlsym() preceding underscores')
56 if host_system == 'windows' or rres.returncode() == 0
57 g_module_need_uscore = 1
60 message('Cross-compiling: assuming that symbols aren\'t prefixed with underscore')
61 g_module_need_uscore = 0
64 if cc.has_function('dlerror', args : g_module_lib_args)
65 g_module_have_dlerror = 1
69 # Done, have we got an implementation?
70 if g_module_impl == ''
72 message('WARNING: No suitable GModule implementation found!')
75 gmoduleconf_conf.set('G_MODULE_IMPL', g_module_impl)
76 gmoduleconf_conf.set('G_MODULE_SUPPORTED', g_module_impl != '0')
77 gmoduleconf_conf.set('G_MODULE_HAVE_DLERROR', g_module_have_dlerror)
78 gmoduleconf_conf.set('G_MODULE_NEED_USCORE', g_module_need_uscore)
79 gmoduleconf_conf.set('G_MODULE_BROKEN_RTLD_GLOBAL', g_module_broken_rtld_global)
81 gmoduleconf_h = configure_file(input : 'gmoduleconf.h.in',
82 output : 'gmoduleconf.h',
83 configuration : gmoduleconf_conf)
85 install_headers(['gmodule.h'], subdir : 'glib-2.0')
87 libgmodule = shared_library('gmodule-2.0',
88 sources : ['gmodule.c'],
89 version : library_version,
90 soversion : soversion,
92 include_directories : [configinc, gmoduleinc],
93 dependencies : [libdl_dep, libglib_dep],
94 c_args : ['-DG_LOG_DOMAIN="GModule"', '-DG_DISABLE_DEPRECATED'] + glib_hidden_visibility_args)
96 libgmodule_dep = declare_dependency(link_with : libgmodule,
97 include_directories : gmoduleinc)