treewide: only define feature macros when the feature is available

Most feature checks already use #ifdef, and do not care about
the value of the macro. Convert all feature checks to do that,
and simplify the meson build scripts by replacing

  if cond
    cdata.set('X', 1)
  endif

with

  cdata.set('X', cond)
This commit is contained in:
Barnabás Pőcze 2022-02-03 18:52:54 +01:00
parent 140378efd6
commit 15e7a61aa7
15 changed files with 49 additions and 83 deletions

View file

@ -218,38 +218,29 @@ check_headers = [
] ]
foreach h : check_headers foreach h : check_headers
if cc.has_header(h.get(0)) cdata.set(h.get(1), cc.has_header(h.get(0)))
cdata.set(h.get(1), 1)
endif
endforeach endforeach
if cc.has_function('gettid', prefix : '#include<unistd.h>', args: [ '-D_GNU_SOURCE' ]) check_functions = [
cdata.set('HAVE_GETTID', 1) ['gettid', '#include <unistd.h>', ['-D_GNU_SOURCE']],
endif ['memfd_create', '#include <sys/mman.h>', ['-D_GNU_SOURCE']],
['getrandom', '#include <stddef.h>\n#include <sys/random.h>', ['-D_GNU_SOURCE']],
['sigabbrev_np', '#include <string.h>', ['-D_GNU_SOURCE']],
]
if cc.has_function('memfd_create', prefix : '#include <sys/mman.h>', args : [ '-D_GNU_SOURCE' ]) foreach f : check_functions
cdata.set('HAVE_MEMFD_CREATE', 1) cdata.set('HAVE_' + f.get(0).to_upper(),
endif cc.has_function(f.get(0), prefix: f.get(1), args: f.get(2)))
endforeach
if cc.has_function('getrandom', prefix : '#include <stddef.h>\n#include <sys/random.h>', args : [ '-D_GNU_SOURCE' ]) cdata.set('HAVE_PIDFD_OPEN',
cdata.set('HAVE_GETRANDOM', 1) cc.get_define('SYS_pidfd_open', prefix: '#include <sys/syscall.h>') != '')
endif
if cc.has_function('sigabbrev_np', prefix : '#include <string.h>', args : [ '-D_GNU_SOURCE' ])
cdata.set('HAVE_SIGABBREV_NP', 1)
endif
if cc.get_define('SYS_pidfd_open', prefix : '#include <sys/syscall.h>') != ''
cdata.set('HAVE_PIDFD_OPEN', 1)
endif
systemd = dependency('systemd', required: get_option('systemd')) systemd = dependency('systemd', required: get_option('systemd'))
systemd_dep = dependency('libsystemd',required: get_option('systemd')) systemd_dep = dependency('libsystemd',required: get_option('systemd'))
summary({'systemd conf data': systemd.found()}, bool_yn: true) summary({'systemd conf data': systemd.found()}, bool_yn: true)
summary({'libsystemd': systemd_dep.found()}, bool_yn: true) summary({'libsystemd': systemd_dep.found()}, bool_yn: true)
if systemd.found() and systemd_dep.found() cdata.set('HAVE_SYSTEMD', systemd.found() and systemd_dep.found())
cdata.set('HAVE_SYSTEMD', 1)
endif
configinc = include_directories('.') configinc = include_directories('.')
includes_inc = include_directories('include') includes_inc = include_directories('include')
@ -276,9 +267,7 @@ dl_lib = cc.find_library('dl', required : false)
pthread_lib = dependency('threads') pthread_lib = dependency('threads')
dbus_dep = dependency('dbus-1', required : get_option('dbus')) dbus_dep = dependency('dbus-1', required : get_option('dbus'))
summary({'dbus (Bluetooth, rt, portal, pw-reserve)': dbus_dep.found()}, bool_yn: true, section: 'Misc dependencies') summary({'dbus (Bluetooth, rt, portal, pw-reserve)': dbus_dep.found()}, bool_yn: true, section: 'Misc dependencies')
if dbus_dep.found() cdata.set('HAVE_DBUS', dbus_dep.found())
cdata.set('HAVE_DBUS', 1)
endif
sdl_dep = dependency('sdl2', required : get_option('sdl2')) sdl_dep = dependency('sdl2', required : get_option('sdl2'))
summary({'SDL2 (video examples)': sdl_dep.found()}, bool_yn: true, section: 'Misc dependencies') summary({'SDL2 (video examples)': sdl_dep.found()}, bool_yn: true, section: 'Misc dependencies')
drm_dep = dependency('libdrm', required : false) drm_dep = dependency('libdrm', required : false)
@ -292,9 +281,7 @@ summary({'readline (for pw-cli)': readline_dep.found()}, bool_yn: true, section:
ncurses_dep = dependency('ncursesw', required : false) ncurses_dep = dependency('ncursesw', required : false)
sndfile_dep = dependency('sndfile', version : '>= 1.0.20', required : get_option('sndfile')) sndfile_dep = dependency('sndfile', version : '>= 1.0.20', required : get_option('sndfile'))
summary({'sndfile': sndfile_dep.found()}, bool_yn: true, section: 'pw-cat/pw-play/pw-dump/filter-chain') summary({'sndfile': sndfile_dep.found()}, bool_yn: true, section: 'pw-cat/pw-play/pw-dump/filter-chain')
if sndfile_dep.found() cdata.set('HAVE_SNDFILE', sndfile_dep.found())
cdata.set('HAVE_SNDFILE', 1)
endif
pulseaudio_dep = dependency('libpulse', required : get_option('libpulse')) pulseaudio_dep = dependency('libpulse', required : get_option('libpulse'))
summary({'libpulse': pulseaudio_dep.found()}, bool_yn: true, section: 'Streaming between daemons') summary({'libpulse': pulseaudio_dep.found()}, bool_yn: true, section: 'Streaming between daemons')
avahi_dep = dependency('avahi-client', required : get_option('avahi')) avahi_dep = dependency('avahi-client', required : get_option('avahi'))
@ -311,14 +298,10 @@ summary({'libcanberra (x11-bell)': canberra_dep.found()}, bool_yn: true,
libusb_dep = dependency('libusb-1.0', required : get_option('libusb')) libusb_dep = dependency('libusb-1.0', required : get_option('libusb'))
summary({'libusb (Bluetooth quirks)': libusb_dep.found()}, bool_yn: true, section: 'Backend') summary({'libusb (Bluetooth quirks)': libusb_dep.found()}, bool_yn: true, section: 'Backend')
if libusb_dep.found() cdata.set('HAVE_LIBUSB', libusb_dep.found())
cdata.set('HAVE_LIBUSB', 1)
endif
cap_lib = dependency('libcap', required : false) cap_lib = dependency('libcap', required : false)
if cap_lib.found() cdata.set('HAVE_LIBCAP', cap_lib.found())
cdata.set('HAVE_LIBCAP', 1)
endif
gst_option = get_option('gstreamer') gst_option = get_option('gstreamer')
gst_deps_def = { gst_deps_def = {
@ -353,18 +336,13 @@ endforeach
gst_dp_found = gst_dep.length() > 0 gst_dp_found = gst_dep.length() > 0
summary({'gstreamer-device-provider': gst_dp_found}, bool_yn: true, section: 'Backend') summary({'gstreamer-device-provider': gst_dp_found}, bool_yn: true, section: 'Backend')
if not get_option('gstreamer-device-provider').disabled() cdata.set('HAVE_GSTREAMER_DEVICE_PROVIDER', not get_option('gstreamer-device-provider').disabled())
cdata.set('HAVE_GSTREAMER_DEVICE_PROVIDER', 1)
endif
webrtc_dep = dependency('webrtc-audio-processing', webrtc_dep = dependency('webrtc-audio-processing',
version : ['>= 0.2', '< 1.0'], version : ['>= 0.2', '< 1.0'],
required : get_option('echo-cancel-webrtc')) required : get_option('echo-cancel-webrtc'))
summary({'WebRTC Echo Canceling': webrtc_dep.found()}, bool_yn: true, section: 'Misc dependencies') summary({'WebRTC Echo Canceling': webrtc_dep.found()}, bool_yn: true, section: 'Misc dependencies')
cdata.set('HAVE_WEBRTC', webrtc_dep.found())
if webrtc_dep.found()
cdata.set('HAVE_WEBRTC', 1)
endif
# On FreeBSD, epoll-shim library is required for eventfd() and timerfd() # On FreeBSD, epoll-shim library is required for eventfd() and timerfd()
epoll_shim_dep = (build_machine.system() == 'freebsd' epoll_shim_dep = (build_machine.system() == 'freebsd'
@ -400,9 +378,7 @@ summary({'OpenSSL (for raop-sink)': openssl_lib.found()}, bool_yn: true)
lilv_lib = dependency('lilv-0', required: get_option('lv2')) lilv_lib = dependency('lilv-0', required: get_option('lv2'))
summary({'lilv (for lv2 plugins)': lilv_lib.found()}, bool_yn: true) summary({'lilv (for lv2 plugins)': lilv_lib.found()}, bool_yn: true)
if lilv_lib.found() cdata.set('HAVE_LILV', lilv_lib.found())
cdata.set('HAVE_LILV', 1)
endif
installed_tests_metadir = pipewire_datadir / 'installed-tests' / pipewire_name installed_tests_metadir = pipewire_datadir / 'installed-tests' / pipewire_name
installed_tests_execdir = pipewire_libexecdir / 'installed-tests' / pipewire_name installed_tests_execdir = pipewire_libexecdir / 'installed-tests' / pipewire_name
@ -411,7 +387,7 @@ installed_tests_template = files('template.test.in')
if not get_option('tests').disabled() if not get_option('tests').disabled()
gstack = find_program('gstack', required : false) gstack = find_program('gstack', required : false)
cdata.set10('HAVE_GSTACK', gstack.found()) cdata.set('HAVE_GSTACK', gstack.found())
endif endif
subdir('po') subdir('po')

View file

@ -594,7 +594,7 @@ static bool device_supports_required_mSBC_transport_modes(
/* Check if USB ALT6 is really available on the device */ /* Check if USB ALT6 is really available on the device */
if (device->adapter->bus_type == BUS_TYPE_USB && !msbc_alt1_ok && msbc_ok) { if (device->adapter->bus_type == BUS_TYPE_USB && !msbc_alt1_ok && msbc_ok) {
#if HAVE_LIBUSB #ifdef HAVE_LIBUSB
if (device->adapter->source_id == SOURCE_ID_USB) { if (device->adapter->source_id == SOURCE_ID_USB) {
msbc_ok = check_usb_altsetting_6(backend, device->adapter->vendor_id, msbc_ok = check_usb_altsetting_6(backend, device->adapter->vendor_id,
device->adapter->product_id); device->adapter->product_id);

View file

@ -5,24 +5,14 @@ foreach dep: bluez5_deps
endif endif
endforeach endforeach
if not get_option('bluez5-backend-hsp-native').disabled() cdata.set('HAVE_BLUEZ_5_BACKEND_NATIVE',
cdata.set('HAVE_BLUEZ_5_BACKEND_HSP_NATIVE', 1) not get_option('bluez5-backend-hsp-native').disabled() or
cdata.set('HAVE_BLUEZ_5_BACKEND_NATIVE', 1) not get_option('bluez5-backend-hfp-native').disabled())
endif cdata.set('HAVE_BLUEZ_5_BACKEND_HSP_NATIVE', not get_option('bluez5-backend-hsp-native').disabled())
if not get_option('bluez5-backend-hfp-native').disabled() cdata.set('HAVE_BLUEZ_5_BACKEND_HFP_NATIVE', not get_option('bluez5-backend-hfp-native').disabled())
cdata.set('HAVE_BLUEZ_5_BACKEND_HFP_NATIVE', 1) cdata.set('HAVE_BLUEZ_5_BACKEND_OFONO', not get_option('bluez5-backend-ofono').disabled())
cdata.set('HAVE_BLUEZ_5_BACKEND_NATIVE', 1) cdata.set('HAVE_BLUEZ_5_BACKEND_HSPHFPD', not get_option('bluez5-backend-hsphfpd').disabled())
endif cdata.set('HAVE_BLUEZ_5_HCI', dependency('bluez', version: '< 6', required: false).found())
if not get_option('bluez5-backend-ofono').disabled()
cdata.set('HAVE_BLUEZ_5_BACKEND_OFONO', 1)
endif
if not get_option('bluez5-backend-hsphfpd').disabled()
cdata.set('HAVE_BLUEZ_5_BACKEND_HSPHFPD', 1)
endif
if dependency('bluez', version: '< 6', required: false).found()
cdata.set('HAVE_BLUEZ_5_HCI', 1)
endif
bluez5_sources = [ bluez5_sources = [
'plugin.c', 'plugin.c',

View file

@ -51,7 +51,7 @@ plugin_init (GstPlugin *plugin)
gst_element_register (plugin, "pipewiresink", GST_RANK_NONE, gst_element_register (plugin, "pipewiresink", GST_RANK_NONE,
GST_TYPE_PIPEWIRE_SINK); GST_TYPE_PIPEWIRE_SINK);
#if HAVE_GSTREAMER_DEVICE_PROVIDER #ifdef HAVE_GSTREAMER_DEVICE_PROVIDER
if (!gst_device_provider_register (plugin, "pipewiredeviceprovider", if (!gst_device_provider_register (plugin, "pipewiredeviceprovider",
GST_RANK_PRIMARY + 1, GST_TYPE_PIPEWIRE_DEVICE_PROVIDER)) GST_RANK_PRIMARY + 1, GST_TYPE_PIPEWIRE_DEVICE_PROVIDER))
return FALSE; return FALSE;

View file

@ -273,7 +273,7 @@ if avahi_dep.found()
'module-zeroconf-discover/avahi-poll.c', 'module-zeroconf-discover/avahi-poll.c',
] ]
pipewire_module_protocol_pulse_deps += avahi_dep pipewire_module_protocol_pulse_deps += avahi_dep
cdata.set('HAVE_AVAHI', 1) cdata.set('HAVE_AVAHI', true)
endif endif
pipewire_module_protocol_pulse = shared_library('pipewire-module-protocol-pulse', pipewire_module_protocol_pulse = shared_library('pipewire-module-protocol-pulse',

View file

@ -32,10 +32,10 @@
#include "config.h" #include "config.h"
#if HAVE_SYS_VFS_H #ifdef HAVE_SYS_VFS_H
#include <sys/vfs.h> #include <sys/vfs.h>
#endif #endif
#if HAVE_SYS_MOUNT_H #ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h> #include <sys/mount.h>
#endif #endif

View file

@ -35,7 +35,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/file.h> #include <sys/file.h>
#include <ctype.h> #include <ctype.h>
#if HAVE_PWD_H #ifdef HAVE_PWD_H
#include <pwd.h> #include <pwd.h>
#endif #endif
#if defined(__FreeBSD__) #if defined(__FreeBSD__)

View file

@ -35,7 +35,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/file.h> #include <sys/file.h>
#if HAVE_PWD_H #ifdef HAVE_PWD_H
#include <pwd.h> #include <pwd.h>
#endif #endif

View file

@ -5105,7 +5105,7 @@ static void impl_clear(struct impl *impl)
pw_map_for_each(&impl->modules, impl_unload_module, impl); pw_map_for_each(&impl->modules, impl_unload_module, impl);
pw_map_clear(&impl->modules); pw_map_clear(&impl->modules);
#if HAVE_DBUS #ifdef HAVE_DBUS
if (impl->dbus_name) { if (impl->dbus_name) {
dbus_release_name(impl->dbus_name); dbus_release_name(impl->dbus_name);
impl->dbus_name = NULL; impl->dbus_name = NULL;
@ -5276,7 +5276,7 @@ struct pw_protocol_pulse *pw_protocol_pulse_new(struct pw_context *context,
pw_context_add_listener(context, &impl->context_listener, pw_context_add_listener(context, &impl->context_listener,
&context_events, impl); &context_events, impl);
#if HAVE_DBUS #ifdef HAVE_DBUS
impl->dbus_name = dbus_request_name(context, "org.pulseaudio.Server"); impl->dbus_name = dbus_request_name(context, "org.pulseaudio.Server");
#endif #endif

View file

@ -34,7 +34,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <dirent.h> #include <dirent.h>
#if HAVE_PWD_H #ifdef HAVE_PWD_H
#include <pwd.h> #include <pwd.h>
#endif #endif
#ifdef __FreeBSD__ #ifdef __FreeBSD__

View file

@ -27,7 +27,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#if HAVE_SYS_RANDOM_H #ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h> #include <sys/random.h>
#endif #endif
#include <string.h> #include <string.h>

View file

@ -24,7 +24,7 @@
#include "config.h" #include "config.h"
#if !HAVE_SIGABBREV_NP #ifndef HAVE_SIGABBREV_NP
#include <stddef.h> #include <stddef.h>
#include <signal.h> #include <signal.h>

View file

@ -36,10 +36,10 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#if HAVE_PIDFD_OPEN #ifdef HAVE_PIDFD_OPEN
#include <sys/syscall.h> #include <sys/syscall.h>
#endif #endif
#if HAVE_LIBCAP #ifdef HAVE_LIBCAP
#include <sys/capability.h> #include <sys/capability.h>
#endif #endif
#include <sys/epoll.h> #include <sys/epoll.h>
@ -177,7 +177,7 @@ static void restore_env(struct pwtest_test *t)
static void pwtest_backtrace(pid_t p) static void pwtest_backtrace(pid_t p)
{ {
#if HAVE_GSTACK #ifdef HAVE_GSTACK
char pid[11]; char pid[11];
pid_t parent, child; pid_t parent, child;
int status; int status;
@ -820,7 +820,7 @@ static int monitor_test_forked(struct pwtest_test *t, pid_t pid, int read_fds[_F
size_t nevents = 0; size_t nevents = 0;
int r; int r;
#if HAVE_PIDFD_OPEN #ifdef HAVE_PIDFD_OPEN
pidfd = syscall(SYS_pidfd_open, pid, 0); pidfd = syscall(SYS_pidfd_open, pid, 0);
#else #else
errno = ENOSYS; errno = ENOSYS;
@ -1168,7 +1168,7 @@ static void list_tests(struct pwtest_context *ctx)
static bool is_debugger_attached(void) static bool is_debugger_attached(void)
{ {
bool rc = false; bool rc = false;
#if HAVE_LIBCAP #ifdef HAVE_LIBCAP
int status; int status;
int pid = fork(); int pid = fork();

View file

@ -233,7 +233,7 @@ PWTEST(context_support)
SPA_TYPE_INTERFACE_Loop, SPA_TYPE_INTERFACE_Loop,
SPA_TYPE_INTERFACE_LoopUtils, SPA_TYPE_INTERFACE_LoopUtils,
SPA_TYPE_INTERFACE_Log, SPA_TYPE_INTERFACE_Log,
#if HAVE_DBUS #ifdef HAVE_DBUS
SPA_TYPE_INTERFACE_DBus, SPA_TYPE_INTERFACE_DBus,
#endif #endif
SPA_TYPE_INTERFACE_CPU SPA_TYPE_INTERFACE_CPU

View file

@ -32,7 +32,7 @@
PWTEST(compat_sigabbrev_np) PWTEST(compat_sigabbrev_np)
{ {
#if !HAVE_SIGABBREV_NP #ifndef HAVE_SIGABBREV_NP
pwtest_str_eq(sigabbrev_np(SIGABRT), "ABRT"); pwtest_str_eq(sigabbrev_np(SIGABRT), "ABRT");
pwtest_str_eq(sigabbrev_np(SIGSEGV), "SEGV"); pwtest_str_eq(sigabbrev_np(SIGSEGV), "SEGV");
pwtest_str_eq(sigabbrev_np(SIGSTOP), "STOP"); pwtest_str_eq(sigabbrev_np(SIGSTOP), "STOP");