aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2020-07-08 15:22:06 -0400
committerXavier Claessens <xclaesse@gmail.com>2020-07-22 19:19:50 -0400
commitc016401f95bce461a9acefc86bb75884684d9a5f (patch)
treebe9a48db8a29e47d72e5a4e1f5fb08a29516ad42
parent6bf61b2a384ab42c679097ea749f8c5235f1e9f8 (diff)
downloadmeson-c016401f95bce461a9acefc86bb75884684d9a5f.zip
meson-c016401f95bce461a9acefc86bb75884684d9a5f.tar.gz
meson-c016401f95bce461a9acefc86bb75884684d9a5f.tar.bz2
coredata: Make warning_level per subproject builtin option
-rw-r--r--docs/markdown/Builtin-options.md61
-rw-r--r--docs/markdown/snippets/per_subproject.md4
-rw-r--r--mesonbuild/coredata.py2
-rw-r--r--test cases/common/230 persubproject options/meson.build4
-rw-r--r--test cases/common/230 persubproject options/subprojects/sub1/foo.c3
-rw-r--r--test cases/common/230 persubproject options/subprojects/sub1/meson.build4
6 files changed, 54 insertions, 24 deletions
diff --git a/docs/markdown/Builtin-options.md b/docs/markdown/Builtin-options.md
index e7101d5..6234ecf 100644
--- a/docs/markdown/Builtin-options.md
+++ b/docs/markdown/Builtin-options.md
@@ -59,27 +59,27 @@ Options that are labeled "per machine" in the table are set per machine. See
the [specifying options per machine](#Specifying-options-per-machine) section
for details.
-| Option | Default value | Description | Is per machine |
-| ------ | ------------- | ----------- | -------------- |
-| auto_features {enabled, disabled, auto} | auto | Override value of all 'auto' features | no |
-| backend {ninja, vs,<br>vs2010, vs2015, vs2017, vs2019, xcode} | ninja | Backend to use | no |
-| buildtype {plain, debug,<br>debugoptimized, release, minsize, custom} | debug | Build type to use | no |
-| debug | true | Debug | no |
-| default_library {shared, static, both} | shared | Default library type | no |
-| errorlogs | true | Whether to print the logs from failing tests. | no |
-| install_umask {preserve, 0000-0777} | 022 | Default umask to apply on permissions of installed files | no |
-| layout {mirror,flat} | mirror | Build directory layout | no |
-| optimization {0, g, 1, 2, 3, s} | 0 | Optimization level | no |
-| pkg_config_path {OS separated path} | '' | Additional paths for pkg-config to search before builtin paths | yes |
-| cmake_prefix_path | [] | Additional prefixes for cmake to search before builtin paths | yes |
-| stdsplit | true | Split stdout and stderr in test logs | no |
-| strip | false | Strip targets on install | no |
-| unity {on, off, subprojects} | off | Unity build | no |
-| unity_size {>=2} | 4 | Unity file block size | no |
-| warning_level {0, 1, 2, 3} | 1 | Set the warning level. From 0 = none to 3 = highest | no |
-| werror | false | Treat warnings as errors | no |
-| wrap_mode {default, nofallback,<br>nodownload, forcefallback} | default | Wrap mode to use | no |
-| force_fallback_for | [] | Force fallback for those dependencies | no |
+| Option | Default value | Description | Is per machine | Is per subproject |
+| ------ | ------------- | ----------- | -------------- | ----------------- |
+| auto_features {enabled, disabled, auto} | auto | Override value of all 'auto' features | no | no |
+| backend {ninja, vs,<br>vs2010, vs2015, vs2017, vs2019, xcode} | ninja | Backend to use | no | no |
+| buildtype {plain, debug,<br>debugoptimized, release, minsize, custom} | debug | Build type to use | no | no |
+| debug | true | Debug | no | no |
+| default_library {shared, static, both} | shared | Default library type | no | yes |
+| errorlogs | true | Whether to print the logs from failing tests. | no | no |
+| install_umask {preserve, 0000-0777} | 022 | Default umask to apply on permissions of installed files | no | no |
+| layout {mirror,flat} | mirror | Build directory layout | no | no |
+| optimization {0, g, 1, 2, 3, s} | 0 | Optimization level | no | no |
+| pkg_config_path {OS separated path} | '' | Additional paths for pkg-config to search before builtin paths | yes | no |
+| cmake_prefix_path | [] | Additional prefixes for cmake to search before builtin paths | yes | no |
+| stdsplit | true | Split stdout and stderr in test logs | no | no |
+| strip | false | Strip targets on install | no | no |
+| unity {on, off, subprojects} | off | Unity build | no | no |
+| unity_size {>=2} | 4 | Unity file block size | no | no |
+| warning_level {0, 1, 2, 3} | 1 | Set the warning level. From 0 = none to 3 = highest | no | yes |
+| werror | false | Treat warnings as errors | no | yes |
+| wrap_mode {default, nofallback,<br>nodownload, forcefallback} | default | Wrap mode to use | no | no |
+| force_fallback_for | [] | Force fallback for those dependencies | no | no |
<a name="build-type-options"></a>
For setting optimization levels and toggling debug, you can either set the
@@ -215,3 +215,22 @@ the command line, as there was no `build.` prefix. Similarly named fields in
the `[properties]` section of the cross file would effect cross compilers, but
the code paths were fairly different allowing differences in behavior to crop
out.
+
+## Specifying options per subproject
+
+Since *0.54.0* `default_library` and `werror` built-in options can be defined
+per subproject. This is useful for example when building shared libraries in the
+main project, but static link a subproject, or when the main project must build
+with no warnings but some subprojects cannot.
+
+Most of the time this would be used either by the parent project by setting
+subproject's default_options (e.g. `subproject('foo', default_options: 'default_library=static')`),
+or by the user using the command line `-Dfoo:default_library=static`.
+
+The value is overriden in this order:
+- Value from parent project
+- Value from subproject's default_options if set
+- Value from subproject() default_options if set
+- Value from command line if set
+
+Since 0.56.0 `warning_level` can also be defined per subproject.
diff --git a/docs/markdown/snippets/per_subproject.md b/docs/markdown/snippets/per_subproject.md
new file mode 100644
index 0000000..6de6068
--- /dev/null
+++ b/docs/markdown/snippets/per_subproject.md
@@ -0,0 +1,4 @@
+## Per subproject `warning_level` option
+
+`warning_level` can now be defined per subproject, in the same way as
+`default_library` and `werror`.
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index af43b31..e2a6954 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -1182,7 +1182,7 @@ builtin_options = OrderedDict([
('strip', BuiltinOption(UserBooleanOption, 'Strip targets on install', False)),
('unity', BuiltinOption(UserComboOption, 'Unity build', 'off', choices=['on', 'off', 'subprojects'])),
('unity_size', BuiltinOption(UserIntegerOption, 'Unity block size', (2, None, 4))),
- ('warning_level', BuiltinOption(UserComboOption, 'Compiler warning level to use', '1', choices=['0', '1', '2', '3'])),
+ ('warning_level', BuiltinOption(UserComboOption, 'Compiler warning level to use', '1', choices=['0', '1', '2', '3'], yielding=False)),
('werror', BuiltinOption(UserBooleanOption, 'Treat warnings as errors', False, yielding=False)),
('wrap_mode', BuiltinOption(UserComboOption, 'Wrap mode', 'default', choices=['default', 'nofallback', 'nodownload', 'forcefallback'])),
('force_fallback_for', BuiltinOption(UserArrayOption, 'Force fallback for those subprojects', [])),
diff --git a/test cases/common/230 persubproject options/meson.build b/test cases/common/230 persubproject options/meson.build
index 20dff90..f76a70c 100644
--- a/test cases/common/230 persubproject options/meson.build
+++ b/test cases/common/230 persubproject options/meson.build
@@ -1,9 +1,11 @@
project('persubproject options', 'c',
default_options : ['default_library=both',
- 'werror=true'])
+ 'werror=true',
+ 'warning_level=3'])
assert(get_option('default_library') == 'both', 'Parent default_library should be "both"')
assert(get_option('werror'))
+assert(get_option('warning_level') == '3')
# Check it build both by calling a method only both_libraries target implement
lib = library('lib1', 'foo.c')
diff --git a/test cases/common/230 persubproject options/subprojects/sub1/foo.c b/test cases/common/230 persubproject options/subprojects/sub1/foo.c
index 63e4de6..82ad2c2 100644
--- a/test cases/common/230 persubproject options/subprojects/sub1/foo.c
+++ b/test cases/common/230 persubproject options/subprojects/sub1/foo.c
@@ -1,5 +1,8 @@
int foo(void);
int foo(void) {
+ /* This is built with -Werror, it would error if warning_level=3 was inherited
+ * from main project and not overridden by this subproject's default_options. */
+ int x;
return 0;
}
diff --git a/test cases/common/230 persubproject options/subprojects/sub1/meson.build b/test cases/common/230 persubproject options/subprojects/sub1/meson.build
index 7afc934..4e4bc1b 100644
--- a/test cases/common/230 persubproject options/subprojects/sub1/meson.build
+++ b/test cases/common/230 persubproject options/subprojects/sub1/meson.build
@@ -1,6 +1,8 @@
-project('sub1', 'c')
+project('sub1', 'c',
+ default_options : ['warning_level=0'])
assert(get_option('default_library') == 'both', 'Should inherit parent project default_library')
+assert(get_option('warning_level') == '0')
# Check it build both by calling a method only both_libraries target implement
lib = library('lib1', 'foo.c')