meson.build 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. project('has arg', 'c', 'cpp')
  2. cc = meson.get_compiler('c')
  3. cpp = meson.get_compiler('cpp')
  4. if cc.get_id() == 'msvc'
  5. is_arg = '/O2'
  6. useless = '/DFOO'
  7. else
  8. is_arg = '-O2'
  9. useless = '-DFOO'
  10. endif
  11. isnt_arg = '-fiambroken'
  12. assert(cc.has_argument(is_arg), 'Arg that should have worked does not work.')
  13. assert(not cc.has_argument(isnt_arg), 'Arg that should be broken is not.')
  14. assert(cpp.has_argument(is_arg), 'Arg that should have worked does not work.')
  15. assert(not cpp.has_argument(isnt_arg), 'Arg that should be broken is not.')
  16. assert(cc.get_supported_arguments([is_arg, isnt_arg, useless]) == [is_arg, useless], 'Arg filtering returned different result.')
  17. assert(cpp.get_supported_arguments([is_arg, isnt_arg, useless]) == [is_arg, useless], 'Arg filtering returned different result.')
  18. # Have useless at the end to ensure that the search goes from front to back.
  19. l1 = cc.first_supported_argument([isnt_arg, is_arg, isnt_arg, useless])
  20. l2 = cc.first_supported_argument(isnt_arg, isnt_arg, isnt_arg)
  21. assert(l1.length() == 1, 'First supported returned wrong result.')
  22. assert(l1.get(0) == is_arg, 'First supported returned wrong argument.')
  23. assert(l2.length() == 0, 'First supported did not return empty array.')
  24. l1 = cpp.first_supported_argument([isnt_arg, is_arg, isnt_arg, useless])
  25. l2 = cpp.first_supported_argument(isnt_arg, isnt_arg, isnt_arg)
  26. assert(l1.length() == 1, 'First supported returned wrong result.')
  27. assert(l1.get(0) == is_arg, 'First supported returned wrong argument.')
  28. assert(l2.length() == 0, 'First supported did not return empty array.')
  29. if cc.get_id() == 'gcc'
  30. pre_arg = '-Wformat'
  31. # NOTE: We have special handling for -Wno-foo args because gcc silently
  32. # ignores unknown -Wno-foo args unless you pass -Werror, so for this test, we
  33. # pass it as two separate arguments.
  34. anti_pre_arg = ['-W', 'no-format']
  35. arg = '-Werror=format-security'
  36. assert(not cc.has_multi_arguments([anti_pre_arg, arg]), 'Arg that should be broken is not.')
  37. assert(cc.has_multi_arguments(pre_arg), 'Arg that should have worked does not work.')
  38. assert(cc.has_multi_arguments([pre_arg, arg]), 'Arg that should have worked does not work.')
  39. # Test that gcc correctly errors out on unknown -Wno flags
  40. assert(not cc.has_argument('-Wno-lol-meson-test-flags'), 'should error out on unknown -Wno args')
  41. assert(not cc.has_multi_arguments(['-Wno-pragmas', '-Wno-lol-meson-test-flags']), 'should error out even if some -Wno args are valid')
  42. endif
  43. if cc.get_id() == 'clang' and cc.version().version_compare('<=4.0.0')
  44. # 4.0.0 does not support -fpeel-loops. Newer versions may.
  45. # Please adjust above version number as new versions of clang are released.
  46. notyet_arg = '-fpeel-loops'
  47. assert(not cc.has_argument(notyet_arg), 'Arg that should be broken (unless clang added support recently) is not.')
  48. endif