Blame gmodule/meson.build

Packit ae235b
gmoduleconf_conf = configuration_data()
Packit ae235b
Packit ae235b
g_module_need_uscore = 0
Packit ae235b
g_module_broken_rtld_global = 0
Packit ae235b
g_module_have_dlerror = 0
Packit ae235b
Packit ae235b
libdl_dep = [ ]
Packit ae235b
g_module_lib_args = [ ]
Packit ae235b
g_module_impl = ''
Packit ae235b
Packit ae235b
dlopen_dlsym_test_code = '''
Packit ae235b
#include <dlfcn.h>
Packit ae235b
int glib_underscore_test (void) { return 42; }
Packit ae235b
int main (int argc, char ** argv) {
Packit ae235b
  void *f1 = (void*)0, *f2 = (void*)0, *handle;
Packit ae235b
  handle = dlopen ((void*)0, 0);
Packit ae235b
  if (handle) {
Packit ae235b
    f1 = dlsym (handle, "glib_underscore_test");
Packit ae235b
    f2 = dlsym (handle, "_glib_underscore_test");
Packit ae235b
  }
Packit ae235b
  return (!f2 || f1);
Packit ae235b
}'''
Packit ae235b
Packit ae235b
# On Windows force native WIN32 shared lib loader
Packit ae235b
if host_system == 'windows'
Packit ae235b
  g_module_impl = 'G_MODULE_IMPL_WIN32'
Packit ae235b
# Force native AIX library loader
Packit ae235b
# dlopen() filepath must be of the form /path/libname.a(libname.so)
Packit ae235b
elif host_system == 'aix'
Packit ae235b
  g_module_impl = 'G_MODULE_IMPL_AR'
Packit ae235b
elif cc.links(dlopen_dlsym_test_code, name : 'dlopen() and dlsym() in system libraries')
Packit ae235b
  g_module_impl = 'G_MODULE_IMPL_DL'
Packit ae235b
# NSLinkModule (dyld) in system libraries (Darwin)
Packit ae235b
elif cc.has_function('NSLinkModule')
Packit ae235b
  g_module_impl = 'G_MODULE_IMPL_DYLD'
Packit ae235b
  g_module_need_uscore = 1
Packit ae235b
elif cc.links(dlopen_dlsym_test_code, args : '-ldl', name : 'dlopen() and dlsym() in libdl')
Packit ae235b
  g_module_impl = 'G_MODULE_IMPL_DL'
Packit ae235b
  libdl_dep = cc.find_library('dl')
Packit ae235b
  g_module_lib_args = '-ldl'
Packit ae235b
endif
Packit ae235b
Packit ae235b
# additional checks for G_MODULE_IMPL_DL
Packit ae235b
if g_module_impl == 'G_MODULE_IMPL_DL'
Packit ae235b
  # FIXME: check for OSF1/5.0 RTLD_GLOBAL brokenness (is this still relevant?)
Packit ae235b
Packit ae235b
  # Check whether we need preceding underscores
Packit ae235b
  if cc.get_id() == 'msvc'
Packit ae235b
    message('Building for MSVC: assuming that symbols are prefixed with underscore')
Packit ae235b
    g_module_need_uscore = 1
Packit ae235b
  elif meson.has_exe_wrapper()
Packit ae235b
    # FIXME: communicate result via stdout instead of return value, so non-0 return is not printed in bold red
Packit ae235b
    rres = cc.run(dlopen_dlsym_test_code,
Packit ae235b
                  args : g_module_lib_args,
Packit ae235b
                  name : 'dlsym() preceding underscores')
Packit ae235b
    if host_system == 'windows' or rres.returncode() == 0
Packit ae235b
      g_module_need_uscore = 1
Packit ae235b
    endif
Packit ae235b
  else
Packit ae235b
    message('Cross-compiling: assuming that symbols aren\'t prefixed with underscore')
Packit ae235b
    g_module_need_uscore = 0
Packit ae235b
  endif
Packit ae235b
Packit ae235b
  if cc.has_function('dlerror', args : g_module_lib_args)
Packit ae235b
    g_module_have_dlerror = 1
Packit ae235b
  endif
Packit ae235b
endif
Packit ae235b
Packit ae235b
# Done, have we got an implementation?
Packit ae235b
if g_module_impl == ''
Packit ae235b
  g_module_impl = '0'
Packit ae235b
  message('WARNING: No suitable GModule implementation found!')
Packit ae235b
endif
Packit ae235b
Packit ae235b
gmoduleconf_conf.set('G_MODULE_IMPL', g_module_impl)
Packit ae235b
gmoduleconf_conf.set('G_MODULE_SUPPORTED', g_module_impl != '0')
Packit ae235b
gmoduleconf_conf.set('G_MODULE_HAVE_DLERROR', g_module_have_dlerror)
Packit ae235b
gmoduleconf_conf.set('G_MODULE_NEED_USCORE', g_module_need_uscore)
Packit ae235b
gmoduleconf_conf.set('G_MODULE_BROKEN_RTLD_GLOBAL', g_module_broken_rtld_global)
Packit ae235b
Packit ae235b
gmoduleconf_h = configure_file(input : 'gmoduleconf.h.in',
Packit ae235b
                               output : 'gmoduleconf.h',
Packit ae235b
                               configuration : gmoduleconf_conf)
Packit ae235b
Packit ae235b
install_headers(['gmodule.h'], subdir : 'glib-2.0')
Packit ae235b
Packit ae235b
gmodule_sources = ['gmodule.c']
Packit ae235b
if host_system == 'windows'
Packit ae235b
  gmodule_win_rc = configure_file(
Packit ae235b
    input: 'gmodule.rc.in',
Packit ae235b
    output: 'gmodule.rc',
Packit ae235b
    configuration: glibconfig_conf,
Packit ae235b
  )
Packit ae235b
  gmodule_win_res = windows.compile_resources(gmodule_win_rc)
Packit ae235b
  gmodule_sources += [gmodule_win_res]
Packit ae235b
endif
Packit ae235b
Packit ae235b
libgmodule = library('gmodule-2.0',
Packit ae235b
  sources : gmodule_sources,
Packit ae235b
  version : library_version,
Packit ae235b
  soversion : soversion,
Packit ae235b
  install : true,
Packit ae235b
  include_directories : [configinc, gmoduleinc],
Packit ae235b
  dependencies : [libdl_dep, libglib_dep],
Packit ae235b
  c_args : ['-DG_LOG_DOMAIN="GModule"', '-DG_DISABLE_DEPRECATED'] + glib_hidden_visibility_args)
Packit ae235b
Packit ae235b
libgmodule_dep = declare_dependency(link_with : libgmodule,
Packit ae235b
  include_directories : gmoduleinc)