summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/compilers/mixins/clike.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py
index a75cd2a81..19a6bb487 100644
--- a/mesonbuild/compilers/mixins/clike.py
+++ b/mesonbuild/compilers/mixins/clike.py
@@ -476,6 +476,21 @@ class CLikeCompiler(Compiler):
if self._compile_int(f'{expression} == {guess}', prefix, env, extra_args, dependencies):
return guess
+ # Try to expand the expression and evaluate it on the build machines compiler
+ if self.language in env.coredata.compilers.build:
+ try:
+ expanded, _ = self.get_define(expression, prefix, env, extra_args, dependencies, False)
+ evaluate_expanded = f'''
+ #include <stdio.h>
+ #include <stdint.h>
+ int main(void) {{ int expression = {expanded}; printf("%d", expression); return 0; }}'''
+ run = env.coredata.compilers.build[self.language].run(evaluate_expanded, env)
+ if run and run.compiled and run.returncode == 0:
+ if self._compile_int(f'{expression} == {run.stdout}', prefix, env, extra_args, dependencies):
+ return int(run.stdout)
+ except mesonlib.EnvironmentException:
+ pass
+
# If no bounds are given, compute them in the limit of int32
maxint = 0x7fffffff
minint = -0x80000000