[PATCH RFC wayland 4/4] Add initial Meson build system

Daniel Stone daniels at collabora.com
Tue Nov 29 16:59:43 UTC 2016


This is not complete, as it doesn't cover all the tests or docs yet, but
generally gets a good bit of the way there.

Signed-off-by: Daniel Stone <daniels at collabora.com>
---
 meson.build                 | 359 ++++++++++++++++++++++++++++++++++++++++++++
 meson_options.txt           |  15 ++
 src/wayland-version.h.meson |  34 +++++
 3 files changed, 408 insertions(+)
 create mode 100644 meson.build
 create mode 100644 meson_options.txt
 create mode 100644 src/wayland-version.h.meson

diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..ca08adc
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,359 @@
+project('wayland',
+	'c', 'cpp',
+	version: '1.12.90',
+	default_options: [
+		'warning_level=2',
+		'c_std=gnu99',
+	]
+)
+
+pkgconfig = import('pkgconfig')
+
+config_h = configuration_data()
+
+wl_version = meson.project_version()
+version_arr = wl_version.split('.')
+wl_version_h = configuration_data()
+wl_version_h.set('WAYLAND_VERSION_MAJOR', version_arr.get(0))
+wl_version_h.set('WAYLAND_VERSION_MINOR', version_arr.get(1))
+wl_version_h.set('WAYLAND_VERSION_MICRO', version_arr.get(2))
+wl_version_h.set('WAYLAND_VERSION', '"@0@"'.format(meson.project_version()))
+configure_file(input: 'src/wayland-version.h.meson',
+	output: 'wayland-version.h',
+	configuration: wl_version_h)
+
+config_h.set('WAYLAND_VERSION', '"@0@"'.format(meson.project_version()))
+
+cc = meson.get_compiler('c')
+
+add_global_arguments([
+	'-Wno-unused-parameter',
+	'-fvisibility=hidden',
+], language: 'c')
+
+can_run_scanner = false
+if get_option('build_scanner')
+	dep_libxml = dependency('libxml-2.0', required: false)
+	deps_scanner = [
+		dependency('expat'),
+		dep_libxml,
+	]
+
+	if dep_libxml.found()
+		# FIXME: This is lame. The include in dtddata.S means that we
+		# have to land wayland.dtd.embed in the build tree.
+		configure_file(
+			input: 'protocol/wayland.dtd',
+			output: 'wayland.dtd.embed',
+			configuration: configuration_data(),
+		)
+		srcs_scanner_libxml = [
+			'src/dtddata.S'
+		]
+		config_h.set('HAVE_LIBXML', 1)
+	else
+		srcs_scanner_libxml = []
+	endif
+
+	exe_scanner = executable('wayland-scanner',
+		'src/scanner.c',
+		'src/wayland-util.c',
+		srcs_scanner_libxml,
+		install: true,
+		dependencies: deps_scanner)
+
+	# pkg-config file is useless atm:
+	# https://github.com/mesonbuild/meson/issues/1096
+	pkgconfig.generate(
+		filebase: 'wayland-scanner-useless',
+		name: 'Wayland Scanner',
+		description: 'Wayland scanner',
+		version: meson.project_version(),
+	)
+
+	if not meson.is_cross_build()
+		run_scanner = exe_scanner
+		can_run_scanner = true
+
+		prog_scanner_test = find_program('tests/scanner-test.sh')
+		prog_sed = find_program('sed')
+		test('scanner',
+			prog_scanner_test,
+			env: [
+				'WAYLAND_SCANNER=@0@'.format(exe_scanner.full_path()),
+				'TEST_DATA_DIR=@0@/tests/data'.format(meson.current_source_dir()),
+				'TEST_OUTPUT_DIR=@0@/tests/output'.format(meson.current_build_dir()),
+				'srcdir=@0@'.format(meson.current_source_dir()),
+				'SED=@0@'.format(prog_sed.path().get(0)),
+			]
+		)
+	endif
+endif
+
+# If we haven't built the scanner, or are cross-compiling, we need to get a
+# host version of the scanner to generate
+if not can_run_scanner
+	run_scanner = find_program('wayland-scanner')
+endif
+
+gen_scanner_client_proto = generator(run_scanner,
+	output: '@BASENAME at -client-protocol.h',
+	arguments: ['client-header', '@INPUT@', '@OUTPUT@'])
+gen_scanner_client_core = generator(run_scanner,
+	output: '@BASENAME at -client-protocol-core.h',
+	arguments: ['client-header', '-c', '@INPUT@', '@OUTPUT@'])
+gen_scanner_server_proto = generator(run_scanner,
+	output: '@BASENAME at -server-protocol.h',
+	arguments: ['server-header', '@INPUT@', '@OUTPUT@'])
+gen_scanner_server_core = generator(run_scanner,
+	output: '@BASENAME at -server-protocol-core.h',
+	arguments: ['server-header', '-c', '@INPUT@', '@OUTPUT@'])
+gen_scanner_impl = generator(run_scanner,
+	output: '@BASENAME at -protocol.c',
+	arguments: ['code', '@INPUT@', '@OUTPUT@'])
+
+header_server_proto = gen_scanner_server_proto.process('protocol/wayland.xml')
+header_server_core = gen_scanner_server_core.process('protocol/wayland.xml')
+header_client_proto = gen_scanner_client_proto.process('protocol/wayland.xml')
+header_client_core = gen_scanner_client_core.process('protocol/wayland.xml')
+proto_impl = gen_scanner_impl.process('protocol/wayland.xml')
+
+# XXX: This is lame, but until Meson 0.37 (?), we can't install headers
+#      generated by a generator.
+custom_target('wayland-client-protocol.h',
+	input: 'protocol/wayland.xml',
+	output: 'wayland-client-protocol.h',
+	command: [
+		run_scanner,
+		'client-header',
+		'@0@/protocol/wayland.xml'.format(meson.current_source_dir()),
+		'wayland-client-protocol.h',
+	],
+	install: true,
+	install_dir: get_option('includedir'),
+)
+
+custom_target('wayland-server-protocol.h',
+	input: 'protocol/wayland.xml',
+	output: 'wayland-server-protocol.h',
+	command: [
+		run_scanner,
+		'server-header',
+		'@0@/protocol/wayland.xml'.format(meson.current_source_dir()),
+		'wayland-server-protocol.h',
+	],
+	install: true,
+	install_dir: get_option('includedir'),
+)
+
+if get_option('build_libs')
+	deps_libwayland = [
+		dependency('libffi'),
+		dependency('threads')
+	]
+
+	headers_libwayland = [
+		'execinfo.h',
+		'time.h',
+		'sys/signalfd.h',
+		'sys/timerfd.h',
+	]
+	foreach h : headers_libwayland
+		if not cc.has_header(h)
+			error('System header @0@ not found'.format(h))
+		endif
+	endforeach
+
+	tokens_libwayland = [
+		['SFD_CLOEXEC', 'sys/signalfd.h'],
+		['TFD_CLOEXEC', 'sys/timerfd.h'],
+		['CLOCK_MONOTONIC', 'time.h'],
+	]
+	foreach t: tokens_libwayland
+		if not cc.has_header_symbol(t.get(1), t.get(0))
+			error('System symbol @0@ not found in header @1@'.
+			      format(t.get(0), t.get(1)))
+		endif
+	endforeach
+
+	lib_common_src = [
+		'src/connection.c',
+		'src/wayland-os.c',
+		'src/wayland-util.c',
+	]
+	install_headers(
+		'src/wayland-util.h',
+	)
+
+	lib_client = library('wayland-client',
+		'src/wayland-client.c',
+		header_client_core,
+		header_client_proto,
+		proto_impl,
+		lib_common_src,
+		install: true,
+		version: '0.3.0',
+		dependencies: deps_libwayland,
+	)
+	dep_lib_client = declare_dependency(link_with: lib_client)
+	install_headers(
+		'src/wayland-client.h',
+		'src/wayland-client-core.h',
+		'src/wayland-egl.h',
+		'src/wayland-egl-core.h',
+	)
+	pkgconfig.generate(
+		filebase: 'wayland-client',
+		name: 'Wayland Client',
+		description: 'Wayland client sidelibrary',
+		version: meson.project_version(),
+		libraries: lib_client,
+	)
+
+	lib_server = library('wayland-server',
+		'src/wayland-server.c',
+		'src/wayland-shm.c',
+		'src/event-loop.c',
+		header_server_core,
+		header_server_proto,
+		proto_impl,
+		lib_common_src,
+		install: true,
+		version: '0.1.0',
+		dependencies: deps_libwayland,
+	)
+	dep_lib_server = declare_dependency(link_with: lib_server)
+	install_headers(
+		'src/wayland-server.h',
+		'src/wayland-server-core.h',
+	)
+	pkgconfig.generate(
+		filebase: 'wayland-server',
+		name: 'Wayland Server',
+		description: 'Wayland server sidelibrary',
+		version: meson.project_version(),
+		libraries: lib_server,
+	)
+
+	lib_cursor = shared_library('wayland-cursor',
+		'cursor/wayland-cursor.c',
+		'cursor/os-compatibility.c',
+		'cursor/xcursor.c',
+		c_args: '-DICONDIR="@0@/icons"'.format(get_option('prefix')),
+		install: true,
+		version: '0.0.0',
+		dependencies: dep_lib_client,
+	)
+	install_headers(
+		'cursor/wayland-cursor.h',
+	)
+	pkgconfig.generate(
+		filebase: 'wayland-cursor',
+		name: 'Wayland Cursor',
+		description: 'Wayland cursor helper library',
+		version: meson.project_version(),
+		libraries: lib_cursor,
+	)
+endif
+
+if get_option('build_docs')
+	prog_doxy = find_program('doxygen')
+	prog_xsltproc = find_program('xsltproc')
+	prog_xmlto = find_program('xmlto')
+	prog_dot = find_program('dot')
+
+	r = run_command(prog_doxy, '-v')
+	if r.returncode() != 0
+		error('Could not run Doxygen to test version')
+	endif
+	if not r.stdout().strip().version_compare('>=1.6.0')
+		error('Doxygen is too old; must be at least version 1.6.0')
+	endif
+
+	r = run_command(prog_dot, '-V')
+	if r.returncode() != 0
+		error('Could not run dot to test Graphviz version')
+	endif
+	if not r.stderr().split().get(4).version_compare('>=2.28.0')
+		error('Graphviz is too old; must be at least version 2.28.0')
+	endif
+
+	# FIXME: docs are still TODO
+endif
+
+dep_tests = declare_dependency(
+	sources: [
+		'tests/test-runner.c',
+		'tests/test-helpers.c',
+		'tests/test-compositor.c',
+		'src/wayland-util.c', # interface-test uses hidden syms from here
+		'src/connection.c', # message-test uses hidden syms from here
+		'src/wayland-os.c',
+	],
+	dependencies: [
+		dep_lib_client,
+		dep_lib_server,
+		dependency('libffi'), # connection-test uses this directly
+		cc.find_library('dl'),
+		dependency('threads'),
+	]
+)
+
+wl_tests = [
+	'array',
+	'client',
+	'compositor-introspection',
+	'connection',
+	'display',
+	'event-loop',
+	'fixed',
+	'interface',
+	'list',
+	'map',
+	'message',
+	'os-wrappers',
+	'queue',
+	'protocol-logger',
+	'resources',
+	'sanity',
+	'signal',
+	'socket',
+]
+
+# exec-fd-leak-checker isn't actually a test, but an external helper
+# binary.
+executable('exec-fd-leak-checker',
+	   'tests/exec-fd-leak-checker.c',
+	   'tests/test-helpers.c',
+)
+
+# These two tests _are_ real tests, but don't use test-runner; they are
+# just compilation tests.
+exe_test_headers = executable('test-headers',
+	'tests/headers-test.c',
+	'tests/headers-protocol-test.c',
+	'tests/headers-protocol-core-test.c',
+	header_server_core,
+	header_server_proto,
+	header_client_core,
+	header_client_proto
+)
+test('headers', exe_test_headers)
+
+exe_test_cpp_compile = executable('test-cpp-compile',
+	'tests/cpp-compile-test.cpp'
+)
+test('cpp-compile', exe_test_cpp_compile)
+
+foreach t : wl_tests
+	exe_test = executable('test- at 0@'.format(t),
+		'tests/@0 at -test.c'.format(t),
+		include_directories: include_directories('src'),
+		dependencies: dep_tests
+	)
+	test(t, exe_test)
+endforeach
+
+configure_file(output: 'config.h',
+	configuration: config_h
+)
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..372149e
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,15 @@
+option('build_libs',
+       type: 'boolean',
+       value: true,
+       description: 'Build libwayland-client and libwayland-server')
+
+# XXX: Default based on cross-build
+option('build_scanner',
+       type: 'boolean',
+       value: true,
+       description: 'Build wayland-scanner code generator (requires Expat)')
+
+option('build_docs',
+       type: 'boolean',
+       value: true,
+       description: 'Build documentation (requires Doxygen, xmlto, Graphviz)')
diff --git a/src/wayland-version.h.meson b/src/wayland-version.h.meson
new file mode 100644
index 0000000..70123b2
--- /dev/null
+++ b/src/wayland-version.h.meson
@@ -0,0 +1,34 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef WAYLAND_VERSION_H
+#define WAYLAND_VERSION_H
+
+#mesondefine WAYLAND_VERSION_MAJOR
+#mesondefine WAYLAND_VERSION_MINOR
+#mesondefine WAYLAND_VERSION_MICRO
+#mesondefine WAYLAND_VERSION
+
+#endif
-- 
2.9.3



More information about the wayland-devel mailing list