meson.build 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. anti_pre_arg = '-Wno-format'
  32. arg = '-Werror=format-security'
  33. assert(not cc.has_multi_arguments([anti_pre_arg, arg]), 'Arg that should be broken is not.')
  34. assert(cc.has_multi_arguments(pre_arg), 'Arg that should have worked does not work.')
  35. assert(cc.has_multi_arguments([pre_arg, arg]), 'Arg that should have worked does not work.')
  36. endif
  37. if cc.get_id() == 'clang' and cc.version().version_compare('<=4.0.0')
  38. # 4.0.0 does not support -fpeel-loops. Newer versions may.
  39. # Please adjust above version number as new versions of clang are released.
  40. notyet_arg = '-fpeel-loops'
  41. assert(not cc.has_argument(notyet_arg), 'Arg that should be broken (unless clang added support recently) is not.')
  42. endif