Add build options of backends 36/278136/1
authorSeunghun Lee <shiin.lee@samsung.com>
Wed, 2 Mar 2022 02:36:44 +0000 (11:36 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 18 Jul 2022 05:58:08 +0000 (14:58 +0900)
Change-Id: I344dd28196280c91f4c3fa064bc60f5a439b3fa2

examples/meson.build
include/meson.build
meson.build
meson_options.txt [new file with mode: 0644]
src/libds/allocator.c [new file with mode: 0644]
src/libds/allocator/allocator.c [deleted file]
src/libds/allocator/meson.build [new file with mode: 0644]
src/libds/backend/meson.build
src/libds/backend/tdm/meson.build
src/libds/meson.build

index 54f1ba7914cc78c9d4cabcc13f31f140fc758335..66336f5705197dd662bf2d655448927377c19ae3 100644 (file)
@@ -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
index 731f7d3a2977f010166607373ff4a439ddc4e449..f273424348e496145c3af936738a5d9b399d5732 100644 (file)
@@ -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,
 )
index 36bfda9be720201af6dc8ad4c23e07076d91e426..2bf1398c73399f9be9f5fc59140aa63793375326 100644 (file)
@@ -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 (file)
index 0000000..02af9b0
--- /dev/null
@@ -0,0 +1 @@
+option('backends', type: 'array', choices: ['auto', 'tdm'], value: ['auto'], description: 'Select built-in backends')
diff --git a/src/libds/allocator.c b/src/libds/allocator.c
new file mode 100644 (file)
index 0000000..34c0aa7
--- /dev/null
@@ -0,0 +1,37 @@
+#include <assert.h>
+#include <stdlib.h>
+#include <wayland-server.h>
+
+#include "libds/log.h"
+#include "libds/interfaces/allocator.h"
+
+WL_EXPORT void
+ds_allocator_init(struct ds_allocator *alloc,
+        const struct ds_allocator_interface *iface, uint32_t buffer_caps)
+{
+    alloc->iface = iface;
+    alloc->buffer_caps = buffer_caps;
+
+    wl_signal_init(&alloc->events.destroy);
+}
+
+WL_EXPORT void
+ds_allocator_destroy(struct ds_allocator *alloc)
+{
+    wl_signal_emit(&alloc->events.destroy, NULL);
+    alloc->iface->destroy(alloc);
+}
+
+WL_EXPORT struct ds_buffer *
+ds_allocator_create_buffer(struct ds_allocator *alloc, int width, int height,
+        uint32_t format)
+{
+    return alloc->iface->create_buffer(alloc, width, height, format);
+}
+
+WL_EXPORT void
+ds_allocator_add_destroy_listener(struct ds_allocator *alloc,
+        struct wl_listener *listener)
+{
+    wl_signal_add(&alloc->events.destroy, listener);
+}
diff --git a/src/libds/allocator/allocator.c b/src/libds/allocator/allocator.c
deleted file mode 100644 (file)
index 34c0aa7..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <assert.h>
-#include <stdlib.h>
-#include <wayland-server.h>
-
-#include "libds/log.h"
-#include "libds/interfaces/allocator.h"
-
-WL_EXPORT void
-ds_allocator_init(struct ds_allocator *alloc,
-        const struct ds_allocator_interface *iface, uint32_t buffer_caps)
-{
-    alloc->iface = iface;
-    alloc->buffer_caps = buffer_caps;
-
-    wl_signal_init(&alloc->events.destroy);
-}
-
-WL_EXPORT void
-ds_allocator_destroy(struct ds_allocator *alloc)
-{
-    wl_signal_emit(&alloc->events.destroy, NULL);
-    alloc->iface->destroy(alloc);
-}
-
-WL_EXPORT struct ds_buffer *
-ds_allocator_create_buffer(struct ds_allocator *alloc, int width, int height,
-        uint32_t format)
-{
-    return alloc->iface->create_buffer(alloc, width, height, format);
-}
-
-WL_EXPORT void
-ds_allocator_add_destroy_listener(struct ds_allocator *alloc,
-        struct wl_listener *listener)
-{
-    wl_signal_add(&alloc->events.destroy, listener);
-}
diff --git a/src/libds/allocator/meson.build b/src/libds/allocator/meson.build
new file mode 100644 (file)
index 0000000..361f96e
--- /dev/null
@@ -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
index c24f0748afc68166cb2b187a054b694e44a42c77..b1fff87b6ce0970b5eb99e7d18f1e347db1e79b3 100644 (file)
@@ -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')
index 9a0b0413520e6fb0630e3e506922ddde741caeeb..82eb16597f1c64f92a51761c6f3eec3424a16ec8 100644 (file)
@@ -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 }
index e7f2970cb94406108008fbf52b401df92997e212..ed8c95f9c65ad1e946e95060a4cfaa5dfbac2f0f 100644 (file)
@@ -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,
 )