diff options
Diffstat (limited to 'docs/markdown')
-rw-r--r-- | docs/markdown/Reference-manual.md | 14 | ||||
-rw-r--r-- | docs/markdown/snippets/get-supported-arguments.md | 23 |
2 files changed, 32 insertions, 5 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index 91f7edd..3f25e80 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -1260,6 +1260,12 @@ the following methods: the positional argument, you can specify external dependencies to use with `dependencies` keyword argument. +- `compiles(code)` returns true if the code fragment given in the + positional argument compiles, you can specify external dependencies + to use with `dependencies` keyword argument, `code` can be either a + string containing source code or a `file` object pointing to the + source code. + - `compute_int(expr, ...')` computes the value of the given expression (as an example `1 + 2`). When cross compiling this is evaluated with an iterative algorithm, you can specify keyword arguments `low` @@ -1286,11 +1292,9 @@ the following methods: - `get_id()` returns a string identifying the compiler. For example, `gcc`, `msvc`, [and more](Compiler-properties.md#compiler-id). -- `compiles(code)` returns true if the code fragment given in the - positional argument compiles, you can specify external dependencies - to use with `dependencies` keyword argument, `code` can be either a - string containing source code or a `file` object pointing to the - source code. +- `get_supported_arguments(list_of_string)` returns an array + containing only the arguments supported by the compiler, as if + `has_argument` were called on them individually. - `has_argument(argument_name)` returns true if the compiler accepts the specified command line argument, that is, can compile code diff --git a/docs/markdown/snippets/get-supported-arguments.md b/docs/markdown/snippets/get-supported-arguments.md new file mode 100644 index 0000000..c0cc9bf --- /dev/null +++ b/docs/markdown/snippets/get-supported-arguments.md @@ -0,0 +1,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) |