meson: Fix warnings when reading back and checking feature flags

Meson does not like comparing things of different types which is a
problem when reading back values of feature flags as they may contain
either false (bool) or 1 (string).

Since there is a strong reason why we use false when the feature does
not exist, we work around this issue by always converting the returned
value to int via to_int().

Fixes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1190
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
This commit is contained in:
Povilas Kanapickas 2021-06-26 09:44:39 +03:00
parent b2a0de4f07
commit b67e514dbb
2 changed files with 19 additions and 10 deletions

View File

@ -16,6 +16,15 @@ conf_data.set('HAVE_TYPEOF', cc.compiles('''
''',
name: 'typeof()') ? '1' : false)
# For feature macros we're using either false (boolean) or '1', which correspond to the macro being
# not defined at all and defined to 1. This is to match autotools behavior and thus preserve
# backwards compatibility with all the existing code that uses #ifdef to check if feature is
# enabled. This ifdef would pass if the macro is defined to 0 which would silently break code
# in various places.
#
# As a complication when we read the configuration from conf_data back we get either string or
# bool. Meson does not like comparing things of different types so we always convert the returned
# value to an integer using to_int().
conf_data.set('MONOTONIC_CLOCK', cc.has_function('clock_gettime') and
cc.compiles('''
#define _POSIX_C_SOURCE 200112L
@ -181,7 +190,7 @@ if cc.has_header_symbol('sys/socket.h', 'SCM_RIGHTS')
conf_data.set('XTRANS_SEND_FDS', '1')
endif
if conf_data.get('HAVE_GETPEEREID') == false and conf_data.get('HAVE_GETPEERUCRED') == false
if conf_data.get('HAVE_GETPEEREID').to_int() == 0 and conf_data.get('HAVE_GETPEERUCRED').to_int() == 0
if not cc.has_header_symbol('sys/socket.h', 'SO_PEERCRED')
conf_data.set('NO_LOCAL_CLIENT_CRED', 1)
endif

View File

@ -21,32 +21,32 @@ srcs_os = [
# Wrapper code for missing C library functions. Note that conf_data contains either '1' or false.
srcs_libc = []
if conf_data.get('HAVE_REALLOCARRAY') == false
if conf_data.get('HAVE_REALLOCARRAY').to_int() == 0
srcs_libc += 'reallocarray.c'
endif
if conf_data.get('HAVE_STRCASECMP') == false
if conf_data.get('HAVE_STRCASECMP').to_int() == 0
srcs_libc += 'strcasecmp.c'
endif
if conf_data.get('HAVE_STRCASESTR') == false
if conf_data.get('HAVE_STRCASESTR').to_int() == 0
srcs_libc += 'strcasestr.c'
endif
if conf_data.get('HAVE_STRLCAT') == false
if conf_data.get('HAVE_STRLCAT').to_int() == 0
srcs_libc += 'strlcat.c'
endif
if conf_data.get('HAVE_STRLCPY') == false
if conf_data.get('HAVE_STRLCPY').to_int() == 0
srcs_libc += 'strlcpy.c'
endif
if conf_data.get('HAVE_STRNDUP') == false
if conf_data.get('HAVE_STRNDUP').to_int() == 0
srcs_libc += 'strndup.c'
endif
if conf_data.get('HAVE_TIMINGSAFE_MEMCMP') == false
if conf_data.get('HAVE_TIMINGSAFE_MEMCMP').to_int() == 0
srcs_libc += 'timingsafe_memcmp.c'
endif
if conf_data.get('HAVE_POLL') == false
if conf_data.get('HAVE_POLL').to_int() == 0
srcs_os += 'xserver_poll.c'
endif
if conf_data.get('BUSFAULT') != false
if conf_data.get('BUSFAULT').to_int() != 0
srcs_os += 'busfault.c'
endif