@@ -8,8 +8,9 @@ project('casync', 'c',
88 ' prefix=/usr' ,
99 ' sysconfdir=/etc' ,
1010 ' localstatedir=/var' ,
11+ ' auto_features=enabled' ,
1112 ],
12- meson_version : ' >= 0.40 ' )
13+ meson_version : ' >= 0.47 ' )
1314
1415cc = meson .get_compiler(' c' )
1516
@@ -62,6 +63,15 @@ foreach arg : c_args
6263 endif
6364endforeach
6465
66+ want_ossfuzz = get_option (' oss-fuzz' )
67+ want_libfuzzer = get_option (' llvm-fuzz' )
68+ if want_ossfuzz and want_libfuzzer
69+ error (' only one of oss-fuzz and llvm-fuzz can be specified' )
70+ endif
71+ fuzzer_build = want_ossfuzz or want_libfuzzer
72+
73+ add_languages (' cpp' , required : fuzzer_build)
74+
6575conf = configuration_data ()
6676conf.set_quoted(' PACKAGE_VERSION' , meson .project_version())
6777
@@ -101,18 +111,27 @@ docdir = join_paths(datadir, 'doc/casync')
101111protocoldir = join_paths (prefixdir, ' lib/casync/protocols' )
102112conf.set_quoted(' CASYNC_PROTOCOL_PATH' , protocoldir)
103113
104- liblzma = dependency (' liblzma' ,
105- version : ' >= 5.1.0' )
114+ liblzma = dependency (
115+ ' liblzma' ,
116+ version : ' >= 5.1.0' ,
117+ required : get_option (' liblzma' ))
118+ conf.set10(' HAVE_LIBLZMA' , liblzma.found())
119+
120+ libz = dependency (
121+ ' zlib' ,
122+ required : get_option (' libz' ))
123+ conf.set10(' HAVE_LIBZ' , libz.found())
124+
125+ libzstd = dependency (
126+ ' libzstd' ,
127+ version : ' >= 0.8.1' ,
128+ required : get_option (' libzstd' ))
129+ conf.set10(' HAVE_LIBZSTD' , libzstd.found())
130+
106131libcurl = dependency (' libcurl' ,
107132 version : ' >= 7.29.0' )
108133openssl = dependency (' openssl' ,
109134 version : ' >= 1.0' )
110-
111- libz = dependency (' zlib' )
112-
113- libzstd = dependency (' libzstd' ,
114- version : ' >= 0.8.1' )
115-
116135libacl = cc.find_library (' acl' )
117136
118137if get_option (' fuse' )
@@ -140,6 +159,12 @@ conf.set10('HAVE_UDEV', get_option('udev'))
140159threads = dependency (' threads' )
141160math = cc.find_library (' m' )
142161
162+ if want_libfuzzer
163+ fuzzing_engine = meson .get_compiler(' cpp' ).find_library (' Fuzzer' )
164+ elif want_ossfuzz
165+ fuzzing_engine = meson .get_compiler(' cpp' ).find_library (' FuzzingEngine' )
166+ endif
167+
143168config_h = configure_file (
144169 output : ' config.h' ,
145170 configuration : conf)
@@ -227,6 +252,9 @@ substs = configuration_data()
227252substs.set_quoted(' top_builddir' , meson .build_root())
228253substs.set_quoted(' top_srcdir' , meson .source_root())
229254substs.set(' bindir_unquoted' , bindir)
255+ substs.set10(' HAVE_LIBLZMA' , liblzma.found())
256+ substs.set10(' HAVE_LIBZ' , libz.found())
257+ substs.set10(' HAVE_LIBZSTD' , libzstd.found())
230258
231259test_script_sh = configure_file (
232260 output : ' test-script.sh' ,
@@ -315,28 +343,57 @@ non_test_sources = '''
315343 test-calc-digest
316344''' .split()
317345
346+ test_dependencies = [
347+ libacl,
348+ liblzma,
349+ libselinux,
350+ libz,
351+ libzstd,
352+ math,
353+ openssl,
354+ threads]
355+
318356foreach test_name : test_sources + non_test_sources
319357 exe = executable (
320358 test_name,
321359 ' test/@[email protected] ' .format(test_name),
322- link_with : libshared,
323360 include_directories : includes,
324- dependencies : [
325- libacl,
326- liblzma,
327- libselinux,
328- libz,
329- libzstd,
330- math,
331- openssl,
332- threads])
361+ link_with : libshared,
362+ dependencies : test_dependencies)
333363
334364 if test_sources.contains(test_name)
335365 test (test_name, exe,
336366 timeout : 3 * 60 )
337367 endif
338368endforeach
339369
370+ fuzzer_exes = []
371+
372+ foreach tuple : fuzzers
373+ sources = tuple[0 ]
374+
375+ deps = test_dependencies
376+ if fuzzer_build
377+ deps += fuzzing_engine
378+ else
379+ sources += fuzz_main_c
380+ endif
381+
382+ name = sources[0 ].split(' /' )[- 1 ].split(' .' )[0 ]
383+
384+ fuzzer_exes += executable (
385+ name,
386+ sources,
387+ include_directories : [includes, include_directories (' test/fuzz' )],
388+ link_with : libshared,
389+ dependencies : deps,
390+ install : false )
391+ endforeach
392+
393+ run_target (' fuzzers' ,
394+ depends : fuzzer_exes,
395+ command : [' true' ])
396+
340397############################################################
341398
342399meson_check_help = find_program (' test/meson-check-help.sh' )
0 commit comments