Skip to content

Commit

Permalink
build: introduce Meson build file rules
Browse files Browse the repository at this point in the history
The Meson build system used by many other virt projects (QEMU, libvirt
and others) is easier to understand & maintain rules for than cmake,
guiding towards best practice.

Signed-off-by: Daniel P. Berrangé <[email protected]>
  • Loading branch information
berrange authored and jlevon committed May 9, 2022
1 parent 18fb66b commit 5b69b60
Showing 9 changed files with 422 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

if rstlint.found()
test(
'rstlint',
rstlint,
suite: 'style',
args: ['vfio-user.rst'],
)
endif
15 changes: 15 additions & 0 deletions include/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

public_include_dir = [include_directories('.')]

libvfio_user_includes = files(
'libvfio-user.h',
'pci_defs.h',
'vfio-user.h'
)

install_headers(
libvfio_user_includes,
subdir: 'vfio-user'
)

subdir('pci_caps')
14 changes: 14 additions & 0 deletions include/pci_caps/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

libvfio_user_pci_caps_includes = files(
'common.h',
'dsn.h',
'msi.h',
'msix.h',
'pm.h',
'px.h',
)

install_headers(
libvfio_user_pci_caps_includes,
subdir: 'vfio-user' / 'pci_caps'
)
47 changes: 47 additions & 0 deletions lib/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

lib_include_dir = [include_directories('.')]

libvfio_user_cflags = []

libvfio_user_sources = [
'dma.c',
'irq.c',
'libvfio-user.c',
'migration.c',
'pci.c',
'pci_caps.c',
'tran.c',
'tran_sock.c',
]

if opt_tran_pipe
libvfio_user_sources += ['tran_pipe.c']
libvfio_user_cflags += ['-DWITH_TRAN_PIPE']
endif

libvfio_user_deps = [
json_c_dep,
]

libvfio_user = library(
'vfio-user',
sources: libvfio_user_sources,
c_args: libvfio_user_cflags + common_cflags,
dependencies: libvfio_user_deps,
include_directories: public_include_dir,
gnu_symbol_visibility: 'hidden',
# We're not providing a stable ABI yet, so
# this remains 0 regardless of API changes
soversion: 0,
version: '0.0.1',
install: true,
install_rpath: rpathdir,
)

libvfio_user_dep = declare_dependency(
link_with: libvfio_user,
dependencies: libvfio_user_deps,
include_directories: public_include_dir,
)

libvfio_so_dir = meson.current_build_dir()
67 changes: 67 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
project(
'libvfio-user',
'c',
version: '0.0.1',
license: 'BSD-3-Clause',
meson_version: '>= 0.53.0',
default_options: [
'buildtype=debugoptimized',
'c_std=gnu99',
'warning_level=2',
],
)

opt_rpath = get_option('rpath')
opt_tran_pipe = get_option('tran-pipe')
opt_debug_logs = get_option('debug-logs')
opt_sanitizers = get_option('b_sanitize')
opt_debug = get_option('debug')

cc = meson.get_compiler('c')

prefix = get_option('prefix')
libdir = prefix / get_option('libdir')

if prefix == '/usr' and not opt_rpath.enabled()
rpathdir = ''
else
rpathdir = libdir
endif

thread_dep = dependency('threads')
dl_dep = cc.find_library('dl', required: true)

json_c_version = '0.11'
json_c_dep = dependency('json-c', version: '>=' + json_c_version)

cmocka_version = ''
cmocka_dep = dependency('cmocka', version: '>=' + cmocka_version)


pytest = find_program('pytest-3', required: false)
flake8 = find_program('flake8', required: false)
rstlint = find_program('restructuredtext-lint', required: false)
valgrind = find_program('valgrind', required: false)

common_cflags = [
'-D_GNU_SOURCE',
]

if opt_debug_logs.enabled() or (not opt_debug_logs.disabled() and opt_debug)
common_cflags += ['-DDEBUG']
endif

if get_option('warning_level') == '2'
# -Wall is set for 'warning_level>=1'
# -Wextra is set for 'warning_level>=2'
common_cflags += cc.get_supported_arguments([
'-Wno-missing-field-initializers',
'-Wmissing-declarations',
])
endif

subdir('include')
subdir('lib')
subdir('samples')
subdir('test')
subdir('docs')
6 changes: 6 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
option('rpath', type: 'feature', value: 'auto',
description: 'whether to include rpath information in installed binaries and libraries')
option('tran-pipe', type: 'boolean', value: false,
description: 'enable pipe transport for testing')
option('debug-logs', type: 'feature', value: 'auto',
description: 'enable extra debugging code (default for debug builds)')
94 changes: 94 additions & 0 deletions samples/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

client_sources = [
'client.c',
'../lib/migration.c',
'../lib/tran.c',
'../lib/tran_sock.c',
]

client_deps = [
json_c_dep,
thread_dep,
]

client = executable(
'client',
client_sources,
c_args: common_cflags,
dependencies: client_deps,
include_directories: public_include_dir + lib_include_dir,
install: false,
)


server_sources = [
'server.c',
]

server_deps = [
libvfio_user_dep,
]

server = executable(
'server',
server_sources,
c_args: common_cflags,
dependencies: server_deps,
include_directories: lib_include_dir,
install: false,
)


null_sources = [
'null.c',
]

null_deps = [
libvfio_user_dep,
thread_dep,
]

null = executable(
'null',
null_sources,
c_args: common_cflags,
dependencies: null_deps,
include_directories: lib_include_dir,
install: false,
)


gpio_pci_idio_16_sources = [
'gpio-pci-idio-16.c',
]

gpio_pci_idio_16_deps = [
libvfio_user_dep,
]

gpio_pci_idio_16 = executable(
'gpio-pci-idio-16',
gpio_pci_idio_16_sources,
c_args: common_cflags,
dependencies: gpio_pci_idio_16_deps,
include_directories: lib_include_dir,
install: false,
)


lspci_sources = [
'lspci.c',
]

lspci_deps = [
libvfio_user_dep,
]

lspci = executable(
'lspci',
lspci_sources,
c_args: common_cflags,
dependencies: lspci_deps,
include_directories: lib_include_dir,
install: false,
)
99 changes: 99 additions & 0 deletions test/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

if valgrind.found()
valgrind_common_wrapper = [
valgrind,
'--quiet',
'--track-origins=yes',
'--error-exitcode=1',
'--exit-on-first-error=yes',
'--leak-check=full',
]

valgrind_unit_wrapper = valgrind_common_wrapper + [
'--suppressions=' + ( meson.current_source_dir() / 'valgrind.supp' ),
'--show-leak-kinds=all',
]
if meson.version().version_compare('<0.57.0')
add_test_setup('valgrind',
exe_wrapper: valgrind_unit_wrapper)
else
add_test_setup('valgrind',
exclude_suites: ['functional', 'pyunit', 'style'],
exe_wrapper: valgrind_unit_wrapper)
endif
endif

unit_tests_sources = [
'unit-tests.c',
'mocks.c',
'../lib/dma.c',
'../lib/irq.c',
'../lib/libvfio-user.c',
'../lib/migration.c',
'../lib/pci.c',
'../lib/pci_caps.c',
'../lib/tran.c',
'../lib/tran_pipe.c',
'../lib/tran_sock.c',
]

unit_tests_deps = [
json_c_dep,
cmocka_dep,
dl_dep,
]
unit_tests_cflags = [
'-DUNIT_TEST',
'-DWITH_TRAN_PIPE',
]

unit_tests = executable(
'unit_tests',
unit_tests_sources,
c_args: unit_tests_cflags + common_cflags,
dependencies: unit_tests_deps,
include_directories: public_include_dir + lib_include_dir,
install: false,
)

test(
'unit_tests',
unit_tests,
suite: 'unit',
)

test(
'test-lspci',
find_program('test-lspci.sh'),
suite: 'functional',
args: [lspci],
)

csenv = []
if opt_sanitizers != 'none'
csenv += ['WITH_ASAN=1']
endif

test(
'test-client-server',
find_program('test-client-server.sh'),
env: csenv,
suite: 'functional',
args: [client, server],
timeout: 90,
)

if opt_sanitizers == 'none'
test(
'test-linkage.sh',
find_program('test-linkage.sh'),
suite: 'functional',
args: [
meson.source_root(),
meson.build_root(),
' '.join(cc.cmd_array()),
]
)
endif

subdir('py')
Loading

0 comments on commit 5b69b60

Please sign in to comment.