Skip to content

Commit 9438d81

Browse files
committed
build(meson): add additional warning flags for libgrovedb
1 parent 18c9e64 commit 9438d81

File tree

3 files changed

+63
-19
lines changed

3 files changed

+63
-19
lines changed

src/ffi/grovedb/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ meson compile -C builddir
5151
- `-Dbuild_tests=[true|false]`: Build unit tests (default: `true`)
5252
- `-Dgrovedb_cxx_build_dir=<path>`: Path to `grovedb_cxx` build directory (auto-detected if empty, ignored if `use_rustdeps=true`)
5353
- `-Drustdeps_build_dir=<path>`: Path to `librustdeps` build directory (auto-detected if empty)
54+
- `-Dsuppress_external_warnings=[true|false]`: Suppress compiler warnings on external sources (default: `true`)
5455
- `-Duse_rustdeps=[true|false]`: Link against `librustdeps` instead of `libgrovedb_cxx` (default: `false`)
5556

5657
## License

src/ffi/grovedb/meson.build

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,46 @@ rustdeps_build_dir = get_option('rustdeps_build_dir')
2626

2727
# C++ compiler
2828
cxx = meson.get_compiler('cpp')
29+
cxx_core_flags_list = [
30+
'-fno-extended-identifiers',
31+
'-fstack-reuse=none', # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348
32+
]
33+
cxx_warn_flags_list = [
34+
'-Wconditional-uninitialized',
35+
'-Wdate-time',
36+
'-Wdocumentation',
37+
'-Wduplicated-branches',
38+
'-Wduplicated-cond',
39+
'-Wgnu',
40+
'-Wimplicit-fallthrough',
41+
'-Wlogical-op',
42+
'-Wloop-analysis',
43+
'-Woverloaded-virtual',
44+
'-Wredundant-decls',
45+
'-Wreorder',
46+
'-Wself-assign',
47+
'-Wshadow-field',
48+
'-Wsuggest-override',
49+
'-Wthread-safety',
50+
'-Wunreachable-code',
51+
'-Wunused-member-function',
52+
'-Wvla',
53+
]
54+
55+
# Check compiler support for flags and apply them
56+
cxx_flags = []
57+
foreach flag : cxx_core_flags_list + cxx_warn_flags_list
58+
if cxx.has_multi_arguments(['-Werror', flag])
59+
cxx_flags += flag
60+
endif
61+
endforeach
62+
63+
# -Wformat and -Wformat-security must defined together
64+
if cxx.has_multi_arguments(['-Werror', '-Wformat', '-Wformat-security'])
65+
cxx_flags += ['-Wformat', '-Wformat-security']
66+
endif
67+
68+
add_project_arguments(cxx_flags, language: 'cpp')
2969

3070
# Check for threading support
3171
thread_dep = dependency('threads', required: true)
@@ -193,32 +233,28 @@ pkg.generate(
193233
subdirs: 'grovedb',
194234
)
195235

196-
# Tests
236+
# Unit tests
237+
suppress_external_warns = get_option('suppress_external_warnings')
238+
test_sources = files(
239+
'src/test/main.cpp',
240+
'src/test/misc_tests.cpp',
241+
)
197242
if build_tests
198243
boost_dep = dependency('boost',
199244
modules: ['unit_test_framework'],
200245
version: '>=1.73.0',
201-
required: false,
246+
required: true,
247+
include_type: suppress_external_warns ? 'system' : 'preserve',
202248
)
203249

204-
if boost_dep.found()
205-
test_sources = files(
206-
'src/test/main.cpp',
207-
'src/test/misc_tests.cpp',
208-
)
209-
210-
# Build test executable
211-
test_exe = executable('test_grovedb',
212-
test_sources,
213-
include_directories: libgrovedb_inc,
214-
dependencies: [libgrovedb_dep, boost_dep],
215-
build_by_default: true,
216-
)
250+
test_bin = executable('test_grovedb',
251+
test_sources,
252+
include_directories: libgrovedb_inc,
253+
dependencies: [libgrovedb_dep, boost_dep],
254+
build_by_default: true,
255+
)
217256

218-
test('grovedb_tests', test_exe)
219-
else
220-
warning('Boost not found. Tests will not be built.')
221-
endif
257+
test('grovedb_tests', test_bin)
222258
endif
223259

224260
# Summary
@@ -231,6 +267,7 @@ summary({
231267

232268
summary({
233269
'C++ compiler': cxx.get_id(),
270+
'C++ flags': ' '.join(cxx_flags),
234271
'C++ standard': get_option('cpp_std'),
235272
}, section: 'Compiler')
236273

src/ffi/grovedb/meson_options.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ option('rustdeps_build_dir',
1616
description: 'Path to rustdeps build directory (auto-detected if empty)'
1717
)
1818

19+
option('suppress_external_warnings',
20+
type: 'boolean',
21+
value: true,
22+
description: 'Suppress warnings from external headers'
23+
)
24+
1925
option('use_rustdeps',
2026
type: 'boolean',
2127
value: false,

0 commit comments

Comments
 (0)