Skip to content

Commit

Permalink
build: add check_preprocessor
Browse files Browse the repository at this point in the history
This can be used to do things like query the values of preprocessor
defines like version macros, among other potential uses.
  • Loading branch information
haasn committed Nov 3, 2021
1 parent edb0caa commit 2107671
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion waftools/checks/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"check_pkg_config_cflags", "check_cc", "check_statement", "check_libs",
"check_headers", "compose_checks", "any_check", "check_true", "any_version",
"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

Expand Down Expand Up @@ -47,6 +47,23 @@ def fn(ctx, dependency_identifier):
return False
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 fn(ctx, dependency_identifier, **kw):
headers = header
Expand Down

0 comments on commit 2107671

Please sign in to comment.