1# Copyright 2023 Android Open Source Project
2# SPDX-License-Identifier: MIT
3
4#===============#
5# Configuration #
6#===============#
7gfxstream_host_args = [
8  '-D_FILE_OFFSET_BITS=64',
9  '-DGFXSTREAM_ENABLE_GUEST_VIRTIO_RESOURCE_TILING_CONTROL=1',
10  '-Wno-unused-parameter',
11  '-Wno-unused-function',
12  '-Wno-unused-variable',
13  '-Wno-ignored-qualifiers',
14  '-Wno-mismatched-tags',
15  '-Wno-missing-field-initializers',
16  '-Wno-implicit-fallthrough',
17]
18
19if host_machine.system() == 'qnx'
20  gfxstream_host_args += '-D_QNX_SOURCE'
21  qnx_target = get_option('qnx_target')
22  if qnx_target == ''
23    error('option qnx_target is not set')
24  endif
25endif
26
27pkg_cflags = []
28pkg_cflags += '-DGFXSTREAM_UNSTABLE=1'
29
30#===============#
31# Dependencies  #
32#===============#
33if host_machine.system() == 'qnx'
34  ## have not yet got pkgconfig to work with cross-compile,
35  ## finding libraries manually in the meantime.
36
37  ## ERROR: Dependency "screen" not found, tried pkgconfig
38  # qnx_screen_dep = dependency('screen')
39
40  rel_path_prefix = meson.get_external_property('qnx_path_prefix')
41  abs_path_prefix = meson.current_source_dir() + '/' + rel_path_prefix
42
43  aemu_libs_path = abs_path_prefix + '/aemu/install/lib'
44
45  incl_aemu_headers = include_directories([
46    rel_path_prefix + '/aemu/install/include',
47    rel_path_prefix + '/aemu/install/include/aemu/host-common',
48    rel_path_prefix + '/aemu/install/include/aemu/snapshot',
49  ])
50
51  aemu_base_lib = cc.find_library('aemu-base', dirs: aemu_libs_path)
52  aemu_base_dep = declare_dependency(include_directories : incl_aemu_headers, dependencies : [aemu_base_lib])
53
54  aemu_common_lib = cc.find_library('aemu-host-common', dirs: aemu_libs_path)
55  aemu_common_dep = declare_dependency(include_directories : incl_aemu_headers, dependencies : [aemu_common_lib])
56
57  aemu_logging_lib = cc.find_library('aemu-logging', dirs: aemu_libs_path)
58  aemu_logging_dep = declare_dependency(include_directories : incl_aemu_headers, dependencies : [aemu_logging_lib])
59
60  aemu_snapshot_lib = cc.find_library('aemu-snapshot', dirs: aemu_libs_path)
61  aemu_snapshot_dep = declare_dependency(include_directories : incl_aemu_headers, dependencies : [aemu_snapshot_lib])
62
63  inc_qnx_headers = include_directories(join_paths(qnx_target, 'usr/include'))
64  qnx_screen_lib = cc.find_library('screen', required : true)
65  qnx_screen_dep = declare_dependency(include_directories: inc_qnx_headers, dependencies: [qnx_screen_lib])
66
67  qnx_egl_lib = cc.find_library('EGL', required : true)
68  qnx_egl_dep = declare_dependency(include_directories: inc_qnx_headers, dependencies: [qnx_egl_lib])
69
70  qnx_gles2_lib = cc.find_library('GLESv2', required : true)
71  qnx_gles2_dep = declare_dependency(include_directories: inc_qnx_headers, dependencies: [qnx_gles2_lib])
72
73else
74  aemu_base_dep = dependency('aemu_base')
75  aemu_common_dep = dependency('aemu_host_common')
76  aemu_logging_dep = dependency('aemu_logging')
77  aemu_snapshot_dep = dependency('aemu_snapshot')
78  dl_dep = dependency('dl')
79  thread_dep = dependency('threads')
80  gfxstream_host_args += '-DGFXSTREAM_UNSTABLE_VULKAN_EXTERNAL_SYNC=1'
81  gfxstream_host_args += '-DGFXSTREAM_UNSTABLE_VULKAN_DMABUF_WINSYS=1'
82endif
83
84if log_level == 'error'
85  gfxstream_host_args += '-DSTREAM_RENDERER_LOG_LEVEL=1'
86elif log_level == 'warn'
87  gfxstream_host_args += '-DSTREAM_RENDERER_LOG_LEVEL=2'
88elif log_level == 'info'
89  gfxstream_host_args += '-DSTREAM_RENDERER_LOG_LEVEL=3'
90endif
91
92if use_auto and (use_gles or use_vulkan or use_magma)
93  error('Can not specify auto and custom options are same time')
94endif
95
96if use_auto
97  use_gles = true
98  use_vulkan = true
99  use_composer = true
100  use_magma = host_machine.system() == 'linux'
101endif
102
103gfxstream_host_args += '-DGFXSTREAM_ENABLE_HOST_GLES=@0@'.format(use_gles ? '1' : '0')
104
105if use_magma
106  gfxstream_host_args += '-DGFXSTREAM_ENABLE_HOST_MAGMA=1'
107  drm_dep = dependency('libdrm', fallback: ['libdrm', 'libdrm_dep'])
108else
109  gfxstream_host_args += '-DGFXSTREAM_ENABLE_HOST_MAGMA=0'
110endif
111
112#===============#
113# Includes      #
114#===============#
115
116gfxstream_headers = files(
117  'include/gfxstream/virtio-gpu-gfxstream-renderer.h',
118  'include/gfxstream/virtio-gpu-gfxstream-renderer-unstable.h')
119
120inc_root = include_directories('../')
121inc_gfxstream_include = include_directories('../include')
122# Included by all host component builds. Leave empty for future build updates.
123inc_include = include_directories()
124inc_utils = include_directories('../utils/include')
125
126if host_machine.system() == 'qnx'
127  inc_gfxstream_include = [inc_qnx_headers, inc_gfxstream_include]
128endif
129
130if use_vulkan
131  inc_vulkan_headers = include_directories('../common/vulkan/include')
132
133  if cc.has_header('renderdoc_app.h')
134    inc_renderdoc_external = include_directories()
135  else
136    inc_renderdoc_external = include_directories('../third-party/renderdoc/include')
137  endif
138endif
139
140if use_magma
141  inc_magma_external = include_directories('../third-party/fuchsia/magma/include')
142  inc_magma_external_lib = include_directories('../third-party/fuchsia/magma/include/lib')
143endif
144
145if cc.has_header('glm/glm.hpp')
146  inc_glm = include_directories()
147else
148  inc_glm = include_directories('../third-party/glm/include')
149endif
150
151inc_stream_servers = include_directories('.')
152inc_host_include = include_directories('include')
153
154subdir('features')
155subdir('tracing')
156
157subdir('apigen-codec-common')
158subdir('gl/gl-host-common')
159subdir('backend')
160
161inc_gfxstream_backend = [inc_root, inc_gfxstream_include, inc_include, inc_apigen_codec, inc_utils,
162                         inc_gl_host_common, inc_host_include, inc_common_utils, inc_host_backend,
163                         inc_host_features, inc_host_tracing]
164
165link_gfxstream_backend = [lib_gl_host_common, lib_apigen_codec, lib_common_utils, lib_host_backend,
166                          lib_host_features, lib_host_tracing]
167
168files_lib_gfxstream_backend = files(
169  'Buffer.cpp',
170  'ExternalObjectManager.cpp',
171  'ChannelStream.cpp',
172  'ColorBuffer.cpp',
173  'DisplaySurface.cpp',
174  'DisplaySurfaceUser.cpp',
175  'Hwc2.cpp',
176  'PostWorker.cpp',
177  'ReadBuffer.cpp',
178  'render_api.cpp',
179  'RenderChannelImpl.cpp',
180  'RenderThread.cpp',
181  'RenderThreadInfo.cpp',
182  'RingStream.cpp',
183  'SyncThread.cpp',
184  'RenderWindow.cpp',
185  'RenderLibImpl.cpp',
186  'RendererImpl.cpp',
187  'FrameBuffer.cpp',
188  'GfxStreamAgents.cpp',
189  'virtio-gpu-gfxstream-renderer.cpp',
190  'VirtioGpuContext.cpp',
191  'VirtioGpuFrontend.cpp',
192  'VirtioGpuResource.cpp',
193  'VirtioGpuRingBlob.cpp',
194  'VirtioGpuTimelines.cpp',
195  'VsyncThread.cpp',
196)
197
198if use_gles or use_vulkan
199  subdir('compressedTextureFormats')
200endif
201
202if use_gles
203  subdir('gl')
204
205  files_lib_gfxstream_backend += files('PostWorkerGl.cpp')
206  files_lib_gfxstream_backend += files('RenderThreadInfoGl.cpp')
207  files_lib_gfxstream_backend += files('RenderControl.cpp')
208
209  inc_gfxstream_backend += [inc_gl_server, inc_gl_snapshot, inc_gles_translator]
210  link_gfxstream_backend += lib_gl_server
211endif
212
213if use_vulkan
214  subdir('vulkan')
215  inc_gfxstream_backend += [inc_cereal, inc_cereal_common, inc_vulkan_headers,
216                            inc_vulkan_server, inc_renderdoc_external]
217  link_gfxstream_backend += lib_vulkan_server
218endif
219
220if use_composer
221  subdir('renderControl_dec')
222  link_gfxstream_backend += lib_composer
223endif
224
225if use_magma
226  subdir('magma')
227  files_lib_gfxstream_backend += files('RenderThreadInfoMagma.cpp')
228  inc_gfxstream_backend += [inc_magma_dec, inc_magma_external]
229  link_gfxstream_backend += lib_magma_server
230endif
231
232if not use_gles
233  files_lib_gfxstream_backend += files('NativeSubWindow_stub.cpp')
234elif host_machine.system() == 'darwin'
235  files_lib_gfxstream_backend += files('NativeSubWindow_cocoa.mm')
236elif host_machine.system() == 'windows'
237  files_lib_gfxstream_backend += files('NativeSubWindow_win32.cpp')
238elif host_machine.system() == 'linux' and use_gles
239  files_lib_gfxstream_backend += files('NativeSubWindow_x11.cpp')
240elif host_machine.system() == 'qnx'
241  files_lib_gfxstream_backend += files(
242    'NativeSubWindow_qnx.cpp',
243    '../qnx/host/platform_qnx.cpp',
244  )
245endif
246
247gfxstream_backend_cpp_args = [
248  '-Wno-unused-parameter',
249  '-Wno-unused-variable',
250  '-Wno-unused-function',
251  '-DVK_GFXSTREAM_STRUCTURE_TYPE_EXT',
252]
253
254deps_gfxstream_backend = [
255  aemu_common_dep,
256  aemu_base_dep,
257  aemu_logging_dep,
258  aemu_snapshot_dep,
259]
260
261link_args_gfxstream_backend = ''
262
263if host_machine.system() == 'linux'
264  deps_gfxstream_backend += [
265    dl_dep,
266    thread_dep,
267  ]
268  link_args_gfxstream_backend = '-Wl,-lpthread,-lrt'
269endif
270
271if host_machine.system() == 'qnx'
272  deps_gfxstream_backend += [
273    qnx_egl_dep,
274    qnx_gles2_dep,
275    qnx_screen_dep,
276  ]
277endif
278
279gfxstream_backend = library(
280  'gfxstream_backend',
281  files_lib_gfxstream_backend,
282  cpp_args: gfxstream_host_args + gfxstream_backend_cpp_args,
283  include_directories: [inc_gfxstream_backend, inc_glm],
284  gnu_symbol_visibility: 'default',
285  dependencies: deps_gfxstream_backend,
286  link_with: link_gfxstream_backend,
287  link_args : link_args_gfxstream_backend,
288  version: '0.1.2',
289  install: true,
290)
291
292install_headers(gfxstream_headers,
293                subdir: 'gfxstream')
294
295pkg = import('pkgconfig')
296pkg.generate(gfxstream_backend,
297             description: 'gfxstream backend',
298             extra_cflags: pkg_cflags,
299             subdirs: 'gfxstream'
300)
301