summaryrefslogtreecommitdiff
path: root/test cases/common
diff options
context:
space:
mode:
authorMarvin Scholz <epirat07@gmail.com>2023-09-06 03:12:55 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2023-09-07 00:45:38 +0300
commit3fc16f05b513f26aa5da614673116074f5d60396 (patch)
tree4227d8e3c741ecefb8fc8849cd25e1399f004741 /test cases/common
parent346a9157436fb88fbf38e2d1284fa7373c14d4a1 (diff)
downloadmeson-3fc16f05b513f26aa5da614673116074f5d60396.tar.gz
Add compiler.has_define
Adds a new method to the compiler object, has_define. This makes it possible to check if a preprocessor macro/define is set or not. This is especially helpful if the define in question is empty, for example: #define MESON_EMPTY_DEFINE This would yield the same results as a missing define with the existing get_define method, as it would return an empty string for both cases. Therefore this additional method is needed.
Diffstat (limited to 'test cases/common')
-rw-r--r--test cases/common/132 get define/meson.build89
1 files changed, 49 insertions, 40 deletions
diff --git a/test cases/common/132 get define/meson.build b/test cases/common/132 get define/meson.build
index 02e5a0c95..019b17afc 100644
--- a/test cases/common/132 get define/meson.build
+++ b/test cases/common/132 get define/meson.build
@@ -2,49 +2,50 @@ project('get define', 'c', 'cpp')
host_system = host_machine.system()
+system_define_map = {
+ 'linux' : ['__linux__', '1'],
+ 'darwin' : ['__APPLE__', '1'],
+ 'windows' : ['_WIN32', '1'],
+ 'cygwin' : ['__CYGWIN__', '1'],
+ 'haiku' : ['__HAIKU__', '1'],
+ 'dragonfly' : ['__DragonFly__', '1'],
+ 'netbsd' : ['__NetBSD__', '1'],
+ 'openbsd' : ['__OpenBSD__', '1'],
+ 'gnu' : ['__GNU__', '1'],
+ 'sunos' : ['__sun__', '1'],
+
+ # The __FreeBSD__ define will be equal to the major version of the release
+ # (ex, in FreeBSD 11.x, __FreeBSD__ == 11). To make the test robust when
+ # being run on various versions of FreeBSD, just test that the define is
+ # set.
+ 'freebsd' : ['__FreeBSD__'],
+}
+
foreach lang : ['c', 'cpp']
cc = meson.get_compiler(lang)
- if host_system == 'linux'
- d = cc.get_define('__linux__')
- assert(d == '1', '__linux__ value is @0@ instead of 1'.format(d))
- elif host_system == 'darwin'
- d = cc.get_define('__APPLE__')
- assert(d == '1', '__APPLE__ value is @0@ instead of 1'.format(d))
- elif host_system == 'windows'
- d = cc.get_define('_WIN32')
- assert(d == '1', '_WIN32 value is @0@ instead of 1'.format(d))
- elif host_system == 'cygwin'
- d = cc.get_define('__CYGWIN__')
- assert(d == '1', '__CYGWIN__ value is @0@ instead of 1'.format(d))
- elif host_system == 'haiku'
- d = cc.get_define('__HAIKU__')
- assert(d == '1', '__HAIKU__ value is @0@ instead of 1'.format(d))
- elif host_system == 'freebsd'
- # the __FreeBSD__ define will be equal to the major version of the release
- # (ex, in FreeBSD 11.x, __FreeBSD__ == 11). To make the test robust when
- # being run on various versions of FreeBSD, just test that the define is
- # set.
- d = cc.get_define('__FreeBSD__')
- assert(d != '', '__FreeBSD__ value is unset')
- elif host_system == 'dragonfly'
- d = cc.get_define('__DragonFly__')
- assert(d == '1', '__DragonFly__ value is @0@ instead of 1'.format(d))
- elif host_system == 'netbsd'
- d = cc.get_define('__NetBSD__')
- assert(d == '1', '__NetBSD__ value is @0@ instead of 1'.format(d))
- elif host_system == 'openbsd'
- d = cc.get_define('__OpenBSD__')
- assert(d == '1', '__OpenBSD__ value is @0@ instead of 1'.format(d))
- elif host_system == 'gnu'
- d = cc.get_define('__GNU__')
- assert(d == '1', '__GNU__ value is @0@ instead of 1'.format(d))
- elif host_system == 'sunos'
- d = cc.get_define('__sun__')
- assert(d == '1', '__sun__ value is @0@ instead of 1'.format(d))
- else
+
+ if not system_define_map.has_key(host_system)
error('Please report a bug and help us improve support for this platform')
endif
+ system_define = system_define_map.get(host_system)
+
+ def_name = system_define[0]
+ def_val = cc.get_define(system_define[0])
+ def_exist = cc.has_define(system_define[0])
+
+ assert((def_val != '') == def_exist,
+ 'The has_define and get_define results for @0@ disagree with each other'.format(def_name))
+
+ if system_define.length() == 2
+ assert(def_val == system_define[1],
+ '@0@ value is @1@ instead of @2@'.format(def_name, def_val, system_define[1]))
+ elif system_define.length() == 1
+ assert(def_val != '', '@0@ value is unset'.format(def_name))
+ else
+ assert('Invalid number of items in system_define array, this is a bug in the test!')
+ endif
+
if cc.find_library('z', required : false).found()
# When a C file containing #include <foo.h> is pre-processed and foo.h is
# found in the compiler's default search path, GCC inserts an extra comment
@@ -63,8 +64,16 @@ foreach lang : ['c', 'cpp']
endif
# Check that an undefined value is empty.
- have = cc.get_define('MESON_FAIL_VALUE')
- assert(have == '', 'MESON_FAIL_VALUE value is "@0@" instead of ""'.format(have))
+ have_val = cc.get_define('MESON_FAIL_VALUE')
+ have = cc.has_define('MESON_FAIL_VALUE')
+ assert(have_val == '', 'MESON_FAIL_VALUE value is "@0@" instead of ""'.format(have_val))
+ assert(not have, 'MESON_FAIL_VALUE was found even though it should not have been')
+
+ # Check that an empty define is reported as existing.
+ have_val = cc.get_define('MESON_EMPTY_VALUE', prefix: ['#define MESON_EMPTY_VALUE'])
+ have = cc.has_define('MESON_EMPTY_VALUE', prefix: ['#define MESON_EMPTY_VALUE'])
+ assert(have_val == '', 'MESON_EMPTY_VALUE value is "@0@" instead of ""'.format(have_val))
+ assert(have, 'MESON_EMPTY_VALUE was not found even though it should have been')
# Check if prefix array works properly and has the expected order
have = cc.get_define('MESON_FAIL_VALUE', prefix: ['#define MESON_FAIL_VALUE 1', '#undef MESON_FAIL_VALUE'])