build: make tests optional

Add a meson option -Dtests and --without-tests automake option
to disable the compilation of all available testcases.
This is useful for compiling projects with Flatpak such as
GNOME Control Center which disables all possible integrations since they
only need the DBus part of ModemManager.

Contributes to https://gitlab.gnome.org/GNOME/gnome-control-center/-/merge_requests/1392
This commit is contained in:
Dylan Van Assche
2022-07-25 09:18:29 +02:00
parent 041f53af8b
commit ba96ccc615
9 changed files with 57 additions and 10 deletions

View File

@@ -12,12 +12,15 @@ SUBDIRS = \
cli \
vapi \
introspection \
test \
tools \
examples \
docs \
$(NULL)
if WITH_TESTS
SUBDIRS += test
endif
ChangeLog:
$(AM_V_GEN) if test -d "$(srcdir)/.git"; then \
(GIT_DIR=$(top_srcdir)/.git $(top_srcdir)/missing --run git log --stat) | fmt --split-only > $@.tmp \

View File

@@ -251,6 +251,21 @@ case $with_udev in
;;
esac
dnl-----------------------------------------------------------------------------
dnl build with tests (enabled by default)
dnl
AC_ARG_WITH(tests, AS_HELP_STRING([--without-tests], [Build without testcases]), [], [with_tests=yes])
AM_CONDITIONAL(WITH_TESTS, test "x$with_tests" = "xyes")
case $with_tests in
yes)
AC_DEFINE(WITH_TESTS, 1, [Define if you want to build all testcases])
;;
*)
with_tests=no
;;
esac
dnl-----------------------------------------------------------------------------
dnl Suspend/resume support
dnl
@@ -629,6 +644,7 @@ examples/sms-python/Makefile
examples/network-scan-python/Makefile
examples/sms-c/Makefile
])
AC_OUTPUT
echo "
@@ -643,6 +659,7 @@ echo "
warn ldflags: ${WARN_LDFLAGS}
maintainer mode: ${USE_MAINTAINER_MODE}
release: ${ax_is_release}
tests: ${with_tests}
System paths:
prefix: ${prefix}

View File

@@ -1,5 +1,12 @@
SUBDIRS = . dispatcher-connection dispatcher-fcc-unlock tests
SUBDIRS = \
. \
dispatcher-connection \
dispatcher-fcc-unlock
if WITH_TESTS
SUBDIRS += tests
endif
edit = @sed \
-e 's|@sbindir[@]|$(sbindir)|g' \

View File

@@ -1,7 +1,9 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2021 Iñigo Martinez <inigomartinez@gmail.com>
subdir('tests')
if enable_tests
subdir('tests')
endif
service_conf = {
'sbindir': mm_prefix / mm_sbindir,

View File

@@ -3,7 +3,9 @@
# DBus Introspection files
mm_ifaces_all = files('all.xml')
mm_ifaces_test = files('tests/org.freedesktop.ModemManager1.Test.xml')
if enable_tests
mm_ifaces_test = files('tests/org.freedesktop.ModemManager1.Test.xml')
endif
mm_ifaces = files('org.freedesktop.ModemManager1.xml')

View File

@@ -196,4 +196,6 @@ if enable_gir
endif
endif
subdir('tests')
if enable_tests
subdir('tests')
endif

View File

@@ -88,6 +88,9 @@ cc_args = cc.get_supported_arguments([
'-Wno-missing-field-initializers',
])
# tests are enabled by default
enable_tests = get_option('tests')
# strict flags to use in debug builds
if get_option('buildtype').contains('debug')
cc_args += cc.get_supported_arguments([
@@ -266,7 +269,9 @@ if dist_version != ''
config_h.set('MM_DIST_VERSION', dist_version)
endif
util_dep = cc.find_library('util')
if enable_tests
util_dep = cc.find_library('util')
endif
# introspection support
enable_gir = get_option('introspection')
@@ -376,14 +381,19 @@ subdir('introspection')
subdir('include')
subdir('libqcdm/src')
subdir('libqcdm/tests')
if enable_tests
subdir('libqcdm/tests')
endif
subdir('libmm-glib')
subdir('src')
subdir('plugins')
subdir('cli')
subdir('test')
subdir('tools/tests')
if enable_tests
subdir('test')
subdir('tools/tests')
endif
subdir('examples/sms-c')

View File

@@ -4,6 +4,8 @@
option('udev', type: 'boolean', value: true, description: 'enable udev support')
option('udevdir', type: 'string', value: '', description: 'udev base directory')
option('tests', type: 'boolean', value: true, description: 'enable tests')
option('dbus_policy_dir', type: 'string', value: '', description: 'd-bus system policy directory')
option('systemdsystemunitdir', type: 'string', value: '', description: 'systemd system units directory')

View File

@@ -329,4 +329,6 @@ install_data(
install_dir: udev_rulesdir,
)
subdir('tests')
if enable_tests
subdir('tests')
endif