aboutsummaryrefslogtreecommitdiff
path: root/docs/markdown/snippets/get-supported-arguments.md
blob: c0cc9bfd38269996b4bff1baa66036d6ea04074e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Easier handling of supported compiler arguments

A common pattern for handling multiple desired compiler arguments, was to
test their presence and add them to an array one-by-one, e.g.:

    warning_flags_maybe = [
      '-Wsomething',
      '-Wanother-thing',
      '-Wno-the-other-thing',
    ]
    warning_flags = []
    foreach flag : warning_flags_maybe
      if cc.has_argument(flag)
        warning_flags += flag
      endif
    endforeach
    cc.add_project_argument(warning_flags)

A helper has been added for the foreach/has_argument pattern, so you can
now simply do:

    warning_flags = [ ... ]
    flags = cc.get_supported_flags(warning_flags)