From ed5099f54173a885b85e81bcf950f5fc1ba2ba2c Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Wed, 2 Mar 2022 11:36:44 +0900 Subject: [PATCH] Add build options of backends Change-Id: I344dd28196280c91f4c3fa064bc60f5a439b3fa2 --- examples/meson.build | 34 ++++++++++++++++++---------------- include/meson.build | 12 +++++++++++- meson.build | 12 +++++------- meson_options.txt | 1 + src/libds/{allocator => }/allocator.c | 0 src/libds/allocator/meson.build | 12 ++++++++++++ src/libds/backend/meson.build | 15 ++++++++++++++- src/libds/backend/tdm/meson.build | 26 +++++++++++++++++++++++++- src/libds/meson.build | 21 +++++++++++++++++---- 9 files changed, 103 insertions(+), 30 deletions(-) create mode 100644 meson_options.txt rename src/libds/{allocator => }/allocator.c (100%) create mode 100644 src/libds/allocator/meson.build diff --git a/examples/meson.build b/examples/meson.build index 54f1ba7..66336f5 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -9,12 +9,6 @@ executable('wl-backend', install_dir: libds_bindir, install : true) -executable('tdm-backend', - 'tdm-backend.c', - dependencies: common_deps, - install_dir: libds_bindir, - install : true) - executable('tinyds', 'tinyds.c', dependencies: [ @@ -25,13 +19,21 @@ executable('tinyds', install_dir: libds_bindir, install : true) -executable('tinyds-tdm', - ['tinyds-tdm.c', 'tinyds-helper.c'], - dependencies: [ - common_deps, - dependency('pixman-1', required: true), - dependency('libdrm', required: true), - dependency('libtbm', required: true), - ], - install_dir: libds_bindir, - install : true) +if features.get('tdm-backend') + executable('tdm-backend', + 'tdm-backend.c', + dependencies: common_deps, + install_dir: libds_bindir, + install : true) + + executable('tinyds-tdm', + ['tinyds-tdm.c', 'tinyds-helper.c'], + dependencies: [ + common_deps, + dependency('pixman-1', required: true), + dependency('libdrm', required: true), + dependency('libtbm', required: true), + ], + install_dir: libds_bindir, + install : true) +endif diff --git a/include/meson.build b/include/meson.build index 731f7d3..f273424 100644 --- a/include/meson.build +++ b/include/meson.build @@ -1,3 +1,13 @@ +exclude_files = [] +if not features.get('tdm-backend') + exclude_files += 'backend/tdm.h' +endif + +if not features.get('tbm-allocator') + exclude_files += 'allocator/tbm.h' +endif + install_subdir('libds', - install_dir: get_option('includedir') + install_dir: get_option('includedir'), + exclude_files: exclude_files, ) diff --git a/meson.build b/meson.build index 36bfda9..2bf1398 100644 --- a/meson.build +++ b/meson.build @@ -25,6 +25,10 @@ cdata.set('LIBDS_VERSION_MAJOR', libds_version_major) cdata.set('LIBDS_VERSION_MINOR', libds_version_minor) cdata.set('LIBDS_VERSION_PATCH', libds_version_patch) +features = { + 'tdm-backend': false, + 'tbm-allocator': false, +} subdir('include') subdir('src') @@ -32,10 +36,4 @@ subdir('examples') configure_file(output: 'config.h', install: false, configuration: cdata) -pkgconfig = import('pkgconfig') -pkgconfig.generate(lib_libds, - version: meson.project_version(), - filebase: meson.project_name(), - name: meson.project_name(), - description: 'Wayland compositor library', -) +summary(features, bool_yn: true) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..02af9b0 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1 @@ +option('backends', type: 'array', choices: ['auto', 'tdm'], value: ['auto'], description: 'Select built-in backends') diff --git a/src/libds/allocator/allocator.c b/src/libds/allocator.c similarity index 100% rename from src/libds/allocator/allocator.c rename to src/libds/allocator.c diff --git a/src/libds/allocator/meson.build b/src/libds/allocator/meson.build new file mode 100644 index 0000000..361f96e --- /dev/null +++ b/src/libds/allocator/meson.build @@ -0,0 +1,12 @@ +libds_files += files('shm.c') + +libtbm = dependency( + 'libtbm', + required: false, + not_found_message: 'Required for TBM allocator support.' +) +if libtbm.found() + libds_files += files('tbm.c') + libds_deps += libtbm + features += { 'tbm-allocator': true } +endif diff --git a/src/libds/backend/meson.build b/src/libds/backend/meson.build index c24f074..b1fff87 100644 --- a/src/libds/backend/meson.build +++ b/src/libds/backend/meson.build @@ -1,2 +1,15 @@ +all_backends = ['tdm'] +backends = get_option('backends') +if 'auto' in backends and get_option('auto_features').enabled() + backends = all_backends +elif 'auto' in backends and get_option('auto_features').disabled() + backends = [] +endif + +foreach backend : all_backends + if backend in backends or 'auto' in backends + subdir(backend) + endif +endforeach + subdir('wayland') -subdir('tdm') diff --git a/src/libds/backend/tdm/meson.build b/src/libds/backend/tdm/meson.build index 9a0b041..82eb165 100644 --- a/src/libds/backend/tdm/meson.build +++ b/src/libds/backend/tdm/meson.build @@ -1,8 +1,32 @@ +msg = ['Required for TDM backend support.'] +if 'tdm' in backends + msg += 'Install "libtdm" and "libtbm", or disable the tdm backend' +endif + +libtdm = dependency( + 'libtdm', + required: 'tdm' in backends, + not_found_message: '\n'.join(msg) +) + +libtbm = dependency( + 'libtbm', + required: 'tdm' in backends, + not_found_message: '\n'.join(msg) +) + +if not libtdm.found() or not libtbm.found() + subdir_done() +endif + libds_files += files( 'backend.c', 'output.c', ) libds_deps += [ - dependency('libtdm', required: true), + libtdm, + libtbm ] + +features += { 'tdm-backend': true } diff --git a/src/libds/meson.build b/src/libds/meson.build index e7f2970..ed8c95f 100644 --- a/src/libds/meson.build +++ b/src/libds/meson.build @@ -2,9 +2,7 @@ libds_files = [ 'log.c', 'addon.c', 'buffer.c', - 'allocator/allocator.c', - 'allocator/shm.c', - 'allocator/tbm.c', + 'allocator.c', 'swapchain.c', 'output.c', 'compositor.c', @@ -52,7 +50,6 @@ math = meson.get_compiler('c').find_library('m') wayland_server = dependency('wayland-server', required: true) pixman = dependency('pixman-1', required: true) libdrm = dependency('libdrm', required: true) -libtbm = dependency('libtbm', required: true) libds_deps = [ math, @@ -62,6 +59,7 @@ libds_deps = [ ] subdir('backend') +subdir('allocator') lib_libds = shared_library('ds', libds_files, dependencies: libds_deps, @@ -70,8 +68,23 @@ lib_libds = shared_library('ds', libds_files, install: true ) +ds_vars = {} +foreach name, have : features + ds_vars += { 'have_' + name.underscorify(): have.to_string() } +endforeach + dep_libds = declare_dependency( link_with: lib_libds, dependencies: libds_deps, include_directories: [ common_inc, include_directories('.') ], + variables: ds_vars, +) + +pkgconfig = import('pkgconfig') +pkgconfig.generate(lib_libds, + version: meson.project_version(), + filebase: meson.project_name(), + name: meson.project_name(), + description: 'Wayland compositor library', + variables: ds_vars, ) -- 2.7.4