File: meson.build

package info (click to toggle)
waypipe 0.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,288 kB
  • sloc: ansic: 15,809; xml: 9,436; python: 1,726; sh: 248; makefile: 28
file content (227 lines) | stat: -rw-r--r-- 6,551 bytes parent folder | download
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
project(
    'waypipe',
    'c',
    license: ['GPL3+', 'MIT/Expat'],
    meson_version: '>=0.56.0',
    default_options: ['c_std=c11', 'warning_level=3', 'werror=true'],
    version: '0.11.0',
)

# mention version
raw_version = '@0@'.format(meson.project_version())
git = find_program('git', native: true, required: false)
if git.found()
    dir_arg = '--git-dir=@0@/.git'.format(meson.project_source_root())
    commit = run_command(
        [git, dir_arg, 'rev-parse', '--verify', '-q', 'HEAD'],
        check: false,
    )
    if commit.returncode() == 0
        raw_version = '@0@ (commit @1@)'.format(
            meson.project_version(),
            commit.stdout().strip(),
        )
    endif
endif
version = '"@0@"'.format(raw_version)

if get_option('build_rs')
    cargo = find_program('cargo', native: true)
    sh = find_program('sh', native: true)
    objcopy = find_program('objcopy', native: true)

    # Because meson and cargo interact badly, option implementation and dependency resolution are deferred to cargo
    # However, to 'autodetect' what features are available, we duplicate some of the build logic
    features = []
    has_lz4 = false
    has_zstd = false
    has_gbm = false
    has_dmabuf = false
    has_video = false

    # compute maximum of with_lz4/with_zstd/with_gbm/with_video features
    max_feature = get_option('with_lz4')
    if (max_feature.auto() and get_option('with_zstd').enabled()) or (not max_feature.enabled() and get_option(
            'with_zstd',
        ).auto())
        max_feature = get_option('with_zstd')
    endif
    if (max_feature.auto() and get_option('with_gbm').enabled()) or (not max_feature.enabled() and get_option(
            'with_gbm',
        ).auto())
        max_feature = get_option('with_gbm')
    endif
    if (max_feature.auto() and get_option('with_video').enabled()) or (not max_feature.enabled() and get_option(
            'with_video',
        ).auto())
        max_feature = get_option('with_video')
    endif

    bindgen = find_program(
        'bindgen',
        version: '>= 0.66.0',
        native: true,
        required: max_feature,
    )
    liblz4 = dependency(
        'liblz4',
        version: '>=1.7.0',
        required: get_option('with_lz4'),
    )
    if bindgen.found() and liblz4.found()
        has_lz4 = true
        features += ['lz4']
    endif
    libzstd = dependency(
        'libzstd',
        version: '>=0.4.6',
        required: get_option('with_zstd'),
    )
    if bindgen.found() and libzstd.found()
        has_zstd = true
        features += ['zstd']
    endif
    libvulkan = dependency('vulkan', required: get_option('with_dmabuf'))
    if libvulkan.found()
        # Note: 'ash' is the vulkan wrapper used, and may require other libraries/programs to be present
        has_dmabuf = true
        features += ['dmabuf']
    endif
    libgbm = dependency(
        'gbm',
        version: '>=11.0.0',  # gbm is part of Mesa and has a matching version
        required: get_option('with_gbm'),
    )
    if bindgen.found() and libzstd.found()
        has_zstd = true
        features += ['gbmfallback']
    endif
    glslc = find_program(
        'glslc',
        native: true,
        required: get_option('with_video'),
    )
    libavutil = dependency(
        'libavutil',
        version: '>=58.11.100',
        required: get_option('with_video'),
    )
    libavcodec = dependency(
        'libavcodec',
        version: '>=59.0.100',
        required: get_option('with_video'),
    )
    if bindgen.found() and libavcodec.found() and libavutil.found() and glslc.found()
        has_video = true
        features += ['video']
    endif

    target_dir = meson.project_build_root() / 'target'
    output = target_dir / 'release/waypipe'
    manifest = meson.project_source_root() / 'Cargo.toml'

    # Cargo has no direct analogue for 'g' or 'plain' optimization levels,
    # so the choices for them are somewhat arbitrary
    if get_option('optimization') == '0' or get_option('optimization') == 'g'
        profile = 'meson-0'
    elif get_option('optimization') == '1' or get_option('optimization') == 'plain'
        profile = 'meson-1'
    elif get_option('optimization') == '3'
        profile = 'meson-3'
    elif get_option('optimization') == 's'
        profile = 'meson-s'
    else
        profile = 'meson-2'
    endif

    if get_option('debug') == false
        profile += '-strip'
    endif
    message('Cargo will be run with profile: @0@'.format(profile))

    binary = custom_target(
        'waypipe',
        build_always_stale: true,
        output: 'waypipe',
        command: [
            sh,
            '@SOURCE_ROOT@' / 'compile_wrapper.sh',
            profile,
            manifest,
            target_dir,
            ','.join(features),
            '@OUTPUT@',
            raw_version,
            has_lz4.to_string('true', 'false'),
            has_zstd.to_string('true', 'false'),
            has_dmabuf.to_string('true', 'false'),
            has_video.to_string('true', 'false'),
        ],
        install: true,
        install_dir: get_option('bindir'),
    )

    test(
        'running cargo test',
        cargo,
        args: [
            'test',
            '--frozen',
            '--bin',
            'waypipe',
            '--test',
            'proto',
            '-v',
            '--manifest-path',
            manifest,
            '--no-default-features',
            '--target-dir',
            target_dir,
            '--features',
            ','.join(features + ['test_proto']),
        ],
        timeout: 200,
        priority: 100,
    )

    test(
        'running (shortened) waypipe bench',
        sh,
        args: [
            '-c',
            ' '.join([binary.full_path(), '--test-fast-bench', 'bench']),
        ],
        depends: binary,
    )
endif

if get_option('build_c')
    subdir('waypipe-c')
endif

scdoc = dependency(
    'scdoc',
    version: '>=1.9.4',
    native: true,
    required: get_option('man-pages'),
)
if scdoc.found()
    scdoc_prog = find_program(
        scdoc.get_variable(pkgconfig: 'scdoc'),
        native: true,
    )
    sh = find_program('sh', native: true)
    mandir = get_option('mandir')
    custom_target(
        'waypipe.1',
        input: 'waypipe.scd',
        output: 'waypipe.1',
        command: [
            sh,
            '-c',
            '@0@ < @INPUT@ > @1@'.format(scdoc_prog.full_path(), 'waypipe.1'),
        ],
        install: true,
        install_dir: '@0@/man1'.format(mandir),
    )
endif