[glib/wip/lantw/meson-move-libdl_dep-to-the-top-level] meson: Move libdl_dep to the top level



commit 05385b6edc6499765888562a5da1a64ef7c1159a
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Thu Aug 29 23:19:08 2019 +0800

    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 it can be shared by
    all directories.
    
    It is a follow-up of https://gitlab.gnome.org/GNOME/glib/merge_requests/810.

 gio/tests/meson.build |  6 +-----
 gmodule/meson.build   | 25 +++----------------------
 meson.build           | 22 ++++++++++++++++++++++
 3 files changed, 26 insertions(+), 27 deletions(-)
---
diff --git a/gio/tests/meson.build b/gio/tests/meson.build
index 3a6b50bb5..b5593a4ec 100644
--- a/gio/tests/meson.build
+++ b/gio/tests/meson.build
@@ -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,
           )
diff --git a/gmodule/meson.build b/gmodule/meson.build
index 942f9af3c..d38ad2df1 100644
--- a/gmodule/meson.build
+++ b/gmodule/meson.build
@@ -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
diff --git a/meson.build b/meson.build
index d9e0a56ad..26b3fd229 100644
--- a/meson.build
+++ b/meson.build
@@ -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 + '''


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]