aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/dependencies/misc.py
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild/dependencies/misc.py')
-rw-r--r--mesonbuild/dependencies/misc.py95
1 files changed, 90 insertions, 5 deletions
diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py
index 47694af..15055aa 100644
--- a/mesonbuild/dependencies/misc.py
+++ b/mesonbuild/dependencies/misc.py
@@ -32,7 +32,7 @@ from .base import (
if T.TYPE_CHECKING:
from ..environment import Environment, MachineChoice
- from .base import DependencyType # noqa: F401
+ from .base import DependencyType, Dependency # noqa: F401
@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CMAKE})
@@ -404,16 +404,101 @@ class ShadercDependency(ExternalDependency):
return [DependencyMethods.SYSTEM, DependencyMethods.PKGCONFIG]
-@factory_methods({DependencyMethods.PKGCONFIG})
+class CursesConfigToolDependency(ConfigToolDependency):
+
+ """Use the curses config tools."""
+
+ tool = 'curses-config'
+ # ncurses5.4-config is for macOS Catalina
+ tools = ['ncursesw6-config', 'ncursesw5-config', 'ncurses6-config', 'ncurses5-config', 'ncurses5.4-config']
+
+ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any], language: T.Optional[str] = None):
+ super().__init__(name, env, kwargs, language)
+ if not self.is_found:
+ return
+ self.compile_args = self.get_config_value(['--cflags'], 'compile_args')
+ self.link_args = self.get_config_value(['--libs'], 'link_args')
+
+
+class CursesSystemDependency(ExternalDependency):
+
+ """Curses dependency the hard way.
+
+ This replaces hand rolled find_library() and has_header() calls. We
+ provide this for portability reasons, there are a large number of curses
+ implementations, and the differences between them can be very annoying.
+ """
+
+ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
+ super().__init__(name, env, kwargs)
+
+ candidates = [
+ ('pdcurses', ['pdcurses/curses.h']),
+ ('ncursesw', ['ncursesw/ncurses.h', 'ncurses.h']),
+ ('ncurses', ['ncurses/ncurses.h', 'ncurses/curses.h', 'ncurses.h']),
+ ('curses', ['curses.h']),
+ ]
+
+ # Not sure how else to elegently break out of both loops
+ for lib, headers in candidates:
+ l = self.clib_compiler.find_library(lib, env, [])
+ if l:
+ for header in headers:
+ h = self.clib_compiler.has_header(header, '', env)
+ if h[0]:
+ self.is_found = True
+ self.link_args = l
+ # Not sure how to find version for non-ncurses curses
+ # implementations. The one in illumos/OpenIndiana
+ # doesn't seem to have a version defined in the header.
+ if lib.startswith('ncurses'):
+ v, _ = self.clib_compiler.get_define('NCURSES_VERSION', '#include <{}>'.format(header), env, [], [self])
+ self.version = v.strip('"')
+ if lib.startswith('pdcurses'):
+ v_major, _ = self.clib_compiler.get_define('PDC_VER_MAJOR', '#include <{}>'.format(header), env, [], [self])
+ v_minor, _ = self.clib_compiler.get_define('PDC_VER_MINOR', '#include <{}>'.format(header), env, [], [self])
+ self.version = '{}.{}'.format(v_major, v_minor)
+
+ # Check the version if possible, emit a wraning if we can't
+ req = kwargs.get('version')
+ if req:
+ if self.version:
+ self.is_found = mesonlib.version_compare(self.version, req)
+ else:
+ mlog.warning('Cannot determine version of curses to compare against.')
+
+ if self.is_found:
+ mlog.debug('Curses library:', l)
+ mlog.debug('Curses header:', header)
+ break
+ if self.is_found:
+ break
+
+ @staticmethod
+ def get_methods() -> T.List[DependencyMethods]:
+ return [DependencyMethods.SYSTEM]
+
+
+@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL, DependencyMethods.SYSTEM})
def curses_factory(env: 'Environment', for_machine: 'MachineChoice',
- kwargs: T.Dict[str, T.Any], methods: T.List[DependencyMethods]) -> T.List['DependencyType']:
- candidates = [] # type: T.List['DependencyType']
+ kwargs: T.Dict[str, T.Any], methods: T.List[DependencyMethods]) -> T.List[T.Callable[[], 'Dependency']]:
+ candidates = [] # type: T.List[T.Callable[[], Dependency]]
if DependencyMethods.PKGCONFIG in methods:
- pkgconfig_files = ['ncurses', 'ncursesw']
+ pkgconfig_files = ['pdcurses', 'ncursesw', 'ncurses', 'curses']
for pkg in pkgconfig_files:
candidates.append(functools.partial(PkgConfigDependency, pkg, env, kwargs))
+ # There are path handling problems with these methods on msys, and they
+ # don't apply to windows otherwise (cygwin is handled seperately from
+ # windows)
+ if not env.machines[for_machine].is_windows():
+ if DependencyMethods.CONFIG_TOOL in methods:
+ candidates.append(functools.partial(CursesConfigToolDependency, 'curses', env, kwargs))
+
+ if DependencyMethods.SYSTEM in methods:
+ candidates.append(functools.partial(CursesSystemDependency, 'curses', env, kwargs))
+
return candidates