From e1ffae0580259343be7665c6b2f014fe71b8c05c Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Wed, 12 Apr 2017 16:00:48 +0100 Subject: Add Compiler.get_supported_arguments() Add a helper for the common pattern of: args_to_use = [] foreach arg : candidate_args if cc.has_argument(arg) args_to_use += arg endif endforeach Replaced with: args_to_use = cc.get_supported_arguments(candidate_args) --- docs/markdown/Reference-manual.md | 4 ++++ docs/markdown/snippets/get-supported-arguments.md | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 docs/markdown/snippets/get-supported-arguments.md (limited to 'docs/markdown') 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) -- cgit v1.1 From 552c15b978434456780f9efea1e7f05b21b1208f Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Thu, 31 Aug 2017 18:31:12 +0100 Subject: Alphabetize compiler.compiles() --- docs/markdown/Reference-manual.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'docs/markdown') diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index e388878..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` @@ -1290,12 +1296,6 @@ the following methods: 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 - string containing source code or a `file` object pointing to the - source code. - - `has_argument(argument_name)` returns true if the compiler accepts the specified command line argument, that is, can compile code without erroring out or printing a warning about an unknown flag, -- cgit v1.1