@@ -26,6 +26,46 @@ rustdeps_build_dir = get_option('rustdeps_build_dir')
2626
2727# C++ compiler
2828cxx = 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
3171thread_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+ )
197242if 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)
222258endif
223259
224260# Summary
@@ -231,6 +267,7 @@ summary({
231267
232268summary ({
233269 ' C++ compiler' : cxx.get_id(),
270+ ' C++ flags' : ' ' .join(cxx_flags),
234271 ' C++ standard' : get_option (' cpp_std' ),
235272}, section : ' Compiler' )
236273
0 commit comments