aboutsummaryrefslogtreecommitdiff
path: root/docs/markdown
diff options
context:
space:
mode:
Diffstat (limited to 'docs/markdown')
-rw-r--r--docs/markdown/Reference-manual.md4
-rw-r--r--docs/markdown/snippets/get-supported-arguments.md23
2 files changed, 27 insertions, 0 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md
index 91f7edd..e388878 100644
--- a/docs/markdown/Reference-manual.md
+++ b/docs/markdown/Reference-manual.md
@@ -1286,6 +1286,10 @@ the following methods:
- `get_id()` returns a string identifying the compiler. For example,
`gcc`, `msvc`, [and more](Compiler-properties.md#compiler-id).
+- `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.
+
- `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
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)