1 | # This file sets the architecture-independent compiler flags used throughout
|
---|
2 | # this repository.
|
---|
3 | # For architecture-specific flags, see $srcroot/meson/cross/$arch.
|
---|
4 |
|
---|
5 | add_project_arguments(
|
---|
6 | # TODO: Remove from project arguments and only use where necessary.
|
---|
7 | # Any change in config forces everything to rebuild due to lack of granularity here.
|
---|
8 | '-imacros', meson.build_root() / 'config.h',
|
---|
9 | language : [ 'c' ],
|
---|
10 | )
|
---|
11 |
|
---|
12 | add_project_link_arguments(
|
---|
13 | cc.get_supported_link_arguments([
|
---|
14 | '-Wl,--gc-sections',
|
---|
15 | '-Wl,--warn-common',
|
---|
16 | ]),
|
---|
17 | '-Wl,--fatal-warnings',
|
---|
18 | language : [ 'c', 'cpp' ],
|
---|
19 | )
|
---|
20 |
|
---|
21 | # TODO: enable more warnings
|
---|
22 | # FIXME: -fno-builtin-strftime works around seemingly spurious format warning.
|
---|
23 | # We should investigate what's going on there.
|
---|
24 |
|
---|
25 | extra_common_flags = [
|
---|
26 | '-O' + OPTIMIZATION,
|
---|
27 | '-fexec-charset=UTF-8',
|
---|
28 | '-finput-charset=UTF-8',
|
---|
29 |
|
---|
30 | '-D_HELENOS_SOURCE',
|
---|
31 |
|
---|
32 | '-Wa,--fatal-warnings',
|
---|
33 |
|
---|
34 | '-Wall',
|
---|
35 | '-Wextra',
|
---|
36 | '-Werror-implicit-function-declaration',
|
---|
37 | '-Wwrite-strings',
|
---|
38 | '-Wunknown-pragmas',
|
---|
39 |
|
---|
40 | '-Wno-unused-parameter',
|
---|
41 |
|
---|
42 | '-pipe',
|
---|
43 |
|
---|
44 | '-ffunction-sections',
|
---|
45 | '-fno-common',
|
---|
46 | '-fdebug-prefix-map=' + meson.source_root() + '=.',
|
---|
47 | ]
|
---|
48 |
|
---|
49 | if cc.get_id() != 'clang'
|
---|
50 | # Clang's own headers emit macro redefinition warnings.
|
---|
51 | extra_common_flags += '-Wsystem-headers'
|
---|
52 | endif
|
---|
53 |
|
---|
54 | if UARCH != 'ia64'
|
---|
55 | extra_common_flags += [ '-fvar-tracking-assignments' ]
|
---|
56 | endif
|
---|
57 |
|
---|
58 | if CONFIG_DEBUG
|
---|
59 | extra_common_flags += [ '-Werror' ]
|
---|
60 | endif
|
---|
61 |
|
---|
62 | if CONFIG_LINE_DEBUG
|
---|
63 | extra_common_flags += [ '-gdwarf-4', '-g3' ]
|
---|
64 | endif
|
---|
65 |
|
---|
66 | extra_cflags = extra_common_flags + [
|
---|
67 | '-Wmissing-prototypes',
|
---|
68 |
|
---|
69 | '-Wno-missing-braces',
|
---|
70 | '-Wno-missing-field-initializers',
|
---|
71 | '-Wno-unused-command-line-argument',
|
---|
72 | '-Wno-unused-parameter',
|
---|
73 | '-Wno-typedef-redefinition',
|
---|
74 | '-Wno-clobbered',
|
---|
75 | '-Wno-nonnull-compare',
|
---|
76 |
|
---|
77 | '-fno-builtin-strftime',
|
---|
78 | ]
|
---|
79 |
|
---|
80 | if CONFIG_UBSAN
|
---|
81 | extra_cflags += '-fsanitize=undefined'
|
---|
82 | endif
|
---|
83 |
|
---|
84 | extra_cppflags = extra_common_flags + [
|
---|
85 | '-fno-exceptions',
|
---|
86 | '-frtti',
|
---|
87 | ]
|
---|
88 |
|
---|
89 | w_flags = {
|
---|
90 | 'c': extra_cflags,
|
---|
91 | 'cpp': extra_cppflags,
|
---|
92 | }
|
---|
93 |
|
---|
94 | # TODO: To remove noise in Meson output, we may want to cut down on
|
---|
95 | # the explicitly checked flags and just enable those supported by
|
---|
96 | # both gcc and clang unconditionally.
|
---|
97 |
|
---|
98 | # Process flags. Only sets those that compiler supports.
|
---|
99 | foreach lang : [ 'c', 'cpp' ]
|
---|
100 | extra_cflags = meson.get_compiler(lang).get_supported_arguments(w_flags.get(lang))
|
---|
101 | add_project_arguments(extra_cflags, language : [ lang ])
|
---|
102 | add_project_link_arguments(extra_cflags, language : [ lang ])
|
---|
103 | endforeach
|
---|