diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py index a75cd2a81bf0..19a6bb4875af 100644 --- a/mesonbuild/compilers/mixins/clike.py +++ b/mesonbuild/compilers/mixins/clike.py @@ -476,6 +476,21 @@ def cross_compute_int(self, expression: str, low: T.Optional[int], high: T.Optio 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 + #include + 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