Skip to content

Commit

Permalink
meson build: Add support for meson build
Browse files Browse the repository at this point in the history
  • Loading branch information
ringlej committed Nov 8, 2022
1 parent d6da9a1 commit e429b4c
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
66 changes: 66 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
project('libmodbus', 'c', version : '3.1.8')

libmodbus_version = meson.project_version()
ver_arr = libmodbus_version.split('.')

libmodbus_version_major = ver_arr[0]
libmodbus_version_minor = ver_arr[1]
libmodbus_version_micro = ver_arr[2]

ver_conf = configuration_data()
ver_conf.set('LIBMODBUS_VERSION', libmodbus_version)
ver_conf.set('LIBMODBUS_VERSION_MAJOR', libmodbus_version_major)
ver_conf.set('LIBMODBUS_VERSION_MINOR', libmodbus_version_minor)
ver_conf.set('LIBMODBUS_VERSION_MICRO', libmodbus_version_micro)

cc = meson.get_compiler('c')
cdata = configuration_data()
check_headers = [
'arpa/inet.h',
'byteswap.h',
'errno.h',
'fcntl.h',
'inttypes.h',
'limits.h',
'linux/serial.h',
'netdb.h',
'netinet/in.h',
'netinet/tcp.h',
'stdint.h',
'sys/ioctl.h',
'sys/params.h',
'sys/socket.h',
'sys/time.h',
'sys/types.h',
'termios.h',
'time.h',
'unistd.h',
]

foreach h : check_headers
if cc.has_header(h)
cdata.set('HAVE_' + h.underscorify().to_upper(), 1)
endif
endforeach

check_functions = [
['HAVE_ACCEPT4', 'accept4', '#include<sys/socket.h>'],
['HAVE_GETADDRINFO', 'getaddrinfo', '#include<netdb.h>'],
['HAVE_GETTIMEOFDAY', 'gettimeofday', '#include<sys/time.h>'],
['HAVE_SELECT', 'select', '#include<sys/select.h>'],
['HAVE_SOCKET', 'socket', '#include<sys/socket.h>'],
['HAVE_STRERROR', 'strerror', '#include<string.h>'],
['HAVE_STRLCPY', 'strlcpy', '#include<string.h>'],
]

foreach f : check_functions
if cc.has_function(f.get(1), prefix : f.get(2))
cdata.set(f.get(0), 1)
endif
endforeach

configure_file(output : 'config.h',
configuration : cdata)

subdir('src')
subdir('tests')
29 changes: 29 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
modbus_version_h = configure_file(input : 'modbus-version.h.in',
output : 'modbus-version.h',
configuration : ver_conf)

sources = files([
'modbus.c',
'modbus-data.c',
'modbus-rtu.c',
'modbus-tcp.c',
])

headers = [
'modbus.h',
modbus_version_h,
'modbus-rtu.h',
'modbus-tcp.h',
]
install_headers(headers, subdir : 'modbus')

lt_current = 6
lt_revision = 0
lt_age = 1
lt_version = '@0@.@1@.@2@'.format(lt_current, lt_age, lt_revision)

modbuslib = library('modbus', sources,
version: lt_version,
soversion: lt_current,
include_directories : include_directories('..'),
install : true)
50 changes: 50 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
configure_file(input : 'unit-test.h.in',
output : 'unit-test.h',
configuration : cdata)

incdir = include_directories('../src')

bandwidth_server_one = executable(
'bandwidth-server-one', 'bandwidth-server-one.c',
link_with : modbuslib,
include_directories : incdir
)

bandwidth_server_many_up = executable(
'bandwidth-server-many-up', 'bandwidth-server-many-up.c',
link_with : modbuslib,
include_directories : incdir
)

bandwidth_client = executable(
'bandwidth-client', 'bandwidth-client.c',
link_with : modbuslib,
include_directories : incdir
)

random_test_server = executable(
'random-test-server', 'random-test-server.c',
link_with : modbuslib,
include_directories : incdir
)

random_test_client = executable(
'random-test-client', 'random-test-client.c',
link_with : modbuslib,
include_directories : incdir
)

unit_test_server = executable(
'unit-test-server', 'unit-test-server.c',
link_with : modbuslib,
include_directories : incdir
)

unit_test_client = executable(
'unit-test-client', 'unit-test-client.c',
link_with : modbuslib,
include_directories : incdir
)

test('unit-tests', find_program('unit-tests.sh'),
workdir : meson.current_build_dir())

0 comments on commit e429b4c

Please sign in to comment.