diff --git a/docs/markdown/Dependencies.md b/docs/markdown/Dependencies.md index 0cbed5c2c..9dabef8ae 100644 --- a/docs/markdown/Dependencies.md +++ b/docs/markdown/Dependencies.md @@ -393,6 +393,17 @@ foreach h : check_headers endforeach ``` +## dl (libdl) + +*(added 0.62.0)* + +Provides access to the dynamic link interface (functions: dlopen, +dlclose, dlsym and others). On systems where this is not built +into libc (mostly glibc < 2.34), tries to find an external library +providing them instead. + +`method` may be `auto`, `builtin` or `system`. + ## Fortran Coarrays *(added 0.50.0)* diff --git a/docs/markdown/snippets/libdl-dependency.md b/docs/markdown/snippets/libdl-dependency.md new file mode 100644 index 000000000..fee780ca9 --- /dev/null +++ b/docs/markdown/snippets/libdl-dependency.md @@ -0,0 +1,8 @@ +## New custom dependency for libdl + +``` +dependency('dl') +``` + +will now check for the functionality of libdl.so, but first check if it is +provided in the libc (for example in libc on OpenBSD or in musl libc on linux). diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py index ff0bd30e3..b0c25b1f2 100644 --- a/mesonbuild/dependencies/__init__.py +++ b/mesonbuild/dependencies/__init__.py @@ -36,6 +36,7 @@ from .misc import ( BlocksDependency, OpenMPDependency, cups_factory, curses_factory, gpgme_factory, libgcrypt_factory, libwmf_factory, netcdf_factory, pcap_factory, python3_factory, shaderc_factory, threads_factory, ThreadDependency, iconv_factory, intl_factory, + dl_factory ) from .platform import AppleFrameworks from .qt import qt4_factory, qt5_factory, qt6_factory @@ -254,6 +255,7 @@ packages.update({ 'shaderc': shaderc_factory, 'iconv': iconv_factory, 'intl': intl_factory, + 'dl': dl_factory, # From platform: 'appleframeworks': AppleFrameworks, diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index 470305e91..c95f7daba 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -60,6 +60,25 @@ def netcdf_factory(env: 'Environment', return candidates +class DlBuiltinDependency(BuiltinDependency): + def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]): + super().__init__(name, env, kwargs) + + if self.clib_compiler.has_function('dlopen', '#include ', env)[0]: + self.is_found = True + + +class DlSystemDependency(SystemDependency): + def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]): + super().__init__(name, env, kwargs) + + h = self.clib_compiler.has_header('dlfcn.h', '', env) + self.link_args = self.clib_compiler.find_library('dl', env, [], self.libtype) + + if h[0] and self.link_args: + self.is_found = True + + class OpenMPDependency(SystemDependency): # Map date of specification release (which is the macro value) to a version. VERSIONS = { @@ -559,6 +578,13 @@ cups_factory = DependencyFactory( cmake_name='Cups', ) +dl_factory = DependencyFactory( + 'dl', + [DependencyMethods.BUILTIN, DependencyMethods.SYSTEM], + builtin_class=DlBuiltinDependency, + system_class=DlSystemDependency, +) + gpgme_factory = DependencyFactory( 'gpgme', [DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL],