Skip to content

Commit be3c354

Browse files
committed
meson: add support for meson build system
1 parent 5e200de commit be3c354

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

README

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,37 @@ To build and run the tests, run 'make test'.
5858
In release mode, fewer tests will be run as the assert() calls will be
5959
elided.
6060

61+
Meson
62+
-----
63+
64+
This project can also be built with [meson](https://github.com/mesonbuild/meson)
65+
66+
1. Install Python and meson
67+
`pip install meson`
68+
69+
2. Set up meson build
70+
(optionally set install path, otherwise remove -prefix)
71+
(optionally enable tests)
72+
73+
```
74+
export PREFIX=PATH/TO/INSTALL/DIRECTORY
75+
meson setup builddir --prefix=$PREFIX -Dtests=true
76+
```
77+
78+
3. Compile and optionally run tests
79+
80+
```
81+
meson compile -C builddir -v
82+
meson test -C builddir -v
83+
```
84+
85+
4. Install
86+
87+
```
88+
meson install -C builddir
89+
```
90+
91+
6192
API documentation
6293
-----------------
6394

meson.build

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
project('wapcaplet', 'c',
2+
version: '0.4.3',
3+
default_options: ['c_std=c99', 'warning_level=2'])
4+
5+
cc = meson.get_compiler('c')
6+
7+
# Compiler flags
8+
cflags = ['-D_BSD_SOURCE', '-D_DEFAULT_SOURCE', '-DSTMTEXPR']
9+
if cc.get_id() != 'gcc' or cc.version().split('.')[0].to_int() >= 3
10+
cflags += ['-Wstrict-prototypes', '-Wmissing-prototypes', '-Wmissing-declarations', '-Wnested-externs']
11+
endif
12+
if host_machine.system() != 'haiku'
13+
cflags += ['-Werror']
14+
endif
15+
16+
# Source files
17+
wapcaplet_sources = files(
18+
'src/libwapcaplet.c'
19+
)
20+
21+
# Include directories
22+
inc = include_directories('include')
23+
24+
# Build the static library
25+
wapcaplet_lib = static_library('wapcaplet',
26+
sources: wapcaplet_sources,
27+
include_directories: inc,
28+
c_args: cflags,
29+
install: true
30+
)
31+
32+
# Install headers
33+
install_headers('include/libwapcaplet/libwapcaplet.h',
34+
subdir: 'libwapcaplet'
35+
)
36+
37+
# Pkg-config file
38+
pkg = import('pkgconfig')
39+
pkg.generate(wapcaplet_lib,
40+
name: 'libwapcaplet',
41+
description: 'A string internment library',
42+
version: '0.4.3',
43+
subdirs: '' # Set to empty to use ${includedir} instead of ${includedir}/libwapcaplet
44+
)
45+
46+
# Tests
47+
if get_option('tests')
48+
check_dep = dependency('check', required: false)
49+
if check_dep.found()
50+
test_exe = executable('wapcaplet_test',
51+
sources: ['test/testmain.c', 'test/basictests.c'],
52+
include_directories: inc,
53+
link_with: wapcaplet_lib,
54+
c_args: cflags,
55+
dependencies: check_dep
56+
)
57+
test('wapcaplet_tests', test_exe)
58+
endif
59+
endif

meson_options.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
option('tests', type: 'boolean', value: false, description: 'Enable test suite')

0 commit comments

Comments
 (0)