gfxstream: add meson build

Right now, gfxstream downloads dependencies it needs via CMake
`FetchContent`, and that's generally in-advisable when writing
a package for distribution.

The CMake build also exports libraries and symbols that ideally
should be kept internal to gfxstream (like opengles.cpp symbols).
This is due to AEMU CMake compatibility, but even upstream
QEMU has moved to a meson based system. Meson should work well
on Unix systems, and Windows the standard strategy is to use a
mingw cross-compiler.

This allows gfxstream to be a completely external and versioned
dependency.

Note, tests were not compiled and only Linux has been tested so
far.  Also, meson configure -Ddecoders=auto is recommended until
decoder specific code can be further isolated.

BUG=284306280
TEST=Compile using the following options:

(Linux dependencies)
sudo apt-get install libdrm
sudo apt-get install libglm-dev
sudo apt-get install libstb-dev

mkdir aemu-build
(in platform/hardware/google/aemu)
cmake -DAEMU_COMMON_GEN_PKGCONFIG=ON -DAEMU_COMMON_BUILD_CONFIG=gfxstream
      -DENABLE_VKCEREAL_TESTS=OFF . ../
make -j && sudo make install

(in gfxstream)
mkdir amd64-build
meson -Ddefault_library=static amd64-build/
ninja -C amd64-build
sudo ninja -C amd64-build/ install

Change-Id: I1722d84e4810ec5e3377797b6951cef4209c278e
diff --git a/gl-host-common/meson.build b/gl-host-common/meson.build
new file mode 100644
index 0000000..d606454
--- /dev/null
+++ b/gl-host-common/meson.build
@@ -0,0 +1,46 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+files_lib_gl_host_common = files(
+  'opengles.cpp',
+  'opengl/EmuglBackendList.cpp',
+  'opengl/emugl_config.cpp',
+  'opengl/GLProcessPipe.cpp',
+  'opengl/GpuFrameBridge.cpp',
+  'opengl/gpuinfo.cpp',
+  'opengl/logger.cpp',
+  'opengl/misc.cpp',
+  'opengl/OpenglEsPipe.cpp',
+)
+
+files_gl_host_common_darwin = files(
+  'opengl/macTouchOpenGL.m',
+  'opengl/NativeGpuInfo_darwin.cpp',
+)
+
+files_gl_host_common_win32 = files(
+  'opengl/NativeGpuInfo_windows.cpp',
+)
+
+files_gl_host_common_linux = files(
+  'opengl/NativeGpuInfo_linux.cpp',
+)
+
+# HACK: For the misc.h file already in AEMU host common
+inc_gl_host_common = include_directories('include')
+
+if host_machine.system() == 'darwin'
+  files_lib_gl_host_common += files_gl_host_common_darwin
+elif host_machine.system() == 'windows'
+  files_lib_gl_host_common += files_gl_host_common_win32
+elif host_machine.system() == 'linux'
+  files_lib_gl_host_common += files_gl_host_common_linux
+endif
+
+lib_gl_host_common = static_library(
+  'gl_host_common',
+  files_lib_gl_host_common,
+  cpp_args: default_cpp_args,
+  include_directories: [inc_include, inc_gl_host_common],
+  dependencies: [aemu_base_dep, aemu_common_dep]
+)
diff --git a/host/apigen-codec-common/meson.build b/host/apigen-codec-common/meson.build
new file mode 100644
index 0000000..b5a6e8e
--- /dev/null
+++ b/host/apigen-codec-common/meson.build
@@ -0,0 +1,21 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+inc_apigen_codec = include_directories('.')
+
+files_lib_apigen_codec = files(
+  'ChecksumCalculator.cpp',
+  'ChecksumCalculatorThreadInfo.cpp',
+  'glUtils.cpp',
+)
+
+if host_machine.system() == 'linux'
+  files_lib_apigen_codec += files('X11Support.cpp')
+endif
+
+lib_apigen_codec = static_library(
+  'apigen_codec',
+  files_lib_apigen_codec,
+  cpp_args: default_cpp_args,
+  dependencies: aemu_base_dep,
+)
diff --git a/host/compressedTextureFormats/meson.build b/host/compressedTextureFormats/meson.build
new file mode 100644
index 0000000..fbf912a
--- /dev/null
+++ b/host/compressedTextureFormats/meson.build
@@ -0,0 +1,12 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+files_lib_compressed_textures = files(
+  'etc.cpp',
+  'AstcCpuDecompressorNoOp.cpp',
+)
+
+lib_compressed_textures = static_library(
+  'compressed_textures',
+  files_lib_compressed_textures,
+)
diff --git a/host/gl/OpenGLESDispatch/meson.build b/host/gl/OpenGLESDispatch/meson.build
new file mode 100644
index 0000000..217f2d7
--- /dev/null
+++ b/host/gl/OpenGLESDispatch/meson.build
@@ -0,0 +1,20 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+files_lib_gl_dispatch = files(
+  'EGLDispatch.cpp',
+  'gles1_stubbed_in_translator_namespace.cpp',
+  'gles2_stubbed_in_translator_namespace.cpp',
+  'GLESv1Dispatch.cpp',
+  'GLESv2Dispatch.cpp',
+  'OpenGLDispatchLoader.cpp',
+  'StaticDispatch.cpp',
+)
+
+lib_gl_dispatch = static_library(
+  'gl_dispatch',
+  files_lib_gl_dispatch,
+  include_directories: inc_include,
+  cpp_args: '-fvisibility=default',
+  link_with: [lib_egl_translator, lib_glescm_translator, lib_glesv2_translator]
+)
diff --git a/host/gl/gles1_dec/meson.build b/host/gl/gles1_dec/meson.build
new file mode 100644
index 0000000..1a92654
--- /dev/null
+++ b/host/gl/gles1_dec/meson.build
@@ -0,0 +1,15 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+files_lib_gles1_dec = files(
+  'gles1_dec.cpp',
+  'gles1_server_context.cpp',
+  'GLESv1Decoder.cpp',
+)
+
+lib_gles1_dec = static_library(
+  'gles1_dec',
+  files_lib_gles1_dec,
+  cpp_args: default_cpp_args,
+  include_directories: [inc_include, inc_apigen_codec, inc_gles_translator]
+)
diff --git a/host/gl/gles2_dec/meson.build b/host/gl/gles2_dec/meson.build
new file mode 100644
index 0000000..11f4dd8
--- /dev/null
+++ b/host/gl/gles2_dec/meson.build
@@ -0,0 +1,17 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+files_lib_gles2_dec = files(
+  'gles2_dec.cpp',
+  'gles2_server_context.cpp',
+  'GLESv2Decoder.cpp',
+)
+
+lib_gles2_dec = static_library(
+  'gles2_dec',
+  files_lib_gles2_dec,
+  cpp_args: default_cpp_args,
+  include_directories: [inc_include, inc_apigen_codec, inc_gles_translator,
+                        inc_gl_snapshot],
+  link_with: lib_gl_snapshot,
+)
diff --git a/host/gl/glestranslator/EGL/meson.build b/host/gl/glestranslator/EGL/meson.build
new file mode 100644
index 0000000..5bee348
--- /dev/null
+++ b/host/gl/glestranslator/EGL/meson.build
@@ -0,0 +1,59 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+files_lib_egl_translator = files(
+  'ClientAPIExts.cpp',
+  'EglConfig.cpp',
+  'EglContext.cpp',
+  'EglDisplay.cpp',
+  'EglGlobalInfo.cpp',
+  'EglImp.cpp',
+  'EglPbufferSurface.cpp',
+  'EglSurface.cpp',
+  'EglThreadInfo.cpp',
+  'EglValidate.cpp',
+  'EglWindowSurface.cpp',
+  'ShaderCache.cpp',
+  'ThreadInfo.cpp',
+  'EglOsApi_egl.cpp',
+)
+
+files_egl_darwin = files(
+  'EglOsApi_darwin.cpp',
+  'MacNative.m',
+  'MacPixelFormatsAttribs.m',
+)
+
+files_egl_win32 = files(
+  'CoreProfileConfigs_windows.cpp',
+  'EglOsApi_wgl.cpp',
+)
+
+files_egl_linux = files(
+  'CoreProfileConfigs_linux.cpp',
+  'EglOsApi_glx.cpp',
+  'X11ErrorHandler.cpp',
+)
+
+egl_cpp_args = [
+  '-fvisibility=hidden',
+  '-Wno-inconsistent-missing-override',
+]
+
+if host_machine.system() == 'darwin'
+  files_lib_egl_translator += files_egl_darwin
+elif host_machine.system() == 'windows'
+  files_lib_egl_translator += files_egl_win32
+elif host_machine.system() == 'linux'
+  files_lib_egl_translator += files_egl_linux
+endif
+
+lib_egl_translator = static_library(
+  'egl_translator',
+  files_lib_egl_translator,
+  cpp_args: egl_cpp_args,
+  include_directories: [inc_include, inc_gles_translator, inc_apigen_codec,
+                        inc_gl_host_common, inc_stream_servers],
+  link_with: [lib_gl_common, lib_apigen_codec, lib_gl_host_common],
+  dependencies: [aemu_base_dep, aemu_common_dep, logging_base_dep]
+)
diff --git a/host/gl/glestranslator/GLES_CM/meson.build b/host/gl/glestranslator/GLES_CM/meson.build
new file mode 100644
index 0000000..5607c1c
--- /dev/null
+++ b/host/gl/glestranslator/GLES_CM/meson.build
@@ -0,0 +1,17 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+files_lib_glescm_translator = files(
+  'CoreProfileEngine.cpp',
+  'GLEScmContext.cpp',
+  'GLEScmImp.cpp',
+  'GLEScmUtils.cpp',
+  'GLEScmValidate.cpp',
+)
+
+lib_glescm_translator = static_library(
+  'glescm_translator',
+  files_lib_glescm_translator,
+  cpp_args: default_cpp_args,
+  include_directories: [inc_include, inc_gles_translator],
+)
diff --git a/host/gl/glestranslator/GLES_V2/meson.build b/host/gl/glestranslator/GLES_V2/meson.build
new file mode 100644
index 0000000..b4bf2a0
--- /dev/null
+++ b/host/gl/glestranslator/GLES_V2/meson.build
@@ -0,0 +1,21 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+files_lib_glesv2_translator = files(
+  'ANGLEShaderParser.cpp',
+  'GLESv2Context.cpp',
+  'GLESv2Imp.cpp',
+  'GLESv2Validate.cpp',
+  'ProgramData.cpp',
+  'SamplerData.cpp',
+  'ShaderParser.cpp',
+  'ShaderValidator.cpp',
+  'TransformFeedbackData.cpp',
+)
+
+lib_glesv2_translator = static_library(
+  'glesv2_translator',
+  files_lib_glesv2_translator,
+  cpp_args: default_cpp_args,
+  include_directories: [inc_include, inc_gles_translator, inc_stream_servers]
+)
diff --git a/host/gl/glestranslator/GLcommon/meson.build b/host/gl/glestranslator/GLcommon/meson.build
new file mode 100644
index 0000000..6de5661
--- /dev/null
+++ b/host/gl/glestranslator/GLcommon/meson.build
@@ -0,0 +1,33 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+files_lib_gl_common = files(
+  'etc.cpp',
+  'rgtc.cpp',
+  'FramebufferData.cpp',
+  'GLBackgroundLoader.cpp',
+  'GLDispatch.cpp',
+  'GLESbuffer.cpp',
+  'GLEScontext.cpp',
+  'GLESpointer.cpp',
+  'GLESvalidate.cpp',
+  'GLutils.cpp',
+  'NamedObject.cpp',
+  'ObjectData.cpp',
+  'ObjectNameSpace.cpp',
+  'PaletteTexture.cpp',
+  'RangeManip.cpp',
+  'SaveableTexture.cpp',
+  'ScopedGLState.cpp',
+  'ShareGroup.cpp',
+  'TextureData.cpp',
+  'TextureUtils.cpp',
+)
+
+lib_gl_common = static_library(
+  'gl_common',
+  files_lib_gl_common,
+  cpp_args: default_cpp_args,
+  include_directories: [inc_include, inc_stream_servers, inc_gles_translator],
+  link_with: lib_compressed_textures,
+)
diff --git a/host/gl/glestranslator/meson.build b/host/gl/glestranslator/meson.build
new file mode 100644
index 0000000..87e99b5
--- /dev/null
+++ b/host/gl/glestranslator/meson.build
@@ -0,0 +1,7 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+subdir('GLcommon')
+subdir('GLES_V2')
+subdir('GLES_CM')
+subdir('EGL')
diff --git a/host/gl/glsnapshot/meson.build b/host/gl/glsnapshot/meson.build
new file mode 100644
index 0000000..d6bd9be
--- /dev/null
+++ b/host/gl/glsnapshot/meson.build
@@ -0,0 +1,13 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+files_lib_gl_snapshot = files(
+  'GLSnapshot.cpp',
+)
+
+lib_gl_snapshot = static_library(
+  'gl_snapshot',
+  files_lib_gl_snapshot,
+  cpp_args: default_cpp_args,
+  include_directories: inc_include
+)
diff --git a/host/gl/meson.build b/host/gl/meson.build
new file mode 100644
index 0000000..df91bf7
--- /dev/null
+++ b/host/gl/meson.build
@@ -0,0 +1,49 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+inc_gl_server = include_directories('.')
+inc_gles_translator = include_directories('glestranslator/include')
+inc_gl_snapshot = include_directories('glsnapshot')
+
+# snapshot
+subdir('glsnapshot')
+
+# GLES decoder
+subdir('gles1_dec')
+subdir('gles2_dec')
+
+# GLES translator
+subdir('glestranslator')
+
+# GLES dispatch based on Translator
+subdir('OpenGLESDispatch')
+
+files_lib_gl_server = files(
+  'BufferGl.cpp',
+  'ColorBufferGl.cpp',
+  'CompositorGl.cpp',
+  'DebugGl.cpp',
+  'DisplayGl.cpp',
+  'DisplaySurfaceGl.cpp',
+  'EmulatedEglConfig.cpp',
+  'EmulatedEglContext.cpp',
+  'EmulatedEglFenceSync.cpp',
+  'EmulatedEglImage.cpp',
+  'EmulatedEglWindowSurface.cpp',
+  'EmulationGl.cpp',
+  'GLESVersionDetector.cpp',
+  'ReadbackWorkerGl.cpp',
+  'TextureDraw.cpp',
+  'TextureResize.cpp',
+  'YUVConverter.cpp',
+)
+
+lib_gl_server = static_library(
+  'gl_server',
+  files_lib_gl_server,
+  cpp_args: default_cpp_args,
+  include_directories: [inc_include, inc_stream_servers, inc_apigen_codec,
+                        inc_gl_snapshot, inc_gl_host_common],
+  link_with: [lib_gles1_dec, lib_gles2_dec, lib_apigen_codec, lib_gl_dispatch,
+              lib_apigen_codec],
+)
diff --git a/host/magma/magma_dec/meson.build b/host/magma/magma_dec/meson.build
new file mode 100644
index 0000000..0ede4eb
--- /dev/null
+++ b/host/magma/magma_dec/meson.build
@@ -0,0 +1,16 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+inc_magma_dec = include_directories('.')
+
+files_lib_magma_dec = files(
+  'magma_dec.cpp',
+  'magma_server_context.cpp',
+)
+
+lib_magma_dec = static_library(
+  'magma_dec',
+  files_lib_magma_dec,
+  cpp_args: default_cpp_args,
+  include_directories: [inc_include, inc_magma_external, inc_apigen_codec],
+)
diff --git a/host/magma/meson.build b/host/magma/meson.build
new file mode 100644
index 0000000..481c82b
--- /dev/null
+++ b/host/magma/meson.build
@@ -0,0 +1,25 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+subdir('magma_dec')
+
+files_lib_magma_server = files(
+  'Decoder.cpp',
+  'IntelDrmDecoder.cpp',
+  'DrmDevice.cpp',
+)
+
+magma_server_cpp_args = [
+  '-DGFXSTREAM_MAGMA_USE_INTEL_DRM=1',
+]
+
+lib_magma_server = static_library(
+  'magma_server',
+  files_lib_magma_server,
+  cpp_args: default_cpp_args + magma_server_cpp_args,
+  include_directories: [inc_root, inc_include, inc_magma_external,
+                        inc_magma_external_lib, inc_apigen_codec, inc_magma_dec,
+                        inc_stream_servers],
+  dependencies: drm_dep,
+  link_with: [lib_magma_dec, lib_apigen_codec],
+)
diff --git a/host/meson.build b/host/meson.build
new file mode 100644
index 0000000..dc6f338
--- /dev/null
+++ b/host/meson.build
@@ -0,0 +1,105 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+inc_stream_servers = include_directories('.')
+
+subdir('apigen-codec-common')
+
+inc_gfxstream_backend = [inc_root, inc_include, inc_apigen_codec, inc_utils,
+                         inc_gl_host_common]
+
+link_gfxstream_backend = [lib_gl_host_common]
+
+files_lib_gfxstream_backend = files(
+  'Buffer.cpp',
+  'BlobManager.cpp',
+  'ChannelStream.cpp',
+  'ColorBuffer.cpp',
+  'DisplaySurface.cpp',
+  'DisplaySurfaceUser.cpp',
+  'Hwc2.cpp',
+  'PostWorker.cpp',
+  'ReadBuffer.cpp',
+  'render_api.cpp',
+  'RenderChannelImpl.cpp',
+  'RenderThread.cpp',
+  'RenderThreadInfo.cpp',
+  'RingStream.cpp',
+  'SyncThread.cpp',
+  'RenderControl.cpp',
+  'RenderWindow.cpp',
+  'RenderLibImpl.cpp',
+  'RendererImpl.cpp',
+  'FrameBuffer.cpp',
+  'GfxStreamAgents.cpp',
+  'virtio-gpu-gfxstream-renderer.cpp',
+  'VirtioGpuTimelines.cpp',
+  'VsyncThread.cpp',
+)
+
+if use_gles or use_vulkan
+  subdir('compressedTextureFormats')
+endif
+
+if use_gles
+  subdir('gl')
+
+  files_lib_gfxstream_backend += files('PostWorkerGl.cpp')
+  files_lib_gfxstream_backend += files('RenderThreadInfoGl.cpp')
+
+  inc_gfxstream_backend += [inc_gl_server, inc_gl_snapshot, inc_gles_translator]
+  link_gfxstream_backend += lib_gl_server
+endif
+
+if use_vulkan
+  subdir('vulkan')
+  inc_gfxstream_backend += [inc_vulkan_server, inc_renderdoc_external]
+  link_gfxstream_backend += lib_vulkan_server
+endif
+
+if use_composer
+  subdir('renderControl_dec')
+  link_gfxstream_backend += lib_composer
+endif
+
+if use_magma
+  subdir('magma')
+  files_lib_gfxstream_backend += files('RenderThreadInfoMagma.cpp')
+  inc_gfxstream_backend += [inc_magma_dec, inc_magma_external]
+  link_gfxstream_backend += lib_magma_server
+endif
+
+if host_machine.system() == 'darwin'
+  files_lib_gfxstream_backend += files('NativeSubWindow_cocoa.m')
+elif host_machine.system() == 'windows'
+  files_lib_gfxstream_backend += files('NativeSubWindow_win32.cpp')
+elif host_machine.system() == 'linux'
+  files_lib_gfxstream_backend += files('NativeSubWindow_x11.cpp')
+endif
+
+gfxstream_backend_cpp_args = [
+  '-Wno-unused-parameter',
+  '-Wno-unused-variable',
+  '-Wno-unused-function',
+  '-DVK_GFXSTREAM_STRUCTURE_TYPE_EXT',
+]
+
+gfxstream_backend = library(
+  'gfxstream_backend',
+  files_lib_gfxstream_backend,
+  cpp_args: default_cpp_args + gfxstream_backend_cpp_args,
+  include_directories: inc_gfxstream_backend,
+  gnu_symbol_visibility: 'default',
+  dependencies: [aemu_common_dep, aemu_base_dep, logging_base_dep],
+  link_with: link_gfxstream_backend,
+  install: true,
+)
+
+install_headers(gfxstream_header,
+                subdir: 'gfxstream')
+
+pkg = import('pkgconfig')
+pkg.generate(gfxstream_backend,
+             description: 'gfxstream backend',
+             subdirs: 'gfxstream'
+)
diff --git a/host/renderControl_dec/meson.build b/host/renderControl_dec/meson.build
new file mode 100644
index 0000000..65db881
--- /dev/null
+++ b/host/renderControl_dec/meson.build
@@ -0,0 +1,14 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+files_lib_composer = files(
+  'renderControl_dec.cpp',
+  'renderControl_server_context.cpp'
+)
+
+lib_composer = static_library(
+  'composer',
+  files_lib_composer,
+  cpp_args: default_cpp_args,
+  include_directories: [inc_include, inc_apigen_codec],
+)
diff --git a/host/vulkan/cereal/meson.build b/host/vulkan/cereal/meson.build
new file mode 100644
index 0000000..5cf72e3
--- /dev/null
+++ b/host/vulkan/cereal/meson.build
@@ -0,0 +1,26 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+files_lib_cereal = files(
+  'common/goldfish_vk_extension_structs.cpp',
+  'common/goldfish_vk_marshaling.cpp',
+  'common/goldfish_vk_reserved_marshaling.cpp',
+  'common/goldfish_vk_testing.cpp',
+  'common/goldfish_vk_deepcopy.cpp',
+  'common/goldfish_vk_handlemap.cpp',
+  'common/goldfish_vk_dispatch.cpp',
+  'common/goldfish_vk_transform.cpp'
+)
+
+cereal_cpp_args = [
+  '-DVK_GFXSTREAM_STRUCTURE_TYPE_EXT',
+  '-DVK_GOOGLE_address_space',
+]
+
+lib_vulkan_cereal = static_library(
+  'cereal',
+  files_lib_cereal,
+  cpp_args: cereal_cpp_args,
+  include_directories: [inc_stream_servers, inc_vulkan_server, inc_utils,
+                        inc_include],
+)
diff --git a/host/vulkan/emulated_textures/meson.build b/host/vulkan/emulated_textures/meson.build
new file mode 100644
index 0000000..25ccebf
--- /dev/null
+++ b/host/vulkan/emulated_textures/meson.build
@@ -0,0 +1,20 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+files_emulated_textures = files(
+  'AstcTexture.cpp',
+  'CompressedImageInfo.cpp',
+  'GpuDecompressionPipeline.cpp',
+)
+
+emulated_texture_args = [
+  '-DVK_GFXSTREAM_STRUCTURE_TYPE_EXT'
+]
+
+lib_emulated_textures = static_library(
+  'emulated_textures',
+  files_emulated_textures,
+  cpp_args: emulated_texture_args,
+  include_directories: [inc_utils, inc_root, inc_vulkan_server, inc_include,
+                        inc_stream_servers],
+)
diff --git a/host/vulkan/meson.build b/host/vulkan/meson.build
new file mode 100644
index 0000000..7ee389e
--- /dev/null
+++ b/host/vulkan/meson.build
@@ -0,0 +1,63 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+inc_vulkan_cereal = include_directories('cereal')
+inc_vulkan_server = include_directories('.')
+
+subdir('cereal')
+subdir('emulated_textures')
+
+files_lib_vulkan_server = files(
+  'BorrowedImageVk.cpp',
+  'BufferVk.cpp',
+  'ColorBufferVk.cpp',
+  'CompositorVk.cpp',
+  'DisplayVk.cpp',
+  'DisplaySurfaceVk.cpp',
+  'PostWorkerVk.cpp',
+  'DebugUtilsHelper.cpp',
+  'SwapChainStateVk.cpp',
+  'RenderThreadInfoVk.cpp',
+  'VkAndroidNativeBuffer.cpp',
+  'VkCommonOperations.cpp',
+  'VkDecoder.cpp',
+  'VkDecoderGlobalState.cpp',
+  'VkDecoderSnapshot.cpp',
+  'VkFormatUtils.cpp',
+  'VkReconstruction.cpp',
+  'VulkanDispatch.cpp',
+  'VulkanHandleMapping.cpp',
+  'VulkanStream.cpp',
+  'vk_util.cpp'
+)
+
+vulkan_server_cpp_args = [
+  '-fvisibility=hidden',
+  '-Wno-inconsistent-missing-override',
+  '-Wno-unused-value',
+  '-Wno-return-type',
+  '-Wno-return-type-c-linkage',
+  '-Wno-unused-parameter',
+  '-Wno-unused-variable',
+  '-Wno-unused-function',
+  '-Wno-uninitialized',
+  '-DVK_GFXSTREAM_STRUCTURE_TYPE_EXT',
+]
+
+# Shouldn't these be defined by standard Vulkan headers?
+if host_machine.system() == 'darwin'
+  vulkan_server_cpp_args += '-DVK_USE_PLATFORM_METAL_EXT'
+elif host_machine.system() == 'windows'
+  vulkan_server_cpp_args += '-DVK_USE_PLATFORM_WIN32_KHR'
+endif
+
+lib_vulkan_server = static_library(
+  'lib_vulkan_server',
+  files_lib_vulkan_server,
+  cpp_args:vulkan_server_cpp_args,
+  include_directories: [inc_root, inc_include, inc_utils, inc_apigen_codec,
+                        inc_vulkan_cereal, inc_stream_servers,
+                        inc_vulkan_server, inc_renderdoc_external,
+                        inc_gl_host_common],
+  link_with: [lib_vulkan_cereal, lib_emulated_textures]
+)
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..846b19f
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,102 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+
+project('gfxstream_backend', 'cpp', 'c',
+         version : '0.0.1',
+         license : 'MIT OR Apache-2.0',
+         default_options : ['cpp_std=gnu++17'])
+
+cc = meson.get_compiler('cpp')
+prog_python = import('python').find_installation('python3')
+
+#===============#
+# Configuration #
+#===============#
+c_args = []
+cpp_args = []
+
+default_cpp_args = [
+  '-D_FILE_OFFSET_BITS=64',
+  '-Wno-unused-parameter',
+  '-Wno-unused-function',
+  '-Wno-unused-variable',
+  '-Wno-ignored-qualifiers',
+  '-Wno-reorder-ctor',
+  '-Wno-mismatched-tags',
+  '-Wno-missing-field-initializers',
+  '-Wno-implicit-fallthrough',
+  '-Wno-unused-private-field',
+  '-Wno-macro-redefined'
+]
+
+#===============#
+# Dependencies  #
+#===============#
+drm_dep = dependency('libdrm')
+aemu_base_dep = dependency('aemu_base')
+aemu_common_dep = dependency('aemu_host_common')
+logging_base_dep = dependency('logging_base')
+
+#===============#
+# Decoders      #
+#===============#
+decoders = get_option('decoders')
+
+use_auto = decoders.contains('auto')
+use_gles = decoders.contains('gles')
+use_vulkan = decoders.contains('vulkan')
+use_magma = decoders.contains('magma')
+use_composer = decoders.contains('composer')
+
+if use_auto and (use_gles or use_vulkan or use_magma)
+  error('Can not specify auto and custom options are same time')
+endif
+
+if use_auto
+  use_gles = true
+  use_vulkan = true
+  use_composer = true
+  use_magma = host_machine.system() == 'linux'
+endif
+
+#===============#
+# Includes      #
+#===============#
+
+gfxstream_header = files('include/render-utils/virtio-gpu-gfxstream-renderer.h')
+
+inc_root = include_directories('.')
+inc_include = include_directories('include')
+inc_utils = include_directories('utils/include')
+
+if use_vulkan
+  inc_renderdoc_external = include_directories('third-party/renderdoc/include')
+endif
+
+if use_magma
+  inc_magma_external = include_directories('third-party/fuchsia/magma/include')
+  inc_magma_external_lib = include_directories('third-party/fuchsia/magma/include/lib')
+endif
+
+#================#
+# Subdirectories #
+#================#
+
+subdir('gl-host-common')
+subdir('host')
+
+#================#
+# Summary        #
+#================#
+
+summary({'prefix': get_option('prefix'),
+         'libdir': get_option('libdir'),
+        }, section: 'Directories')
+summary({'c_args': (' ').join(get_option('c_args')),
+         'cpp_args': (' ').join(get_option('cpp_args')),
+         'buildtype': (' ').join(get_option('buildtype')),
+         'gles': use_gles,
+         'vulkan': use_vulkan,
+         'magma': use_magma,
+         'composer': use_composer,
+        }, section: 'Configuration')
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..b487a33
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,15 @@
+# Copyright 2023 Android Open Source Project
+# SPDX-License-Identifier: MIT
+option(
+  'decoders',
+  type : 'array',
+  value : ['auto'],
+  choices : [
+    'gles',
+    'vulkan',
+    'magma',
+    'composer',
+    'auto',
+  ],
+  description : 'A list of supported decoders to build'
+)