summaryrefslogtreecommitdiff
path: root/meson.build
blob: aac990918b778a2d8ed4fa2bed1849516560757a (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
112
113
114
115
116
117
project('usbredir', 'c',
    version: '0.13.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 = [
    '--param=ssp-buffer-size=4',
]
if host_machine.system() != 'windows'
    cc_flags += [ '-D_FORTIFY_SOURCE=2' ]
    if not get_option('stack_protector').disabled()
        cc_flags += [ '-fstack-protector' ]
    endif
endif

# 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')

config = configuration_data()

if get_option('extra-checks')
  config.set('ENABLE_EXTRA_CHECKS', '1')
endif

config.set('USBREDIR_VISIBLE', '')
foreach visibility : [
    '__attribute__((visibility ("default")))',
    '__attribute__((dllexport))',
    '__declspec(dllexport)',
]
    code = '@0@ int func() { return 123; }'.format(visibility)
    if compiler.compiles(code, name : 'visibility check')
	config.set('USBREDIR_VISIBLE', visibility)
	break
    endif
endforeach

#
# 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('usbredirtestclient')

    if get_option('fuzzing').enabled()
        subdir('fuzzing')
    endif
endif
if get_option('tests').enabled()
    subdir('tests')
endif
subdir('data')

summary(summary_info, bool_yn: true)