aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-09-18 10:40:13 -0700
committerDylan Baker <dylan@pnwbakers.com>2020-09-29 14:58:32 -0700
commit5aee8567b8c0ec3d242424bdc88a32f3303e61c4 (patch)
treeec4c17da837b8f117c0927303d44bfb9b8009d82
parentcb6ccf2632c3b09237b2bfe04687fa5d8b4c88ab (diff)
downloadmeson-5aee8567b8c0ec3d242424bdc88a32f3303e61c4.zip
meson-5aee8567b8c0ec3d242424bdc88a32f3303e61c4.tar.gz
meson-5aee8567b8c0ec3d242424bdc88a32f3303e61c4.tar.bz2
dependencies/curses: Add a system dependency
That calls find_library and has_header in conjunction to look for curses implementations that are baked into the system without any other find method.
-rw-r--r--docs/markdown/Dependencies.md4
-rw-r--r--docs/markdown/snippets/curses-dependency-improvements.md4
-rw-r--r--mesonbuild/dependencies/misc.py59
-rw-r--r--test cases/frameworks/31 curses/meson_options.txt2
-rw-r--r--test cases/frameworks/31 curses/test.json3
5 files changed, 65 insertions, 7 deletions
diff --git a/docs/markdown/Dependencies.md b/docs/markdown/Dependencies.md
index eccfe0a..a8ada1d 100644
--- a/docs/markdown/Dependencies.md
+++ b/docs/markdown/Dependencies.md
@@ -623,9 +623,9 @@ Curses (and ncurses) are a cross platform pain in the butt. Meson wraps up
these dependencies in the `curses` dependency. This covers both `ncurses`
(preferred) and other curses implementations.
-`method` may be `auto`, `pkg-config`, or `config-tool`
+`method` may be `auto`, `pkg-config`, `config-tool`, or `system`.
-*New in 0.56.0* The `config-tool` method.
+*New in 0.56.0* The `config-tool` and `system` methods.
<hr>
<a name="footnote1">1</a>: They may appear to be case-insensitive, if the
diff --git a/docs/markdown/snippets/curses-dependency-improvements.md b/docs/markdown/snippets/curses-dependency-improvements.md
index bd1d001..237da4c 100644
--- a/docs/markdown/snippets/curses-dependency-improvements.md
+++ b/docs/markdown/snippets/curses-dependency-improvements.md
@@ -1,4 +1,4 @@
## Improvements for the builtin curses dependency
-This method has been extended to use config-tools for lookup as well as
-pkg-config.
+This method has been extended to use config-tools, and a fallback to
+find_library for lookup as well as pkg-config.
diff --git a/mesonbuild/dependencies/misc.py b/mesonbuild/dependencies/misc.py
index c1e17d7..08747ce 100644
--- a/mesonbuild/dependencies/misc.py
+++ b/mesonbuild/dependencies/misc.py
@@ -420,7 +420,61 @@ class CursesConfigToolDependency(ConfigToolDependency):
self.link_args = self.get_config_value(['--libs'], 'link_args')
-@factory_methods({DependencyMethods.PKGCONFIG, DependencyMethods.CONFIG_TOOL})
+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 = [
+ ('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('"')
+
+ # 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[T.Callable[[], 'Dependency']]:
candidates = [] # type: T.List[T.Callable[[], Dependency]]
@@ -433,6 +487,9 @@ def curses_factory(env: 'Environment', for_machine: 'MachineChoice',
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
diff --git a/test cases/frameworks/31 curses/meson_options.txt b/test cases/frameworks/31 curses/meson_options.txt
index 3a587f4..e294e83 100644
--- a/test cases/frameworks/31 curses/meson_options.txt
+++ b/test cases/frameworks/31 curses/meson_options.txt
@@ -1,6 +1,6 @@
option(
'method',
type : 'combo',
- choices : ['pkg-config', 'config-tool'],
+ choices : ['pkg-config', 'config-tool', 'system'],
value : 'pkg-config',
)
diff --git a/test cases/frameworks/31 curses/test.json b/test cases/frameworks/31 curses/test.json
index 0de1f73..3995695 100644
--- a/test cases/frameworks/31 curses/test.json
+++ b/test cases/frameworks/31 curses/test.json
@@ -3,7 +3,8 @@
"options": {
"method": [
{ "val": "pkg-config" },
- { "val": "config-tool" }
+ { "val": "config-tool" },
+ { "val": "system" }
]
}
}