summaryrefslogtreecommitdiff
path: root/meson.build
blob: 55e4deaa4167b290e61c2e2b97abdeb42c0369ff (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
project('usbredir', 'c', 'cpp',
    version: '0.8.0',
    license: 'LGPLv2.1+',
    meson_version : '>= 0.53',
    default_options : [
        'buildtype=debugoptimized',
        'warning_level=1',
    ])

summary_info = {'prefix': get_option('prefix')}

usbredir_include_root_dir = include_directories('.')

cc_flags = [
    '-Wp,-D_FORTIFY_SOURCE=2',
    '--param=ssp-buffer-size=4',
]

# Check if we are building from .git
git = run_command('test', '-d', '.git').returncode() == 0
git_werror = get_option('git_werror')
if git_werror.enabled() or git_werror.auto() and git
  cc_flags += [ '-Werror' ]
endif

compiler = meson.get_compiler('c')
supported_cc_flags = compiler.get_supported_arguments(cc_flags)
add_project_arguments(supported_cc_flags, language: 'c')

if host_machine.system() != 'windows'
    add_project_arguments('-fstack-protector', language: 'c')
endif

want_libfuzzer = get_option('llvm-fuzz').enabled()
if want_libfuzzer
    add_languages('cpp', required : true)
    fuzzing_engine = meson.get_compiler('cpp').find_library('Fuzzer', required : false)
    if fuzzing_engine.found()
        add_project_arguments('-fsanitize-coverage=trace-pc-guard,trace-cmp', language : 'c')
    elif compiler.has_argument('-fsanitize=fuzzer-no-link')
        add_project_arguments('-fsanitize=fuzzer-no-link', language : 'c')
    else
        error('Looks like neither libFuzzer nor -fsanitize=fuzzer-no-link is supported')
    endif
    # This is preferable to static linking
    add_project_link_arguments('-shared-libsan', language: ['c', 'cpp'])
endif

config = configuration_data()

#
# write config.h
#
proj_name = meson.project_name()
proj_version = meson.project_version()
config_data = {
    'VERSION' : proj_version,
    'PACKAGE_VERSION' : proj_version,
    'PACKAGE_STRING' : '@0@ @1@'.format(proj_name, proj_version),
    'PACKAGE_BUGREPORT' : 'https://gitlab.freedesktop.org/spice/usbredir/issues',
}

foreach key, value : config_data
    config.set_quoted(key, value)
endforeach

#
# check for system headers
#
headers = [
    'inttypes.h',
    'stdint.h',
    'stdlib.h',
    'strings.h',
    'string.h',
    'sys/stat.h',
    'sys/types.h',
    'unistd.h',
]

foreach header : headers
    if compiler.has_header(header)
        config.set('HAVE_@0@'.format(header.underscorify().to_upper()), '1')
    endif
endforeach

if host_machine.system() == 'windows'
    wixl_arch = 'x64'
    if host_machine.cpu() != 'x86_64'
        wixl_arch = 'x86'
    endif
    config.set('WIXL_ARCH', wixl_arch)
endif

configure_file(output : 'config.h', configuration : config)

subdir('usbredirparser')
subdir('usbredirhost')
if get_option('tools').enabled()
    subdir('tools')
endif
if host_machine.system() != 'windows'
    subdir('usbredirserver')
    subdir('usbredirtestclient')
    if want_libfuzzer
        subdir('fuzzing')
    endif
endif
subdir('data')

summary(summary_info, bool_yn: true)