1project(
2	'waypipe',
3	'c',
4	license: 'MIT/Expat',
5	meson_version: '>=0.47.0',
6	default_options: [
7		'c_std=c11',
8		'warning_level=3',
9		'werror=true',
10	],
11	version: '0.8.2',
12)
13
14# DEFAULT_SOURCE implies POSIX_C_SOURCE 200809L + extras like CMSG_LEN
15# requires glibc >= 4.19 (2014), freebsd libc (since 2016?), musl >= 1.15 (2014)
16add_project_arguments('-D_DEFAULT_SOURCE', language: 'c')
17
18# Sometimes ignoring the result of read()/write() is the right thing to do
19add_project_arguments('-Wno-unused-result', language: 'c')
20
21cc = meson.get_compiler('c')
22config_data = configuration_data()
23
24# mention version
25version = '"v0.8.2"'.format(meson.project_version())
26git = find_program('git', native: true, required: false)
27if false
28	dir_arg = '--git-dir=@0@/.git'.format(meson.source_root())
29	commit = run_command([git, dir_arg, 'rev-parse', '--verify', '-q', 'HEAD'])
30	if commit.returncode() == 0
31		version = '"v0.8.2 (commit @1@)"'.format(meson.project_version(), commit.stdout().strip())
32	endif
33endif
34config_data.set('WAYPIPE_VERSION', version)
35
36# Make build reproducible if possible
37python3 = import('python').find_installation()
38prefix_finder = 'import os.path; print(os.path.join(os.path.relpath(\'@0@\', \'@1@\'),\'\'))'
39r = run_command(python3, '-c', prefix_finder.format(meson.source_root(), meson.build_root()))
40relative_dir = r.stdout().strip()
41if cc.has_argument('-fmacro-prefix-map=/prefix/to/hide=')
42	add_project_arguments(
43		'-fmacro-prefix-map=@0@='.format(relative_dir),
44		language: 'c',
45	)
46else
47	add_project_arguments(
48		'-DWAYPIPE_REL_SRC_DIR="@0@"'.format(relative_dir),
49		language: 'c',
50	)
51endif
52
53libgbm = dependency('gbm', required: get_option('with_dmabuf'))
54libdrm = dependency('libdrm', required: get_option('with_dmabuf'))
55if libgbm.found() and libdrm.found()
56	config_data.set('HAS_DMABUF', 1, description: 'Support DMABUF replication')
57	has_dmabuf = true
58else
59	has_dmabuf = false
60endif
61pthreads = dependency('threads')
62rt = cc.find_library('rt')
63# XXX dtrace -G (Solaris, FreeBSD, NetBSD) isn't supported yet
64is_linux = host_machine.system() == 'linux'
65is_darwin = host_machine.system() == 'darwin'
66if (is_linux or is_darwin) and get_option('with_systemtap') and cc.has_header('sys/sdt.h')
67	config_data.set('HAS_USDT', 1, description: 'Enable static trace probes')
68endif
69liblz4 = dependency('liblz4', version: '>=1.7.0', required: get_option('with_lz4'))
70if liblz4.found()
71	config_data.set('HAS_LZ4', 1, description: 'Enable LZ4 compression')
72endif
73libzstd = dependency('libzstd', version: '>=0.4.6', required: get_option('with_zstd'))
74if libzstd.found()
75	config_data.set('HAS_ZSTD', 1, description: 'Enable Zstd compression')
76endif
77libavcodec = dependency('libavcodec', required: get_option('with_video'))
78libavutil = dependency('libavutil', required: get_option('with_video'))
79libswscale = dependency('libswscale', required: get_option('with_video'))
80libva = dependency('libva', required: get_option('with_vaapi'))
81if libavcodec.found() and libavutil.found() and libswscale.found()
82	config_data.set('HAS_VIDEO', 1, description: 'Enable video (de)compression')
83	if libva.found()
84		config_data.set('HAS_VAAPI', 1, description: 'Enable hardware video (de)compression with VAAPI')
85	endif
86endif
87
88waypipe_includes = [include_directories('protocols'), include_directories('src')]
89if libdrm.found()
90	waypipe_includes += include_directories(libdrm.get_pkgconfig_variable('includedir'))
91endif
92
93subdir('protocols')
94subdir('src')
95subdir('test')
96
97scdoc = dependency('scdoc', version: '>=1.9.4', native: true, required: get_option('man-pages'))
98if scdoc.found()
99	scdoc_prog = find_program(scdoc.get_pkgconfig_variable('scdoc'), native: true)
100	sh = find_program('sh', native: true)
101	mandir = get_option('mandir')
102	custom_target(
103		'waypipe.1',
104		input: 'waypipe.scd',
105		output: 'waypipe.1',
106		command: [
107			sh, '-c', '@0@ < @INPUT@ > @1@'.format(scdoc_prog.path(), 'waypipe.1')
108		],
109		install: true,
110		install_dir: '@0@/man1'.format(mandir)
111	)
112endif
113