diff --git a/docs/markdown/Dependencies.md b/docs/markdown/Dependencies.md index 9f0ab7f17..d09c688ae 100644 --- a/docs/markdown/Dependencies.md +++ b/docs/markdown/Dependencies.md @@ -453,6 +453,15 @@ language. *New in 0.56.0* the dependencies now return proper dependency types and `get_variable` and similar methods should work as expected. +## iconv + +*(added 0.60.0)* + +Provides access to the `iconv` family of C functions. On systems where this is +not built into libc, tries to find an external library providing them instead. + +`method` may be `auto`, `builtin` or `system`. + ## intl *(added 0.59.0)* diff --git a/docs/markdown/snippets/iconv-dependency.md b/docs/markdown/snippets/iconv-dependency.md new file mode 100644 index 000000000..21a298541 --- /dev/null +++ b/docs/markdown/snippets/iconv-dependency.md @@ -0,0 +1,8 @@ +## New custom dependency for iconv + +``` +dependency('iconv') +``` + +will now check for the functionality of libiconv.so, but first check if it is +provided in the libc (for example in glibc or musl libc on Linux). diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py index bd90c90e9..ff0bd30e3 100644 --- a/mesonbuild/dependencies/__init__.py +++ b/mesonbuild/dependencies/__init__.py @@ -35,7 +35,7 @@ from .scalapack import scalapack_factory 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, intl_factory, + shaderc_factory, threads_factory, ThreadDependency, iconv_factory, intl_factory, ) from .platform import AppleFrameworks from .qt import qt4_factory, qt5_factory, qt6_factory @@ -252,6 +252,7 @@ packages.update({ 'libgcrypt': libgcrypt_factory, 'gpgme': gpgme_factory, 'shaderc': shaderc_factory, + 'iconv': iconv_factory, 'intl': intl_factory, # From platform: diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index faf06a1a3..daa7dff6f 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -448,6 +448,25 @@ class CursesSystemDependency(SystemDependency): break +class IconvBuiltinDependency(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('iconv_open', '', env)[0]: + self.is_found = True + + +class IconvSystemDependency(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('iconv.h', '', env) + self.link_args = self.clib_compiler.find_library('iconv', env, [], self.libtype) + + if h[0] and self.link_args: + self.is_found = True + + class IntlBuiltinDependency(BuiltinDependency): def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]): super().__init__(name, env, kwargs) @@ -467,7 +486,9 @@ class IntlSystemDependency(SystemDependency): self.is_found = True if self.static: - self.link_args += self.clib_compiler.find_library('iconv', env, [], self.libtype) + if not self._add_sub_dependency(iconv_factory(env, self.for_machine, {})): + self.is_found = False + return @factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.SYSTEM}) @@ -580,6 +601,13 @@ threads_factory = DependencyFactory( system_class=ThreadDependency, ) +iconv_factory = DependencyFactory( + 'iconv', + [DependencyMethods.BUILTIN, DependencyMethods.SYSTEM], + builtin_class=IconvBuiltinDependency, + system_class=IconvSystemDependency, +) + intl_factory = DependencyFactory( 'intl', [DependencyMethods.BUILTIN, DependencyMethods.SYSTEM],