mirror of https://github.com/mpv-player/mpv
build: add check_preprocessor
This can be used to do things like query the values of preprocessor defines like version macros, among other potential uses.
This commit is contained in:
parent
edb0caa441
commit
2107671691
|
@ -9,7 +9,7 @@ __all__ = [
|
||||||
"check_pkg_config_cflags", "check_cc", "check_statement", "check_libs",
|
"check_pkg_config_cflags", "check_cc", "check_statement", "check_libs",
|
||||||
"check_headers", "compose_checks", "any_check", "check_true", "any_version",
|
"check_headers", "compose_checks", "any_check", "check_true", "any_version",
|
||||||
"load_fragment", "check_stub", "check_ctx_vars", "check_program",
|
"load_fragment", "check_stub", "check_ctx_vars", "check_program",
|
||||||
"check_pkg_config_datadir", "check_macos_sdk"]
|
"check_pkg_config_datadir", "check_macos_sdk", "check_preprocessor"]
|
||||||
|
|
||||||
any_version = None
|
any_version = None
|
||||||
|
|
||||||
|
@ -47,6 +47,23 @@ def check_libs(libs, function):
|
||||||
return False
|
return False
|
||||||
return fn
|
return fn
|
||||||
|
|
||||||
|
def check_preprocessor(header, expression, **kw_ext):
|
||||||
|
def fn(ctx, dependency_identifier, **kw):
|
||||||
|
headers = header
|
||||||
|
if not isinstance(headers, list):
|
||||||
|
headers = [header]
|
||||||
|
hs = "\n".join(["#include <{0}>".format(h) for h in headers])
|
||||||
|
fragment = ("{0}\n"
|
||||||
|
"#if !({1})\n#error\n#endif\n"
|
||||||
|
"int main(int argc, char **argv)\n"
|
||||||
|
"{{ return 0; }}").format(hs, expression)
|
||||||
|
opts = __merge_options__(dependency_identifier,
|
||||||
|
{'fragment':fragment},
|
||||||
|
__define_options__(dependency_identifier),
|
||||||
|
kw_ext, kw)
|
||||||
|
return ctx.check_cc(**_filter_cc_arguments(ctx, opts))
|
||||||
|
return fn
|
||||||
|
|
||||||
def check_statement(header, statement, **kw_ext):
|
def check_statement(header, statement, **kw_ext):
|
||||||
def fn(ctx, dependency_identifier, **kw):
|
def fn(ctx, dependency_identifier, **kw):
|
||||||
headers = header
|
headers = header
|
||||||
|
|
Loading…
Reference in New Issue