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 gmodule_sources = ['gmodule.c']
88 if host_system == 'windows'
89 gmodule_win_rc = configure_file(
90 input: 'gmodule.rc.in',
92 configuration: glibconfig_conf,
94 gmodule_win_res = windows.compile_resources(gmodule_win_rc)
95 gmodule_sources += [gmodule_win_res]
98 libgmodule = library('gmodule-2.0',
99 sources : gmodule_sources,
100 version : library_version,
101 soversion : soversion,
103 include_directories : [configinc, gmoduleinc],
104 dependencies : [libdl_dep, libglib_dep],
105 c_args : ['-DG_LOG_DOMAIN="GModule"', '-DG_DISABLE_DEPRECATED'] + glib_hidden_visibility_args,
106 link_args : [glib_link_flags],
109 supported_var = 'gmodule_supported=@0@'.format(g_module_impl != '0')
111 pkg.generate(libraries : [libgmodule, thread_dep],
112 requires : ['glib-2.0'],
113 version : glib_version,
114 variables : [supported_var],
115 install_dir : glib_pkgconfigreldir,
116 filebase : 'gmodule-no-export-2.0',
118 description : 'Dynamic module loader for GLib',
121 pkg.generate(libraries : [libgmodule, export_dynamic_ldflags],
122 requires : ['glib-2.0'],
123 version : glib_version,
124 variables : [supported_var],
125 install_dir : glib_pkgconfigreldir,
126 filebase : 'gmodule-export-2.0',
128 description : 'Dynamic module loader for GLib',
131 pkg.generate(libraries : [libgmodule, export_dynamic_ldflags],
132 requires : ['glib-2.0'],
133 version : glib_version,
134 variables : [supported_var],
135 install_dir : glib_pkgconfigreldir,
136 filebase : 'gmodule-2.0',
138 description : 'Dynamic module loader for GLib',
141 libgmodule_dep = declare_dependency(link_with : libgmodule,
142 include_directories : gmoduleinc)