Meson: Get results from cross file properties if cannot run code

When cross compiling and not exe wrapper has been defined cc.run() raise
an exception. Avoid this by taking the value from [properties] in the
cross file and provide sensible default if the variable is not defined.

https://bugzilla.gnome.org/show_bug.cgi?id=794898
This commit is contained in:
Xavier Claessens 2018-04-02 23:01:25 -04:00
parent 3f741e087f
commit b0ae762a33

View File

@ -10,6 +10,8 @@ project('glib', 'c', 'cpp',
cc = meson.get_compiler('c') cc = meson.get_compiler('c')
cxx = meson.get_compiler('cpp') cxx = meson.get_compiler('cpp')
cc_can_run = not meson.is_cross_build() or meson.has_exe_wrapper()
if cc.get_id() == 'msvc' if cc.get_id() == 'msvc'
# Ignore several spurious warnings for things glib does very commonly # Ignore several spurious warnings for things glib does very commonly
# If a warning is completely useless and spammy, use '/wdXXXX' to suppress it # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
@ -731,10 +733,15 @@ main(void)
exit(1); exit(1);
}''' }'''
rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf') if cc_can_run
if rres.compiled() and rres.returncode() == 0 rres = cc.run(vsnprintf_c99_test_code, name : 'C99 vsnprintf')
glib_conf.set('HAVE_C99_VSNPRINTF', 1) if rres.compiled() and rres.returncode() == 0
have_good_vsnprintf = true glib_conf.set('HAVE_C99_VSNPRINTF', 1)
have_good_vsnprintf = true
endif
else
have_good_vsnprintf = meson.get_cross_property('have_c99_vsnprintf', false)
glib_conf.set('HAVE_C99_VSNPRINTF', have_good_vsnprintf)
endif endif
snprintf_c99_test_code = ''' snprintf_c99_test_code = '''
@ -773,10 +780,15 @@ main(void)
exit(1); exit(1);
}''' }'''
rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf') if cc_can_run
if rres.compiled() and rres.returncode() == 0 rres = cc.run(snprintf_c99_test_code, name : 'C99 snprintf')
glib_conf.set('HAVE_C99_SNPRINTF', 1) if rres.compiled() and rres.returncode() == 0
have_good_snprintf = true glib_conf.set('HAVE_C99_SNPRINTF', 1)
have_good_snprintf = true
endif
else
have_good_snprintf = meson.get_cross_property('have_c99_snprintf', false)
glib_conf.set('HAVE_C99_SNPRINTF', have_good_snprintf)
endif endif
endif endif
@ -1277,16 +1289,13 @@ va_list_val_copy_prog = '''
return 0; return 0;
}''' }'''
# We do this in two steps so if compilation fails already it looks less alarming if cc_can_run
glib_va_val_copy = false rres = cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values')
if cc.compiles(va_list_val_copy_prog, name : 'va_lists can be copied as values') glib_va_val_copy = rres.returncode() == 0
# FIXME: what to do when cross-compiling? else
if cc.run(va_list_val_copy_prog, name : 'va_lists can be copied as values').returncode() == 0 glib_va_val_copy = meson.get_cross_property('va_val_copy', true)
glib_va_val_copy = true
endif
endif endif
if not glib_va_val_copy if not glib_va_val_copy
glib_va_val_copy = false
glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1' glib_vacopy = glib_vacopy + '\n#define G_VA_COPY_AS_ARRAY 1'
glib_conf.set('G_VA_COPY_AS_ARRAY', 1) glib_conf.set('G_VA_COPY_AS_ARRAY', 1)
endif endif
@ -1470,7 +1479,6 @@ else
endif endif
endif endif
# FIXME: how to do this when cross-compiling?
# FIXME: we should make it print the result and always return 0, so that # FIXME: we should make it print the result and always return 0, so that
# the output in meson shows up as green # the output in meson shows up as green
stack_grows_check_prog = ''' stack_grows_check_prog = '''
@ -1488,13 +1496,16 @@ stack_grows_check_prog = '''
f (100); f (100);
return b > a ? 0 : 1; return b > a ? 0 : 1;
}''' }'''
stack_grows_run_result = cc.run(stack_grows_check_prog, name : 'stack grows check')
if stack_grows_run_result.compiled() and stack_grows_run_result.returncode() == 0 if cc_can_run
glibconfig_conf.set('G_HAVE_GROWING_STACK', 1) rres = cc.run(stack_grows_check_prog, name : 'stack grows check')
growing_stack = rres.returncode() == 0
else else
glibconfig_conf.set('G_HAVE_GROWING_STACK', 0) growing_stack = meson.get_cross_property('growing_stack', false)
endif endif
glibconfig_conf.set('G_HAVE_GROWING_STACK', growing_stack)
# Tests for iconv # Tests for iconv
# #
# USE_LIBICONV_GNU: Using GNU libiconv # USE_LIBICONV_GNU: Using GNU libiconv