external_project: Add default configure options

pull/8264/head
Xavier Claessens 4 years ago
parent 6a6323ff09
commit 11cfc258fc
  1. 12
      docs/markdown/External-Project-module.md
  2. 24
      mesonbuild/modules/unstable_external_project.py

@ -54,8 +54,10 @@ build system. Usually in a `meson.build` file placed in the top directory of a
subproject, but could be also in any subdir.
Its first positional argument is the name of the configure script to be
executed (e.g. `configure` or `autogen.sh`), that file must be in the current
directory and executable.
executed (e.g. `configure`), that file must be in the current directory and
executable. Note that if a bootstrap script is required (e.g. `autogen.sh` when
building from git instead of tarball), it can be done using `run_command()`
before calling `add_project()` method.
Keyword arguments:
- `configure_options`: An array of strings to be passed as arguments to the
@ -63,7 +65,11 @@ Keyword arguments:
them to the configure script: `@PREFIX@`, `@LIBDIR@` and `@INCLUDEDIR@`.
Note that `libdir` and `includedir` paths are relative to `prefix` in Meson
but some configure scripts requires absolute path, in that case they can be
passed as `'--libdir=@PREFIX@/@LIBDIR@'`.
passed as `'--libdir=@PREFIX@/@LIBDIR@'`. *Since 0.57.0* default arguments are
added in case some tags are not found in `configure_options`:
`'--prefix=@PREFIX@'`, `'--libdir=@PREFIX@/@LIBDIR@'`, and
`'--includedir=@PREFIX@/@INCLUDEDIR@'`. It was previously considered a fatal
error to not specify them.
- `cross_configure_options`: Extra options appended to `configure_options` only
when cross compiling. special tag `@HOST@` will be replaced by
`'{}-{}-{}'.format(host_machine.cpu_family(), build_machine.system(), host_machine.system()`.

@ -90,11 +90,11 @@ class ExternalProject(InterpreterObject):
configure_prog = self.interpreter.find_program_impl(configure_path.as_posix())
configure_cmd = configure_prog.get_command()
d = {'PREFIX': self.prefix.as_posix(),
'LIBDIR': self.libdir.as_posix(),
'INCLUDEDIR': self.includedir.as_posix(),
}
self._validate_configure_options(d.keys())
d = [('PREFIX', '--prefix=@PREFIX@', self.prefix.as_posix()),
('LIBDIR', '--libdir=@PREFIX@/@LIBDIR@', self.libdir.as_posix()),
('INCLUDEDIR', '--includedir=@PREFIX@/@INCLUDEDIR@', self.includedir.as_posix()),
]
self._validate_configure_options(d)
configure_cmd += self._format_options(self.configure_options, d)
@ -102,7 +102,7 @@ class ExternalProject(InterpreterObject):
host = '{}-{}-{}'.format(self.host_machine.cpu_family,
self.build_machine.system,
self.host_machine.system)
d = {'HOST': host}
d = [('HOST', None, host)]
configure_cmd += self._format_options(self.cross_configure_options, d)
# Set common env variables like CFLAGS, CC, etc.
@ -136,23 +136,23 @@ class ExternalProject(InterpreterObject):
def _quote_and_join(self, array: T.List[str]) -> str:
return ' '.join([shlex.quote(i) for i in array])
def _validate_configure_options(self, required_keys: T.List[str]):
def _validate_configure_options(self, variables: T.List[T.Tuple[str, str, str]]):
# Ensure the user at least try to pass basic info to the build system,
# like the prefix, libdir, etc.
for key in required_keys:
for key, default, val in variables:
key_format = '@{}@'.format(key)
for option in self.configure_options:
if key_format in option:
break
else:
m = 'At least one configure option must contain "{}" key'
raise InterpreterException(m.format(key_format))
FeatureNew('Default configure_option', '0.57.0').use(self.subproject)
self.configure_options.append(default)
def _format_options(self, options: T.List[str], variables: T.Dict[str, str]) -> T.List[str]:
def _format_options(self, options: T.List[str], variables: T.List[T.Tuple[str, str, str]]) -> T.List[str]:
out = []
missing = set()
regex = get_variable_regex('meson')
confdata = {k: (v, None) for k, v in variables.items()}
confdata = {k: (v, None) for k, d, v in variables}
for o in options:
arg, missing_vars = do_replacement(regex, o, 'meson', confdata)
missing.update(missing_vars)

Loading…
Cancel
Save