meson: fix search path for setcap
[platform/upstream/gstreamer.git] / libs / gst / helpers / meson.build
1 executable('gst-plugin-scanner',
2   'gst-plugin-scanner.c',
3   c_args : gst_c_args,
4   include_directories : [configinc],
5   dependencies : [gobject_dep, gmodule_dep, glib_dep, mathlib, gst_dep],
6   link_with : [printf_lib],
7   install_dir : helpers_install_dir,
8   install: true,
9 )
10
11 # Used in test env setup to make tests find plugin scanner in build tree
12 gst_scanner_dir = meson.current_build_dir()
13
14 if bashcomp_found
15   executable('gst-completion-helper',
16     'gst-completion-helper.c',
17     c_args : gst_c_args,
18     include_directories : [configinc],
19     dependencies : [gobject_dep, glib_dep, gst_dep],
20     install_dir : helpers_install_dir,
21     install: true,
22   )
23 endif
24
25 # Check PTP support
26 have_ptp = false
27 if host_machine.system() == 'android'
28   message('PTP not supported on Android because of permissions.')
29 elif host_machine.system() == 'windows'
30   message('PTP not supported on Windows, not ported yet.')
31 elif host_machine.system() == 'ios' # FIXME: is it also darwing on iOS ?
32   message('PTP not supported on iOS because of permissions.')
33 elif host_machine.system() == 'darwin'
34   if cc.has_header('MobileCoreServices/MobileCoreServices.h')
35     message('PTP not supported on iOS because of permissions.')
36   else
37     have_ptp = true
38   endif
39 elif ['linux', 'netbsd', 'freebsd', 'openbsd', 'kfreebsd', 'dragonfly', 'solaris'].contains(host_machine.system())
40   message('PTP supported on ' + host_machine.system() + '.')
41   have_ptp = true
42 endif
43
44 if have_ptp
45   cdata.set('HAVE_PTP', 1, description : 'PTP support available')
46
47   if cc.compiles('''#include <sys/ioctl.h>
48                     #include <net/if.h>
49                     int some_func (void) {
50                       struct ifreq ifr;
51                       struct ifconf ifc;
52                       ioctl(0, SIOCGIFCONF, &ifc);
53                       ioctl(0, SIOCGIFFLAGS, &ifr);
54                       ioctl(0, SIOCGIFHWADDR, &ifr);
55                       return ifr.ifr_hwaddr.sa_data[0];
56                     }''',
57                  name : 'SIOCGIFCONF, SIOCGIFFLAGS and SIOCGIFHWADDR available')
58     cdata.set('HAVE_SIOCGIFCONF_SIOCGIFFLAGS_SIOCGIFHWADDR', 1,
59       description : 'SIOCGIFCONF, SIOCGIFFLAGS and SIOCGIFHWADDR is available')
60   endif
61
62   if cc.compiles('''#include <ifaddrs.h>
63                     #include <net/if.h>
64                     #include <net/if_dl.h>
65                     int some_func (void) {
66                       struct ifaddrs *ifaddr;
67                       getifaddrs(&ifaddr);
68                       return (ifaddr->ifa_flags & IFF_LOOPBACK) && ifaddr->ifa_addr->sa_family != AF_LINK;
69                     }''', name : 'getifaddrs() and AF_LINK available')
70     cdata.set('HAVE_GETIFADDRS_AF_LINK', 1,
71       description : 'getifaddrs() and AF_LINK is available')
72   endif
73
74   gst_ptp_have_cap = false
75   cap_dep = []
76   if cc.has_header('sys/capability.h')
77     cap_dep = cc.find_library('cap', required : false)
78     if cap_dep.found() and cc.has_function('cap_init', dependencies : cap_dep)
79       gst_ptp_have_cap = true
80     endif
81   endif
82
83   setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap', required : false)
84
85   # user/group to change to in gst-ptp-helper
86   ptp_helper_setuid_user = get_option('with-ptp-helper-setuid-user')
87   if ptp_helper_setuid_user != ''
88     cdata.set_quoted('HAVE_PTP_HELPER_SETUID_USER', ptp_helper_setuid_user,
89       description : 'PTP helper setuid user')
90   endif
91   ptp_helper_setuid_group = get_option('with-ptp-helper-setuid-group')
92   if ptp_helper_setuid_group != ''
93     cdata.set_quoted('HAVE_PTP_HELPER_SETUID_GROUP', ptp_helper_setuid_group,
94       description : 'PTP helper setuid group')
95   endif
96
97   # how to install gst-ptp-helper
98   with_ptp_helper_permissions = get_option('with-ptp-helper-permissions')
99   if with_ptp_helper_permissions == 'auto'
100     if gst_ptp_have_cap and setcap.found()
101       with_ptp_helper_permissions = 'capabilities'
102     else
103       with_ptp_helper_permissions = 'setuid-root'
104     endif
105   endif
106   message('How to install gst-ptp-helper: ' + with_ptp_helper_permissions)
107
108   if with_ptp_helper_permissions == 'none'
109     # nothing to do
110   elif with_ptp_helper_permissions == 'setuid-root'
111     cdata.set('HAVE_PTP_HELPER_SETUID', 1,
112         description : 'Use setuid-root for permissions in PTP helper')
113   elif with_ptp_helper_permissions == 'capabilities'
114     if not setcap.found()
115       error('capabilities-based ptp-helper-permissions requested, but could not find setcap tool.')
116     endif
117     cdata.set('HAVE_PTP_HELPER_CAPABILITIES', 1,
118         description : 'Use capabilities for permissions in PTP helper')
119   else
120     error('Unexpected ptp helper permissions value: ' + with_ptp_helper_permissions)
121   endif
122
123   executable('gst-ptp-helper', 'gst-ptp-helper.c',
124     c_args : gst_c_args,
125     include_directories : [configinc, libsinc],
126     dependencies : [gio_dep, gobject_dep, glib_dep, mathlib, gst_dep, cap_dep],
127     link_with : [printf_lib],
128     install_dir : helpers_install_dir,
129     install : true)
130
131   meson.add_install_script('ptp_helper_post_install.sh',
132       helpers_install_dir, with_ptp_helper_permissions,
133       setcap.found() ? setcap.path() : '')
134 endif