summaryrefslogtreecommitdiff
path: root/fuzzing/meson.build
blob: 0cfd5d7681978b320a1af2037b971f0c21cec9c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
add_languages('cpp', required: true)

cpp_compiler = meson.get_compiler('cpp')
cpp_compiler.has_header('fuzzer/FuzzedDataProvider.h', required: true)

link_args = []
link_with = []

fuzz_engine = get_option('fuzzing-engine')
fuzz_install_dir = get_option('fuzzing-install-dir')

if fuzz_engine == 'standalone'
    standalone_lib = static_library('standalone',
        sources: ['standalone.c'],
        install: false,
        )

    link_with += [standalone_lib]
else
    link_args += fuzz_engine.split()

    if not cpp_compiler.links('''
        #include <cstddef>
        #include <cstdint>
        extern "C" int LLVMFuzzerTestOneInput(const uint8_t *, size_t) {
          return 0;
        }
        ''',
        args: link_args,
        )
        error('Linking fuzzing test failed')
    endif
endif

fuzz_targets = {
    'usbredirparserfuzz': [usbredir_parser_lib_dep],
    'usbredirfilterfuzz': [usbredir_parser_lib_dep],
    }

foreach target_name, deps : fuzz_targets
    executable(target_name,
        sources: [target_name + '.cc'],
        dependencies: deps,
        link_language: 'cpp',
        link_args: link_args,
        link_with: link_with,
        install: (fuzz_install_dir != ''),
        install_dir: fuzz_install_dir,
        )

    if fuzz_install_dir != ''
        install_data('default.options',
            install_dir: fuzz_install_dir,
            rename: target_name + '.options',
            )
    endif
endforeach