Meson: Use cc.compute_int() instead of running our own code

When cross compiling we cannot run code, and meson has code to compute
int values without executing code.

https://bugzilla.gnome.org/show_bug.cgi?id=794898
This commit is contained in:
Xavier Claessens 2018-04-06 13:46:15 -04:00
parent d57f3e0a9b
commit 3f741e087f

View File

@ -1339,54 +1339,43 @@ endif
has_winsock2 = cc.has_header('winsock2.h') has_winsock2 = cc.has_header('winsock2.h')
if has_syspoll and has_systypes if has_syspoll and has_systypes
templ = '''#include<sys/poll.h> poll_includes = '''
#include<sys/types.h> #include<sys/poll.h>
#include<stdio.h> #include<sys/types.h>'''
int main(int argc, char **argv) {
printf("%d\n", (int)@0@);
return 0;
}'''
elif has_winsock2 elif has_winsock2
templ = '''#define _WIN32_WINNT 0x0600 poll_includes = '''
#include <stdio.h> #define _WIN32_WINNT 0x0600
#include <winsock2.h> #include <winsock2.h>'''
int main(int argc, char **argv) {
printf("%d\n", (int)@0@);
return 0;
}'''
else else
# FIXME? # FIXME?
error('FIX POLL* defines') error('FIX POLL* defines')
endif endif
value_POLLIN = cc.run(templ.format('POLLIN'), name : 'POLLIN value').stdout().strip() poll_defines = [
value_POLLOUT = cc.run(templ.format('POLLOUT'), name : 'POLLOUT value').stdout().strip() [ 'POLLIN', 'g_pollin' ],
value_POLLPRI = cc.run(templ.format('POLLPRI'), name : 'POLLPRI value').stdout().strip() [ 'POLLOUT', 'g_pollout' ],
value_POLLERR = cc.run(templ.format('POLLERR'), name : 'POLLERR value').stdout().strip() [ 'POLLPRI', 'g_pollpri' ],
value_POLLHUP = cc.run(templ.format('POLLHUP'), name : 'POLLHUP value').stdout().strip() [ 'POLLERR', 'g_pollerr' ],
value_POLLNVAL = cc.run(templ.format('POLLNVAL'), name : 'POLLNVAL value').stdout().strip() [ 'POLLHUP', 'g_pollhup' ],
[ 'POLLNVAL', 'g_pollnval' ],
glibconfig_conf.set('g_pollin', value_POLLIN) ]
glibconfig_conf.set('g_pollout', value_POLLOUT) foreach d : poll_defines
glibconfig_conf.set('g_pollpri', value_POLLPRI) val = cc.compute_int(d[0], prefix: poll_includes)
glibconfig_conf.set('g_pollerr', value_POLLERR) glibconfig_conf.set(d[1], val)
glibconfig_conf.set('g_pollhup', value_POLLHUP) endforeach
glibconfig_conf.set('g_pollnval', value_POLLNVAL)
# Internet address families # Internet address families
# FIXME: what about Cygwin (G_WITH_CYGWIN) # FIXME: what about Cygwin (G_WITH_CYGWIN)
if host_system == 'windows' if host_system == 'windows'
glib_inet_includes= ''' inet_includes = '''
#include <winsock2.h> #include <winsock2.h>'''
'''
else else
glib_inet_includes=''' inet_includes = '''
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>'''
'''
endif endif
net_defines = [ inet_defines = [
[ 'AF_UNIX', 'g_af_unix' ], [ 'AF_UNIX', 'g_af_unix' ],
[ 'AF_INET', 'g_af_inet' ], [ 'AF_INET', 'g_af_inet' ],
[ 'AF_INET6', 'g_af_inet6' ], [ 'AF_INET6', 'g_af_inet6' ],
@ -1394,18 +1383,8 @@ net_defines = [
[ 'MSG_PEEK', 'g_msg_peek' ], [ 'MSG_PEEK', 'g_msg_peek' ],
[ 'MSG_DONTROUTE', 'g_msg_dontroute' ], [ 'MSG_DONTROUTE', 'g_msg_dontroute' ],
] ]
foreach d : net_defines foreach d : inet_defines
templ = '''@0@ val = cc.compute_int(d[0], prefix: inet_includes)
#include <stdio.h>
int main(int argc, char **argv) {
printf("%d\n", (int)@1@);
return 0;
}'''
# FIXME: fix for cross-compilation
if not meson.has_exe_wrapper()
error('Fix sys define detection for cross build')
endif
val = cc.run(templ.format(glib_inet_includes, d[0]), name : d[0] + ' value').stdout().strip()
glibconfig_conf.set(d[1], val) glibconfig_conf.set(d[1], val)
endforeach endforeach