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 [moved from src/libds/allocator/allocator.c with 100% similarity]
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 54f1ba7..66336f5 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 731f7d3..f273424 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 36bfda9..2bf1398 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/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 c24f074..b1fff87 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 9a0b041..82eb165 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 e7f2970..ed8c95f 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,
 )