diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2017-09-29 11:52:06 -0700 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2018-09-07 11:52:15 -0700 |
commit | 51e9db370a0ebccaf220e171c3444a0f2c4e1723 (patch) | |
tree | 1636eec99faf01aeb6e08c0753fa4503fdbdbb38 /docs | |
parent | 8ca463f9f1d432d059c12da42a18fd13b4604b57 (diff) | |
download | meson-51e9db370a0ebccaf220e171c3444a0f2c4e1723.zip meson-51e9db370a0ebccaf220e171c3444a0f2c4e1723.tar.gz meson-51e9db370a0ebccaf220e171c3444a0f2c4e1723.tar.bz2 |
Add method to check for C/C++ function attributes
It's fairly common on Linux and *BSD platforms to check for these
attributes existence, so it makes sense to me to have this checking
build into meson itself. Autotools also has a builtin for handling
these, and by building them in we can short circuit cases that we know
that these don't exist (MSVC).
Additionally this adds support for two common MSVC __declspec
attributes, dllimport and dllexport. This implements the declspec
version (even though GCC has an __attribute__ version that both it and
clang support), since GCC and Clang support the MSVC version as well.
Thus it seems reasonable to assume that most projects will use the
__declspec version over teh __attribute__ version.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/markdown/Reference-manual.md | 12 | ||||
-rw-r--r-- | docs/markdown/Reference-tables.md | 63 | ||||
-rw-r--r-- | docs/markdown/snippets/function_attributes.md | 29 |
3 files changed, 104 insertions, 0 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index e59c153..71771a5 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -1753,6 +1753,18 @@ the following methods: - `version()` returns the compiler's version number as a string. +- `has_function_attribute(name)` *(added in 0.48.0)* returns `true` if the + compiler supports the GNU style (`__attribute__(...)`) `name`. This is + preferable to manual compile checks as it may be optimized for compilers that + do not support such attributes. + [This table](Reference-tables.html#gcc-attribute-support) Lists all of the + supported attributes. + +- `get_supported_function_attributes(list_of_names)` *(added in 0.48.0) + returns an array containing any names that are supported GCC style + attributes. Equivalent to `has_function_attribute` was called on each of them + individually. + The following keyword arguments can be used: - `args` can be used to pass a list of compiler arguments that are diff --git a/docs/markdown/Reference-tables.md b/docs/markdown/Reference-tables.md index 46bcc3d..ab79abd 100644 --- a/docs/markdown/Reference-tables.md +++ b/docs/markdown/Reference-tables.md @@ -99,3 +99,66 @@ These are the parameter names for passing language specific arguments to your bu | Objective C++ | objcpp_args | | Rust | rust_args | | Vala | vala_args | + + +## Function Attributes + +These are the parameters names that are supported using +`compiler.has_function_attribute()` or +`compiler.get_supported_function_attributes()` + +### GCC __attribute__ + +These values are supported using the GCC style `__attribute__` annotations, +which are supported by GCC, Clang, and other compilers. + + +| Name | +|----------------------| +| alias | +| aligned | +| alloc_size | +| always_inline | +| artificial | +| cold | +| const | +| constructor | +| constructor_priority | +| deprecated | +| destructor | +| error | +| externally_visible | +| fallthrough | +| flatten | +| format | +| format_arg | +| gnu_inline | +| hot | +| ifunc | +| malloc | +| noclone | +| noinline | +| nonnull | +| noreturn | +| nothrow | +| optimize | +| packed | +| pure | +| returns_nonnull | +| unused | +| used | +| visibility | +| warning | +| warn_unused_result | +| weak | +| weakreaf | + +### MSVC __declspec + +These values are supported using the MSVC style `__declspec` annotation, +which are supported by MSVC, GCC, Clang, and other compilers. + +| Name | +|----------------------| +| dllexport | +| dllimport | diff --git a/docs/markdown/snippets/function_attributes.md b/docs/markdown/snippets/function_attributes.md new file mode 100644 index 0000000..5514494 --- /dev/null +++ b/docs/markdown/snippets/function_attributes.md @@ -0,0 +1,29 @@ +## Helper methods added for checking GNU style attributes: __attribute__(...) + +A set of new helpers have been added to the C and C++ compiler objects for +checking GNU style function attributes. These are not just simpler to use, they +may be optimized to return fast on compilers that don't support these +attributes. Currently this is true for MSVC. + +```meson +cc = meson.get_compiler('c') +if cc.has_function_attribute('aligned') + add_project_arguments('-DHAVE_ALIGNED', language : 'c') +endif +``` + +Would replace code like: + +```meson +if cc.compiles('''into foo(void) __attribute__((aligned(32)))''') + add_project_arguments('-DHAVE_ALIGNED', language : 'c') +endif +``` + +Additionally, a multi argument version has been added: + +```meson +foreach s : cc.get_supported_function_attributes(['hidden', 'alias']) + add_project_arguments('-DHAVE_@0@'.format(s.to_upper()), language : 'c') +endforeach +``` |