Debian Codegraph @

meson/warnings/meson.build

raw
1 # Copyright 2020-2022 David Robillard <[email protected]>
2 # SPDX-License-Identifier: CC0-1.0 OR ISC
3
4 # General code to enable approximately all warnings in GCC 12, clang, and MSVC.
5 #
6 # This is trivial for clang and MSVC, but GCC doesn't have an "everything"
7 # option, so we need to enable everything we want explicitly. Wall is assumed,
8 # but Wextra is not, for stability.
9 #
10 # These are collected from common.opt and c.opt in the GCC source, and manually
11 # curated with the help of the GCC documentation. Warnings that are
12 # application-specific, historical, or about compatibility between specific
13 # language revisions are omitted. The intent here is to have roughly the same
14 # meaning as clang's Weverything: extremely strict, but general. Specifically
15 # omitted are:
16 #
17 # General:
18 #
19 # Wabi=
20 # Waggregate-return
21 # Walloc-size-larger-than=BYTES
22 # Walloca-larger-than=BYTES
23 # Wframe-larger-than=BYTES
24 # Wlarger-than=BYTES
25 # Wstack-usage=BYTES
26 # Wsystem-headers
27 # Wtraditional
28 # Wtraditional-conversion
29 # Wtrampolines
30 # Wvla-larger-than=BYTES
31 #
32 # Build specific:
33 #
34 # Wpoison-system-directories
35 #
36 # C Specific:
37 #
38 # Wc11-c2x-compat
39 # Wc90-c99-compat
40 # Wc99-c11-compat
41 # Wdeclaration-after-statement
42 # Wtraditional
43 # Wtraditional-conversion
44 #
45 # C++ Specific:
46 #
47 # Wc++0x-compat
48 # Wc++1z-compat
49 # Wc++2a-compat
50 # Wctad-maybe-unsupported
51 # Wnamespaces
52 # Wtemplates
53
54 # GCC warnings that apply to all C-family languages
55 gcc_common_warnings = [
56 '-Walloc-zero',
57 '-Walloca',
58 '-Wanalyzer-too-complex',
59 '-Warith-conversion',
60 '-Warray-bounds=2',
61 '-Wattribute-alias=2',
62 '-Wbidi-chars=ucn',
63 '-Wcast-align=strict',
64 '-Wcast-function-type',
65 '-Wcast-qual',
66 '-Wclobbered',
67 '-Wconversion',
68 '-Wdate-time',
69 '-Wdisabled-optimization',
70 '-Wdouble-promotion',
71 '-Wduplicated-branches',
72 '-Wduplicated-cond',
73 '-Wempty-body',
74 '-Wendif-labels',
75 '-Wfloat-equal',
76 '-Wformat-overflow=2',
77 '-Wformat-signedness',
78 '-Wformat-truncation=2',
79 '-Wformat=2',
80 '-Wignored-qualifiers',
81 '-Wimplicit-fallthrough=3',
82 '-Winit-self',
83 '-Winline',
84 '-Winvalid-pch',
85 '-Wlogical-op',
86 '-Wmissing-declarations',
87 '-Wmissing-field-initializers',
88 '-Wmissing-include-dirs',
89 '-Wmultichar',
90 '-Wnormalized=nfc',
91 '-Wnull-dereference',
92 '-Wopenacc-parallelism',
93 '-Woverlength-strings',
94 '-Wpacked',
95 '-Wpacked-bitfield-compat',
96 '-Wpadded',
97 '-Wpointer-arith',
98 '-Wredundant-decls',
99 '-Wshadow',
100 '-Wshift-negative-value',
101 '-Wshift-overflow=2',
102 '-Wstack-protector',
103 '-Wstrict-aliasing=3',
104 '-Wstrict-overflow=5',
105 '-Wstring-compare',
106 '-Wstringop-overflow=3',
107 '-Wsuggest-attribute=cold',
108 '-Wsuggest-attribute=const',
109 '-Wsuggest-attribute=format',
110 '-Wsuggest-attribute=malloc',
111 '-Wsuggest-attribute=noreturn',
112 '-Wsuggest-attribute=pure',
113 '-Wswitch-default',
114 '-Wswitch-enum',
115 '-Wtrampolines',
116 '-Wtrivial-auto-var-init',
117 '-Wtype-limits',
118 '-Wundef',
119 '-Wuninitialized',
120 '-Wunsafe-loop-optimizations',
121 '-Wunused',
122 '-Wunused-const-variable=2',
123 '-Wunused-macros',
124 '-Wvector-operation-performance',
125 '-Wvla',
126 '-Wwrite-strings',
127 ]
128
129 #####
130 # C #
131 #####
132
133 if is_variable('cc')
134 # Set all_c_warnings for the current C compiler
135 all_c_warnings = []
136
137 if cc.get_id() == 'clang'
138 all_c_warnings += ['-Weverything']
139
140 if not meson.is_cross_build()
141 all_c_warnings += [
142 '-Wno-poison-system-directories',
143 ]
144 endif
145
146 elif cc.get_id() == 'gcc'
147 all_c_warnings += gcc_common_warnings + [
148 '-Wabsolute-value',
149 '-Wbad-function-cast',
150 '-Wc++-compat',
151 '-Wenum-conversion',
152 '-Wjump-misses-init',
153 '-Wmissing-parameter-type',
154 '-Wmissing-prototypes',
155 '-Wnested-externs',
156 '-Wold-style-declaration',
157 '-Wold-style-definition',
158 '-Woverride-init',
159 '-Wsign-compare',
160 '-Wstrict-prototypes',
161 '-Wunsuffixed-float-constants',
162 ]
163
164 elif cc.get_id() == 'msvc'
165 all_c_warnings += [
166 '/Wall',
167 '/experimental:external',
168 '/external:W0',
169 '/external:anglebrackets',
170 ]
171 endif
172
173 all_c_warnings = cc.get_supported_arguments(all_c_warnings)
174 add_global_arguments(all_c_warnings, language: ['c'])
175 endif