Debian Codegraph @

libs/gst/helpers/ptp/meson.build

raw
1 # Check PTP support
2 ptp_helper_option = get_option('ptp-helper')
3
4 if ptp_helper_option.disabled()
5 subdir_done()
6 endif
7
8 ptp_supported = false
9 if host_system in ['linux', 'darwin', 'freebsd', 'openbsd', 'netbsd', 'dragonfly', 'sunos', 'solaris', 'illumos', 'windows', 'gnu']
10 ptp_supported = true
11 if host_system == 'darwin' and subsystem != 'macos'
12 ptp_supported = false
13 endif
14 endif
15
16 if not ptp_supported
17 if ptp_helper_option.enabled()
18 error(f'PTP not supported on @host_system@ (@subsystem@)')
19 endif
20 subdir_done()
21 endif
22
23 have_rust = add_languages('rust', native : false, required : false)
24 if not have_rust
25 if ptp_helper_option.enabled()
26 error('PTP not supported without Rust compiler')
27 endif
28 subdir_done()
29 endif
30
31 rustc = meson.get_compiler('rust')
32
33 if rustc.get_id() not in ['rustc', 'clippy-driver rustc']
34 warning('PTP support is only tested with rustc, found different compiler @0@ @1@'.format(rustc.get_id(), rustc.version()))
35 endif
36
37 # We currently need at least Rust 1.48 on all platforms but Windows.
38 # On Windows some 1.54 API is used that would otherwise complicate things
39 # unncecessarily.
40 rust_req = '1.48'
41 if host_system == 'windows'
42 rust_req = '1.54'
43 endif
44
45 if rustc.get_id() in ['rustc', 'clippy-driver rustc'] and not rustc.version().version_compare('>=' + rust_req)
46 if ptp_helper_option.enabled()
47 error('PTP support requires at least Rust @0@ on this platform, found @1@'.format(rust_req, rustc.version()))
48 endif
49 subdir_done()
50 endif
51
52 cdata.set('HAVE_PTP', 1, description : 'PTP support available')
53
54 ptp_helper_conf_data = configuration_data()
55 rust_args = []
56
57 setcap_prog = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap', required : false)
58 cap_dep = dependency('libcap', required: false)
59
60 # user/group to change to in gst-ptp-helper
61 ptp_helper_setuid_user = get_option('ptp-helper-setuid-user')
62 if ptp_helper_setuid_user != ''
63 ptp_helper_conf_data.set('PTP_HELPER_SETUID_USER', 'Some("@0@")'.format(ptp_helper_setuid_user))
64 else
65 ptp_helper_conf_data.set('PTP_HELPER_SETUID_USER', 'None')
66 endif
67 ptp_helper_setuid_group = get_option('ptp-helper-setuid-group')
68 if ptp_helper_setuid_group != ''
69 ptp_helper_conf_data.set('PTP_HELPER_SETUID_GROUP', 'Some("@0@")'.format(ptp_helper_setuid_group))
70 else
71 ptp_helper_conf_data.set('PTP_HELPER_SETUID_GROUP', 'None')
72 endif
73
74 # how to install gst-ptp-helper
75 with_ptp_helper_permissions = get_option('ptp-helper-permissions')
76 if with_ptp_helper_permissions == 'auto'
77 if setcap_prog.found() and cap_dep.found()
78 with_ptp_helper_permissions = 'capabilities'
79 elif host_system == 'windows'
80 with_ptp_helper_permissions = 'none'
81 else
82 with_ptp_helper_permissions = 'setuid-root'
83 endif
84 endif
85 message('How to install gst-ptp-helper: ' + with_ptp_helper_permissions)
86
87 if with_ptp_helper_permissions == 'none'
88 rust_args += ['--cfg', 'ptp_helper_permissions="none"']
89 # nothing to do
90 elif with_ptp_helper_permissions == 'setuid-root'
91 rust_args += ['--cfg', 'ptp_helper_permissions="setuid-root"']
92 elif with_ptp_helper_permissions == 'capabilities'
93 if not setcap_prog.found()
94 error('capabilities-based ptp-helper-permissions requested, but could not find setcap tool.')
95 elif not cap_dep.found()
96 error('capabilities-based ptp-helper-permissions requested, but could not find libcap.')
97 endif
98 rust_args += ['--cfg', 'ptp_helper_permissions="setcap"']
99 else
100 error('Unexpected ptp helper permissions value: ' + with_ptp_helper_permissions)
101 endif
102
103 conf_lib_rs = configure_file(input : 'conf_lib.rs.in',
104 output : 'conf_lib.rs',
105 configuration: ptp_helper_conf_data)
106
107 conf = static_library('gst_ptp_helper_conf', conf_lib_rs,
108 override_options : ['rust_std=2018'],
109 rust_abi : 'rust')
110
111 exe = executable('gst-ptp-helper', 'main.rs',
112 override_options : ['rust_std=2018'],
113 rust_args : ['-Cpanic=abort', rust_args],
114 dependencies : [cap_dep],
115 link_with : conf,
116 install_dir : helpers_install_dir,
117 install : true)
118
119 # sanity checking
120 if get_option('tests').enabled()
121 exe_test = executable('gst_ptp_helper_test', 'main.rs',
122 override_options : ['rust_std=2018'],
123 rust_args : ['--test', rust_args],
124 dependencies : [cap_dep],
125 link_with : conf)
126
127 test('gst-ptp-helper-test', exe_test, protocol : 'rust')
128 endif
129
130 if host_system != 'windows'
131 meson.add_install_script('ptp_helper_post_install.sh',
132 helpers_install_dir, with_ptp_helper_permissions,
133 setcap_prog.found() ? setcap_prog.full_path() : '')
134 endif
135
136 meson.add_devenv({'GST_PTP_HELPER': exe.full_path()})