Skip to content

Commit 52b8aaa

Browse files
committed
meson build: Add support for meson build
1 parent dd45f19 commit 52b8aaa

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

meson.build

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
project('libmodbus', 'c', version : '3.1.8')
2+
3+
libmodbus_version = meson.project_version()
4+
ver_arr = libmodbus_version.split('.')
5+
6+
libmodbus_version_major = ver_arr[0]
7+
libmodbus_version_minor = ver_arr[1]
8+
libmodbus_version_micro = ver_arr[2]
9+
10+
ver_conf = configuration_data()
11+
ver_conf.set('LIBMODBUS_VERSION', libmodbus_version)
12+
ver_conf.set('LIBMODBUS_VERSION_MAJOR', libmodbus_version_major)
13+
ver_conf.set('LIBMODBUS_VERSION_MINOR', libmodbus_version_minor)
14+
ver_conf.set('LIBMODBUS_VERSION_MICRO', libmodbus_version_micro)
15+
16+
cc = meson.get_compiler('c')
17+
cdata = configuration_data()
18+
check_headers = [
19+
'arpa/inet.h',
20+
'byteswap.h',
21+
'errno.h',
22+
'fcntl.h',
23+
'inttypes.h',
24+
'limits.h',
25+
'linux/serial.h',
26+
'netdb.h',
27+
'netinet/in.h',
28+
'netinet/tcp.h',
29+
'stdint.h',
30+
'sys/ioctl.h',
31+
'sys/params.h',
32+
'sys/socket.h',
33+
'sys/time.h',
34+
'sys/types.h',
35+
'termios.h',
36+
'time.h',
37+
'unistd.h',
38+
]
39+
40+
foreach h : check_headers
41+
if cc.has_header(h)
42+
cdata.set('HAVE_' + h.underscorify().to_upper(), 1)
43+
endif
44+
endforeach
45+
46+
check_functions = [
47+
['HAVE_ACCEPT4', 'accept4', '#include<sys/socket.h>'],
48+
['HAVE_GETADDRINFO', 'getaddrinfo', '#include<netdb.h>'],
49+
['HAVE_GETTIMEOFDAY', 'gettimeofday', '#include<sys/time.h>'],
50+
['HAVE_SELECT', 'select', '#include<sys/select.h>'],
51+
['HAVE_SOCKET', 'socket', '#include<sys/socket.h>'],
52+
['HAVE_STRERROR', 'strerror', '#include<string.h>'],
53+
['HAVE_STRLCPY', 'strlcpy', '#include<string.h>'],
54+
]
55+
56+
foreach f : check_functions
57+
if cc.has_function(f.get(1), prefix : f.get(2))
58+
cdata.set(f.get(0), 1)
59+
endif
60+
endforeach
61+
62+
configure_file(output : 'config.h',
63+
configuration : cdata)
64+
65+
subdir('src')
66+
subdir('tests')

src/meson.build

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
modbus_version_h = configure_file(input : 'modbus-version.h.in',
2+
output : 'modbus-version.h',
3+
configuration : ver_conf)
4+
5+
sources = files([
6+
'modbus.c',
7+
'modbus-data.c',
8+
'modbus-rtu.c',
9+
'modbus-tcp.c',
10+
])
11+
12+
headers = [
13+
'modbus.h',
14+
modbus_version_h,
15+
'modbus-rtu.h',
16+
'modbus-tcp.h',
17+
]
18+
install_headers(headers, subdir : 'modbus')
19+
20+
lt_current = 6
21+
lt_revision = 0
22+
lt_age = 1
23+
lt_version = '@0@.@1@.@2@'.format(lt_current - lt_age, lt_age, lt_revision)
24+
25+
libmodbus = shared_library('modbus', sources,
26+
version: lt_version,
27+
include_directories : include_directories('..'),
28+
install : true)
29+
30+
incdir = include_directories('.')
31+
libmodbus_dep = declare_dependency(link_with : libmodbus,
32+
include_directories: incdir)

tests/meson.build

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
configure_file(input : 'unit-test.h.in',
2+
output : 'unit-test.h',
3+
configuration : cdata)
4+
5+
incdir = include_directories('../src')
6+
7+
bandwidth_server_one = executable(
8+
'bandwidth-server-one', 'bandwidth-server-one.c',
9+
dependencies : libmodbus_dep
10+
)
11+
12+
bandwidth_server_many_up = executable(
13+
'bandwidth-server-many-up', 'bandwidth-server-many-up.c',
14+
dependencies : libmodbus_dep
15+
)
16+
17+
bandwidth_client = executable(
18+
'bandwidth-client', 'bandwidth-client.c',
19+
dependencies : libmodbus_dep
20+
)
21+
22+
random_test_server = executable(
23+
'random-test-server', 'random-test-server.c',
24+
dependencies : libmodbus_dep
25+
)
26+
27+
random_test_client = executable(
28+
'random-test-client', 'random-test-client.c',
29+
dependencies : libmodbus_dep
30+
)
31+
32+
unit_test_server = executable(
33+
'unit-test-server', 'unit-test-server.c',
34+
dependencies : libmodbus_dep
35+
)
36+
37+
unit_test_client = executable(
38+
'unit-test-client', 'unit-test-client.c',
39+
dependencies : libmodbus_dep
40+
)
41+
42+
test('unit-tests', find_program('unit-tests.sh'),
43+
workdir : meson.current_build_dir())

0 commit comments

Comments
 (0)