summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2022-08-26 14:37:55 +0100
committerSimon McVittie <smcv@collabora.com>2022-09-05 09:18:53 +0100
commitcbac331caf7bc6ea35e710972f7fc78c602434b1 (patch)
tree8598158197da7fbc672fcd1b3ac7bd26ab187407
parente9aa22ce379fad9d0a6d261ab1c1ef6ffc105838 (diff)
downloaddbus-python-cbac331caf7bc6ea35e710972f7fc78c602434b1.tar.gz
Add a Meson build system
This allows larger projects to use this as a Meson subproject. Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r--meson.build144
-rw-r--r--meson_options.txt23
-rw-r--r--tests/meson.build66
-rw-r--r--tests/use-as-subproject.py34
-rw-r--r--tests/use-as-subproject/.gitignore5
-rw-r--r--tests/use-as-subproject/README8
-rw-r--r--tests/use-as-subproject/meson.build30
-rw-r--r--tests/use-as-subproject/use-dbus-gmain.c14
8 files changed, 324 insertions, 0 deletions
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..4b96061
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,144 @@
+# Copyright 2022 Collabora Ltd.
+# SPDX-License-Identifier: MIT
+
+project(
+ 'dbus-gmain',
+ 'c',
+ default_options: [
+ 'warning_level=2',
+ ],
+ meson_version: '>=0.56',
+)
+
+cc = meson.get_compiler('c')
+compile_warnings = []
+compile_warnings_c = []
+
+if cc.get_id() != 'msvc'
+ # -fno-common makes the linker more strict: on some systems the linker
+ # is *always* this strict, so we want to behave like that everywhere.
+ # We treat this like a warning, since that's basically how we're using it.
+ compile_warnings += ['-fno-common']
+
+ compile_warnings += [
+ # These warnings are intentionally disabled:
+ # - missing field initializers being implicitly 0 is a feature,
+ # not a bug
+ # - -Wunused-parameter is annoying when writing callbacks that follow
+ # a fixed signature but do not necessarily need all of its parameters
+ '-Wno-missing-field-initializers',
+ '-Wno-unused-parameter',
+
+ # General warnings for both C and C++, excluding those that are part
+ # of -Wall or -Wextra
+ '-Wcast-align',
+ '-Wdouble-promotion',
+ '-Wduplicated-branches',
+ '-Wduplicated-cond',
+ '-Wfloat-equal',
+ '-Wformat-nonliteral',
+ '-Wformat-security',
+ '-Wformat=2',
+ '-Winit-self',
+ '-Wlogical-op',
+ '-Wmissing-declarations',
+ '-Wmissing-format-attribute',
+ '-Wmissing-include-dirs',
+ '-Wmissing-noreturn',
+ '-Wnull-dereference',
+ '-Wpacked',
+ '-Wpointer-arith',
+ '-Wredundant-decls',
+ '-Wshadow',
+ '-Wswitch-default',
+ '-Wswitch-enum',
+ '-Wundef',
+ '-Wunused-but-set-variable',
+ '-Wwrite-strings',
+ ]
+
+ compile_warnings_c += [
+ # Extra warnings just for C
+ '-Wdeclaration-after-statement',
+ '-Wjump-misses-init',
+ '-Wmissing-prototypes',
+ '-Wnested-externs',
+ '-Wold-style-definition',
+ '-Wpointer-sign',
+ '-Wstrict-prototypes',
+ ]
+endif
+
+compile_warnings_c = cc.get_supported_arguments(
+ compile_warnings + compile_warnings_c,
+)
+add_project_arguments(compile_warnings_c, language: 'c')
+
+if get_option('redefine_function_declaration') != ''
+ if not get_option('redefine_function_declaration').contains('name')
+ error('redefine_function_declaration option needs to contain "name"')
+ endif
+
+ if not get_option('redefine_function_declaration').contains('ret')
+ error('redefine_function_declaration option needs to contain "ret"')
+ endif
+
+ if not get_option('redefine_function_declaration').contains('__VA_ARGS__')
+ error('redefine_function_declaration option needs to contain "__VA_ARGS__"')
+ endif
+
+ add_project_arguments(
+ '-DDBUS_GMAIN_FUNCTION(ret, name, ...)=@0@'.format(
+ get_option('redefine_function_declaration'),
+ ),
+ language: 'c',
+ )
+endif
+
+if get_option('redefine_function_name') != ''
+ if not get_option('redefine_function_name').contains('name')
+ error('redefine_function_name option needs to contain "name"')
+ endif
+
+ add_project_arguments(
+ '-DDBUS_GMAIN_FUNCTION_NAME(name)=@0@'.format(
+ get_option('redefine_function_name'),
+ ),
+ language: 'c',
+ )
+endif
+
+dbus_dep = dependency('dbus-1', version: '>=1.8')
+glib_dep = dependency('glib-2.0', version: '>=2.40')
+gthread_dep = dependency(
+ 'gthread-2.0',
+ version: '>=2.40',
+ required: get_option('tests'),
+)
+
+libdbus_gmain = static_library(
+ 'dbus-gmain',
+ 'dbus-gmain.c',
+ dependencies: [
+ dbus_dep,
+ glib_dep,
+ ],
+)
+
+dbus_gmain_dep = declare_dependency(
+ dependencies: [
+ dbus_dep,
+ glib_dep,
+ ],
+ include_directories: include_directories('.'),
+ link_with: libdbus_gmain,
+)
+
+dbus_run_session = find_program(
+ 'dbus-run-session',
+ required: get_option('tests'),
+)
+
+if get_option('tests')
+ subdir('tests')
+endif
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..ed06753
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,23 @@
+# Copyright 2022 Collabora Ltd.
+# SPDX-License-Identifier: MIT
+
+option(
+ 'redefine_function_declaration',
+ type: 'string',
+ value: 'G_GNUC_INTERNAL ret DBUS_GMAIN_FUNCTION_NAME (name) (__VA_ARGS__)',
+ description: 'Redefinition of DBUS_GMAIN_FUNCTION(ret, name, ...)',
+)
+
+option(
+ 'redefine_function_name',
+ type: 'string',
+ value: 'dbus_gmain_ ## name',
+ description: 'Redefinition of DBUS_GMAIN_FUNCTION_NAME(name)',
+)
+
+option(
+ 'tests',
+ type: 'boolean',
+ value: true,
+ description: 'Enable unit tests',
+)
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644
index 0000000..8344ee2
--- /dev/null
+++ b/tests/meson.build
@@ -0,0 +1,66 @@
+# Copyright 2022 Collabora Ltd.
+# SPDX-License-Identifier: MIT
+
+testlib = static_library(
+ 'testutils',
+ 'util.c',
+ dependencies: [
+ dbus_dep,
+ glib_dep,
+ ],
+)
+
+test_thread_server = executable(
+ 'test-thread-server',
+ 'test-thread-server.c',
+ dependencies: [
+ dbus_gmain_dep,
+ dbus_dep,
+ glib_dep,
+ gthread_dep,
+ ],
+ link_with: testlib,
+)
+
+test_thread_client = executable(
+ 'test-thread-client',
+ 'test-thread-client.c',
+ dependencies: [
+ dbus_gmain_dep,
+ dbus_dep,
+ glib_dep,
+ gthread_dep,
+ ],
+ link_with: testlib,
+)
+
+test_cases = ['30574']
+
+foreach test_case : test_cases
+ exe = executable(
+ 'test-' + test_case,
+ test_case + '.c',
+ dependencies: [
+ dbus_gmain_dep,
+ dbus_dep,
+ glib_dep,
+ ],
+ link_with: testlib,
+ )
+ test(
+ test_case,
+ dbus_run_session,
+ args: [
+ '--',
+ exe,
+ ],
+ )
+endforeach
+
+test(
+ 'use-as-subproject',
+ find_program('python3'),
+ args: [
+ files('use-as-subproject.py'),
+ ],
+)
diff --git a/tests/use-as-subproject.py b/tests/use-as-subproject.py
new file mode 100644
index 0000000..3f45c5b
--- /dev/null
+++ b/tests/use-as-subproject.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+# Copyright 2022 Collabora Ltd.
+# SPDX-License-Identifier: MIT
+
+import os
+import shutil
+import subprocess
+import tempfile
+
+HERE = os.path.dirname(os.path.abspath(__file__))
+
+if __name__ == '__main__':
+ if shutil.which('meson') is None:
+ print('SKIP: meson not found in PATH')
+ raise SystemExit(0)
+
+ with tempfile.TemporaryDirectory() as temp:
+ shutil.copytree(
+ os.path.join(HERE, 'use-as-subproject'),
+ os.path.join(temp, 'src'),
+ )
+ os.makedirs(os.path.join(temp, 'src', 'subprojects'), exist_ok=True)
+ os.symlink(
+ os.path.dirname(HERE),
+ os.path.join(temp, 'src', 'subprojects', 'dbus-gmain'),
+ )
+ subprocess.run(
+ ['meson', os.path.join(temp, 'src'), os.path.join(temp, 'build')],
+ check=True,
+ )
+ subprocess.run(
+ ['meson', 'compile', '-C', os.path.join(temp, 'build')],
+ check=True,
+ )
diff --git a/tests/use-as-subproject/.gitignore b/tests/use-as-subproject/.gitignore
new file mode 100644
index 0000000..348f6b5
--- /dev/null
+++ b/tests/use-as-subproject/.gitignore
@@ -0,0 +1,5 @@
+# Copyright 2022 Collabora Ltd.
+# SPDX-License-Identifier: MIT
+
+/_build/
+/subprojects/
diff --git a/tests/use-as-subproject/README b/tests/use-as-subproject/README
new file mode 100644
index 0000000..d0f10fd
--- /dev/null
+++ b/tests/use-as-subproject/README
@@ -0,0 +1,8 @@
+This is a simple example of a project that uses dbus-gmain as a subproject.
+The intention is that if this project can successfully build and use it
+as a subproject, then so could dbus-glib and dbus-python.
+
+<!--
+Copyright 2022 Collabora Ltd.
+SPDX-License-Identifier: MIT
+-->
diff --git a/tests/use-as-subproject/meson.build b/tests/use-as-subproject/meson.build
new file mode 100644
index 0000000..65f651a
--- /dev/null
+++ b/tests/use-as-subproject/meson.build
@@ -0,0 +1,30 @@
+# Copyright 2022 Collabora Ltd.
+# SPDX-License-Identifier: MIT
+
+project(
+ 'use-dbus-gmain-as-subproject',
+ 'c',
+ version : '0',
+ meson_version : '>=0.49.0',
+)
+
+redefine_function_declaration = 'ret DBUS_GMAIN_FUNCTION_NAME (name) (__VA_ARGS__)'
+redefine_function_name = '_my_ ## name'
+
+add_project_arguments(
+ '-DDBUS_GMAIN_FUNCTION(ret, name, ...)=' + redefine_function_declaration,
+ '-DDBUS_GMAIN_FUNCTION_NAME(name)=' + redefine_function_name,
+ language: 'c',
+)
+
+dbus_gmain = subproject(
+ 'dbus-gmain',
+ default_options: [
+ 'redefine_function_declaration=' + redefine_function_declaration,
+ 'redefine_function_name=' + redefine_function_name,
+ 'tests=false',
+ ],
+)
+dbus_gmain_dep = dbus_gmain.get_variable('dbus_gmain_dep')
+
+executable('use-dbus-gmain', 'use-dbus-gmain.c', dependencies: dbus_gmain_dep)
diff --git a/tests/use-as-subproject/use-dbus-gmain.c b/tests/use-as-subproject/use-dbus-gmain.c
new file mode 100644
index 0000000..21bf8e9
--- /dev/null
+++ b/tests/use-as-subproject/use-dbus-gmain.c
@@ -0,0 +1,14 @@
+/*
+ * Copyright 2022 Collabora Ltd.
+ * SPDX-License-Identifier: MIT
+ */
+
+#include <dbus-gmain/dbus-gmain.h>
+
+int
+main (void)
+{
+ DBusConnection *conn = dbus_bus_get (DBUS_BUS_SESSION, NULL);
+ _my_set_up_connection (conn, NULL);
+ return 0;
+}