Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meson support #666

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/meson-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Meson build libmodbus

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: BSFishy/[email protected]
with:
action: test
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')
32 changes: 32 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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_age, lt_revision)

libmodbus = shared_library('modbus', sources,
version: lt_version,
include_directories : include_directories('..'),
install : true)

incdir = include_directories('.')
libmodbus_dep = declare_dependency(link_with : libmodbus,
include_directories: incdir)
41 changes: 41 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
configure_file(input : 'unit-test.h.in',
output : 'unit-test.h',
configuration : cdata)

bandwidth_server_one = executable(
'bandwidth-server-one', 'bandwidth-server-one.c',
dependencies : libmodbus_dep
)

bandwidth_server_many_up = executable(
'bandwidth-server-many-up', 'bandwidth-server-many-up.c',
dependencies : libmodbus_dep
)

bandwidth_client = executable(
'bandwidth-client', 'bandwidth-client.c',
dependencies : libmodbus_dep
)

random_test_server = executable(
'random-test-server', 'random-test-server.c',
dependencies : libmodbus_dep
)

random_test_client = executable(
'random-test-client', 'random-test-client.c',
dependencies : libmodbus_dep
)

unit_test_server = executable(
'unit-test-server', 'unit-test-server.c',
dependencies : libmodbus_dep
)

unit_test_client = executable(
'unit-test-client', 'unit-test-client.c',
dependencies : libmodbus_dep
)

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