meson.build 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. project('get define', 'c', 'cpp')
  2. host_system = host_machine.system()
  3. foreach lang : ['c', 'cpp']
  4. cc = meson.get_compiler(lang)
  5. if host_system == 'linux'
  6. d = cc.get_define('__linux__')
  7. assert(d == '1', '__linux__ value is @0@ instead of 1'.format(d))
  8. elif host_system == 'darwin'
  9. d = cc.get_define('__APPLE__')
  10. assert(d == '1', '__APPLE__ value is @0@ instead of 1'.format(d))
  11. elif host_system == 'windows'
  12. d = cc.get_define('_WIN32')
  13. assert(d == '1', '_WIN32 value is @0@ instead of 1'.format(d))
  14. elif host_system == 'cygwin'
  15. d = cc.get_define('__CYGWIN__')
  16. assert(d == '1', '__CYGWIN__ value is @0@ instead of 1'.format(d))
  17. elif host_system == 'haiku'
  18. d = cc.get_define('__HAIKU__')
  19. assert(d == '1', '__HAIKU__ value is @0@ instead of 1'.format(d))
  20. else
  21. error('Please report a bug and help us improve support for this platform')
  22. endif
  23. if cc.find_library('z', required : false).found()
  24. # When a C file containing #include <foo.h> is pre-processed and foo.h is
  25. # found in the compiler's default search path, GCC inserts an extra comment
  26. # between the delimiter and the define which causes a parsing error.
  27. # https://github.com/mesonbuild/meson/issues/1726
  28. ver = cc.get_define('ZLIB_VER_MAJOR', prefix : '#include <zlib.h>')
  29. assert(ver == '1', 'ZLIB_VER_MAJOR value is "@0@" instead of "1"'.format(ver))
  30. endif
  31. # Check that an undefined value is empty.
  32. have = cc.get_define('MESON_FAIL_VALUE')
  33. assert(have == '', 'MESON_FAIL_VALUE value is "@0@" instead of ""'.format(have))
  34. # This is used in the test_preprocessor_checks_CPPFLAGS() unit test.
  35. have = cc.get_define('MESON_TEST_DEFINE_VALUE')
  36. expect = get_option('MESON_TEST_DEFINE_VALUE')
  37. assert(have == expect, 'MESON_TEST_DEFINE_VALUE value is "@0@" instead of "@1@"'.format(have, expect))
  38. run_1665_test = false
  39. if meson.is_cross_build()
  40. # Can't use an empty array as a fallback here because of
  41. # https://github.com/mesonbuild/meson/issues/1481
  42. lang_args = meson.get_cross_property(lang + '_args', false)
  43. if lang_args != false
  44. foreach lang_arg : lang_args
  45. if lang_arg.contains('MESON_TEST_ISSUE_1665')
  46. run_1665_test = true
  47. endif
  48. endforeach
  49. endif
  50. endif
  51. if run_1665_test
  52. have = cc.get_define('MESON_TEST_ISSUE_1665')
  53. assert(have == '1', 'MESON_TEST_ISSUE_1665 value is "@0@" instead of "1"'.format(have))
  54. endif
  55. endforeach