diff options
-rw-r--r-- | docs/markdown/Dependencies.md | 21 | ||||
-rw-r--r-- | docs/markdown/snippets/intl-dependency.md | 35 | ||||
-rw-r--r-- | mesonbuild/dependencies/__init__.py | 3 | ||||
-rw-r--r-- | mesonbuild/dependencies/misc.py | 28 |
4 files changed, 84 insertions, 3 deletions
diff --git a/docs/markdown/Dependencies.md b/docs/markdown/Dependencies.md index 41f3bc2..caf7af7 100644 --- a/docs/markdown/Dependencies.md +++ b/docs/markdown/Dependencies.md @@ -141,7 +141,7 @@ of all the work behind the scenes to make this work. You can use the keyword `method` to let Meson know what method to use when searching for the dependency. The default value is `auto`. Additional dependencies methods are `pkg-config`, `config-tool`, `cmake`, -`system`, `sysconfig`, `qmake`, `extraframework` and `dub`. +`builtin`, `system`, `sysconfig`, `qmake`, `extraframework` and `dub`. ```meson cups_dep = dependency('cups', method : 'pkg-config') @@ -282,6 +282,15 @@ in the build system DSL or with a script, likely calling putting these in meson upstream the barrier of using them is lowered, as projects using meson don't have to re-implement the logic. +## Builtin + +Some dependencies provide no valid methods for discovery on some systems, +because they are provided internally by the language. One example of this is +intl, which is built into GNU or musl libc but otherwise comes as a `system` +dependency. + +In these cases meson provides convenience wrappers for the `system` dependency, +but first checks if the functionality is usable by default. ## Blocks @@ -400,6 +409,16 @@ language. *New in 0.56.0* the dependencies now return proper dependency types and `get_variable` and similar methods should work as expected. +## intl + +*(added 0.59.0)* + +Provides access to the `*gettext` 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`. + ## libwmf *(added 0.44.0)* diff --git a/docs/markdown/snippets/intl-dependency.md b/docs/markdown/snippets/intl-dependency.md new file mode 100644 index 0000000..8e0cd40 --- /dev/null +++ b/docs/markdown/snippets/intl-dependency.md @@ -0,0 +1,35 @@ +## New custom dependency for libintl + +Meson can now find the library needed for translating messages via gettext. +This works both on systems where libc provides gettext, such as GNU or musl, +and on systems where the gettext project's standalone intl support library is +required, such as macOS. + +Rather than doing something such as: + +``` +intl_dep = dependency('', required: false) + +if cc.has_function('ngettext') + intl_found = true +else + intl_dep = cc.find_library('intl', required: false) + intl_found = intl_dep.found() +endif + +if intl_found + # build options that need gettext + conf.set('ENABLE_NLS', 1) +endif +``` + +one may simply use: + +``` +intl_dep = dependency('intl') + +if intl_dep.found() + # build options that need gettext + conf.set('ENABLE_NLS', 1) +endif +``` diff --git a/mesonbuild/dependencies/__init__.py b/mesonbuild/dependencies/__init__.py index 0dafae1..bd90c90 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, + shaderc_factory, threads_factory, ThreadDependency, 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, + 'intl': intl_factory, # From platform: 'appleframeworks': AppleFrameworks, diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py index 87b1a9b..f131cb7 100644 --- a/mesonbuild/dependencies/misc.py +++ b/mesonbuild/dependencies/misc.py @@ -24,7 +24,7 @@ from .. import mesonlib from .. import mlog from ..environment import detect_cpu_family from .base import DependencyException, DependencyMethods -from .base import SystemDependency +from .base import BuiltinDependency, SystemDependency from .cmake import CMakeDependency from .configtool import ConfigToolDependency from .factory import DependencyFactory, factory_methods @@ -487,6 +487,25 @@ class CursesSystemDependency(SystemDependency): return [DependencyMethods.SYSTEM] +class IntlBuiltinDependency(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('ngettext', '', env)[0]: + self.is_found = True + + +class IntlSystemDependency(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('libintl.h', '', env) + self.link_args = self.clib_compiler.find_library('intl', env, []) + + if h and self.link_args: + self.is_found = True + + @factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.SYSTEM}) def curses_factory(env: 'Environment', for_machine: 'MachineChoice', @@ -596,3 +615,10 @@ threads_factory = DependencyFactory( cmake_name='Threads', system_class=ThreadDependency, ) + +intl_factory = DependencyFactory( + 'intl', + [DependencyMethods.BUILTIN, DependencyMethods.SYSTEM], + builtin_class=IntlBuiltinDependency, + system_class=IntlSystemDependency, +) |