Use epoll-shim to emulate epoll(7) on FreeBSD
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Mon, 15 Mar 2021 22:18:14 +0000 (22:18 +0000)
committerAlexander Richardson <alexander.richardson@cl.cam.ac.uk>
Fri, 10 Sep 2021 11:35:54 +0000 (11:35 +0000)
FreeBSD does not provide epoll(7) and instead requires an external library,
epoll-shim, that implements epoll() using kqueue(2)

Co-authored-by: Jan Beich <jbeich@FreeBSD.org>
Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
meson.build
src/meson.build
tests/meson.build

index 714a86d..427aacf 100644 (file)
@@ -43,6 +43,14 @@ foreach f: have_funcs
 endforeach
 
 if get_option('libraries')
+       if host_machine.system() == 'freebsd'
+               # When building for FreeBSD, epoll(7) is provided by a userspace
+               # wrapper around kqueue(2).
+               epoll_dep = dependency('epoll-shim')
+       else
+               # Otherwise, assume that epoll(7) is supported natively.
+               epoll_dep = []
+       endif
        ffi_dep = dependency('libffi')
 
        decls = [
@@ -52,7 +60,7 @@ if get_option('libraries')
        ]
 
        foreach d: decls
-               if not cc.has_header_symbol(d['header'], d['symbol'])
+               if not cc.has_header_symbol(d['header'], d['symbol'], dependencies: epoll_dep)
                        error('@0@ is needed to compile Wayland libraries'.format(d['symbol']))
                endif
        endforeach
index ec00d81..a5d7410 100644 (file)
@@ -89,7 +89,7 @@ if get_option('libraries')
                        'connection.c',
                        'wayland-os.c'
                ],
-               dependencies: [ ffi_dep, rt_dep ]
+               dependencies: [ epoll_dep, ffi_dep, rt_dep ]
        )
 
        wayland_private_dep = declare_dependency(
@@ -163,6 +163,7 @@ if get_option('libraries')
                ],
                version: '0.1.0',
                dependencies: [
+                       epoll_dep,
                        ffi_dep,
                        wayland_private_dep,
                        wayland_util_dep,
@@ -177,7 +178,7 @@ if get_option('libraries')
        wayland_server_dep = declare_dependency(
                link_with: wayland_server,
                include_directories: [ root_inc, include_directories('.') ],
-               dependencies: [ ffi_dep, mathlib_dep, threads_dep ],
+               dependencies: [ epoll_dep, ffi_dep, mathlib_dep, threads_dep ],
                sources: [
                        wayland_server_protocol_core_h,
                        wayland_server_protocol_h
@@ -206,6 +207,7 @@ if get_option('libraries')
                ],
                version: '0.3.0',
                dependencies: [
+                       epoll_dep,
                        ffi_dep,
                        wayland_private_dep,
                        wayland_util_dep,
index 2e11af4..58794e7 100644 (file)
@@ -9,6 +9,7 @@ test_runner = static_library(
        dependencies: [
                cc.find_library('dl', required: false),
                dependency('threads'),
+               epoll_dep,
                ffi_dep,
                wayland_util_dep,
                wayland_private_dep,
@@ -154,7 +155,7 @@ tests = {
 
 foreach test_name, test_extra_sources: tests
        test_sources = [ test_name + '.c' ] + test_extra_sources
-       test_deps = [test_runner_dep]
+       test_deps = [test_runner_dep, epoll_dep]
        bin = executable(test_name, test_sources, dependencies: test_deps)
        test(
                test_name,