main meson.build
  1project('wld', 'c',
  2  version: '0.0',
  3  meson_version: '>=1.1',
  4  license: 'MIT',
  5  default_options: [
  6    # C11: libdrm uses anonymous union extension
  7    # C23: nouveau.c uses empty initializer extension
  8    'c_std=c23',
  9    'warning_level=3',
 10    'default_library=static',
 11    'b_ndebug=if-release',
 12  ],
 13)
 14
 15cc = meson.get_compiler('c')
 16pkg = import('pkgconfig')
 17inc = include_directories('protocol')
 18
 19c_args = cc.get_supported_arguments([
 20  '-fvisibility=hidden',
 21  '-Wvla',
 22  '-Werror=implicit-function-declaration',
 23  '-Werror=implicit-int',
 24  '-Werror=pointer-sign',
 25  '-Werror=pointer-arith',
 26
 27  '-Wno-sign-compare', # pixman.c:630
 28  '-Wno-gnu-empty-struct', # ARRAY_LENGTH
 29  '-Wno-gnu-statement-expression-from-macro-expansion', # CONTAINER_OF
 30  '-Wno-gnu-zero-variadic-macro-arguments', # wld-private.h:57
 31  '-Wno-static-in-inline', # context.c:unwrap_buffer
 32  '-Wno-unused-parameter', # pixman.c
 33  '-Wno-zero-length-array', # libdrm/i915_drm.h:2472
 34  '-Wno-varargs', # nouveau.c:332
 35  '-Wno-excess-initializers', # wayland.c:121
 36  '-I' + meson.current_build_dir(),
 37]) + [
 38  '-D_POSIX_C_SOURCE=200809L', '-D_NETBSD_SOURCE',
 39  get_option('buildtype') == 'debug' ? '-DENABLE_DEBUG=1' : [],
 40]
 41
 42requires = [
 43  dependency('fontconfig'),
 44  dependency('pixman-1'),
 45]
 46requires_private = [
 47  dependency('freetype2'),
 48]
 49
 50libwld_src = files(
 51  'buffer.c',
 52  'buffered_surface.c',
 53  'color.c',
 54  'context.c',
 55  'font.c',
 56  'renderer.c',
 57  'surface.c',
 58  'pixman.c',
 59)
 60
 61wayland = dependency('wayland-client', required: get_option('wayland'))
 62if wayland.found()
 63  libwld_src += ['wayland.c', 'wayland-shm.c']
 64  c_args += '-DWITH_WAYLAND_SHM=1'
 65  requires_private += wayland
 66endif
 67
 68drm = dependency('libdrm', required: get_option('drm'))
 69if drm.found()
 70  libwld_src += ['drm.c', 'dumb.c']  
 71  requires_private += drm
 72
 73  drivers = get_option('drivers')
 74  foreach driver, src : {
 75    'nouveau': ['nouveau.c'],
 76    'intel': ['intel.c', 'intel/batch.c'],
 77  }
 78    if not drivers.contains('auto') and not drivers.contains(driver)
 79      continue
 80    endif
 81    dep = dependency('libdrm_' + driver, required: drivers.contains(driver))
 82    if dep.found()
 83      libwld_src += src
 84      c_args += '-DWITH_DRM_@0@=1'.format(driver)
 85      requires_private += dep
 86    endif
 87  endforeach
 88endif
 89
 90if wayland.found() and drm.found()
 91  libwld_src += 'wayland-drm.c'
 92  c_args += '-DWITH_WAYLAND_DRM=1'
 93
 94  protocols = import('wayland').scan_xml(
 95    files('protocol/wayland-drm.xml'),
 96    public: false,
 97    client: true,
 98  )
 99  libwld_src += [ protocols[0], protocols[1] ]
100endif
101
102install_headers([
103  'wld.h', 'pixman.h',
104  drm.found() ? 'drm.h' : [],
105  wayland.found() ? 'wayland.h' : [],
106], subdir: 'wld')
107
108libwld_lib = library(
109	'wld',
110	libwld_src,
111	dependencies: requires + requires_private,
112	c_args: c_args,
113	include_directories: inc,
114	# Prevents clashing with wld pixman.h
115	implicit_include_directories: false,
116	install: true,
117)
118
119# Allows other meson projects to use libwld
120libwld = declare_dependency(
121	link_with: libwld_lib,
122	dependencies: requires + requires_private,
123)
124
125pkg.generate(
126  libwld_lib,
127  name: 'wld',
128  description: 'A primitive drawing library library targeted at Wayland',
129  requires: requires,
130  requires_private: requires_private,
131)
132
133doxygen = find_program('doxygen', required: get_option('doxygen'))
134if doxygen.found()
135  run_target('doxygen', command: [doxygen])
136endif