1common_sources = [
2    'benchmark-collection.cpp',
3    'benchmark.cpp',
4    'canvas-generic.cpp',
5    'gl-headers.cpp',
6    'gl-visual-config.cpp',
7    'image-reader.cpp',
8    'libmatrix/log.cc',
9    'libmatrix/mat.cc',
10    'libmatrix/program.cc',
11    'libmatrix/shader-source.cc',
12    'libmatrix/util.cc',
13    'main-loop.cpp',
14    'mesh.cpp',
15    'model.cpp',
16    'options.cpp',
17    'scene-buffer.cpp',
18    'scene-build.cpp',
19    'scene-bump.cpp',
20    'scene-clear.cpp',
21    'scene-conditionals.cpp',
22    'scene.cpp',
23    'scene-default-options.cpp',
24    'scene-desktop.cpp',
25    'scene-effect-2d.cpp',
26    'scene-function.cpp',
27    'scene-grid.cpp',
28    'scene-ideas/a.cc',
29    'scene-ideas.cpp',
30    'scene-ideas/d.cc',
31    'scene-ideas/e.cc',
32    'scene-ideas/i.cc',
33    'scene-ideas/lamp.cc',
34    'scene-ideas/logo.cc',
35    'scene-ideas/m.cc',
36    'scene-ideas/n.cc',
37    'scene-ideas/o.cc',
38    'scene-ideas/s.cc',
39    'scene-ideas/splines.cc',
40    'scene-ideas/table.cc',
41    'scene-ideas/t.cc',
42    'scene-jellyfish.cpp',
43    'scene-loop.cpp',
44    'scene-pulsar.cpp',
45    'scene-refract.cpp',
46    'scene-shading.cpp',
47    'scene-shadow.cpp',
48    'scene-terrain/base-renderer.cpp',
49    'scene-terrain/blur-renderer.cpp',
50    'scene-terrain/copy-renderer.cpp',
51    'scene-terrain.cpp',
52    'scene-terrain/luminance-renderer.cpp',
53    'scene-terrain/normal-from-height-renderer.cpp',
54    'scene-terrain/overlay-renderer.cpp',
55    'scene-terrain/renderer-chain.cpp',
56    'scene-terrain/simplex-noise-renderer.cpp',
57    'scene-terrain/terrain-renderer.cpp',
58    'scene-terrain/texture-renderer.cpp',
59    'scene-texture.cpp',
60    'shared-library.cpp',
61    'text-renderer.cpp',
62    'texture.cpp'
63]
64
65libmatrix_headers_dep = declare_dependency(
66    include_directories: include_directories('libmatrix'),
67    compile_args: ['-DUSE_EXCEPTIONS'],
68)
69
70common_deps = [
71    m_dep,
72    dl_dep,
73    libjpeg_dep,
74    libpng_dep,
75    libmatrix_headers_dep,
76]
77
78if need_drm
79    native_drm_lib = static_library(
80        'native-drm',
81        'native-state-drm.cpp',
82        dependencies: [libdrm_dep, libudev_dep, gbm_dep, libmatrix_headers_dep],
83        )
84    native_drm_dep = declare_dependency(
85        link_with: native_drm_lib,
86        dependencies: libdrm_dep,
87        compile_args: ['-DGLMARK2_USE_DRM', '-D__GBM__'],
88        )
89else
90    native_drm_dep = declare_dependency()
91endif
92
93if need_wayland
94    wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))
95    wayland_protocols_dir = wayland_protocols_dep.get_pkgconfig_variable('pkgdatadir')
96
97    xdg_shell_xml_path = wayland_protocols_dir + '/stable/xdg-shell/xdg-shell.xml'
98    xdg_shell_client_header = custom_target(
99        'xdg-shell client-header',
100        command: [ wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@' ],
101        input: xdg_shell_xml_path,
102        output: 'xdg-shell-client-protocol.h',
103        )
104    xdg_shell_private_code = custom_target(
105        'xdg-shell private-code',
106        command: [ wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@' ],
107        input: xdg_shell_xml_path,
108        output: 'xdg-shell-protocol.c',
109        )
110
111    native_wayland_lib = static_library(
112        'native-wayland',
113        'native-state-wayland.cpp',
114        xdg_shell_client_header,
115        xdg_shell_private_code,
116        dependencies: [libmatrix_headers_dep, wayland_client_dep, wayland_cursor_dep, wayland_egl_dep],
117        )
118
119    native_wayland_dep = declare_dependency(
120        link_with: native_wayland_lib,
121        dependencies: [wayland_client_dep, wayland_cursor_dep, wayland_egl_dep],
122        compile_args: ['-DGLMARK2_USE_WAYLAND', '-DWL_EGL_PLATFORM'],
123        )
124else
125    native_wayland_dep = declare_dependency()
126endif
127
128if need_x11
129    native_x11_lib = static_library(
130        'native-x11',
131        'native-state-x11.cpp',
132        dependencies: [x11_dep, libmatrix_headers_dep],
133        )
134
135    native_x11_dep = declare_dependency(
136        link_with: native_x11_lib,
137        compile_args: ['-DGLMARK2_USE_X11'],
138        )
139else
140    native_x11_dep = declare_dependency()
141endif
142
143if need_gl
144    gl_gl_lib = static_library(
145        'gl-gl',
146        'glad/src/gl.c',
147        include_directories: include_directories('glad/include'),
148        )
149    gl_gl_dep = declare_dependency(
150        link_with: gl_gl_lib,
151        include_directories: include_directories('glad/include'),
152        compile_args: ['-DGLMARK2_USE_GL'],
153        )
154
155    lib_common_gl = static_library(
156        'common-gl',
157        common_sources,
158        dependencies: [gl_gl_dep, common_deps],
159        include_directories: [
160            include_directories('scene-ideas'),
161            include_directories('scene-terrain'),
162            ]
163        )
164    common_gl_dep = declare_dependency(
165        link_with: lib_common_gl,
166        include_directories: include_directories('libmatrix'),
167        )
168else
169    gl_gl_dep = declare_dependency()
170    common_gl_dep = declare_dependency()
171endif
172
173if need_glesv2
174    gl_glesv2_lib = static_library(
175        'gl-glesv2',
176        'glad/src/gles2.c',
177        include_directories: include_directories('glad/include'),
178        )
179    gl_glesv2_dep = declare_dependency(
180        link_with: gl_glesv2_lib,
181        include_directories: include_directories('glad/include'),
182        compile_args: ['-DGLMARK2_USE_GLESv2'],
183        )
184
185    lib_common_glesv2 = static_library(
186        'common-glesv2',
187        common_sources,
188        dependencies: [gl_glesv2_dep, common_deps],
189        include_directories: [
190            include_directories('scene-ideas'),
191            include_directories('scene-terrain'),
192            ]
193        )
194    common_glesv2_dep = declare_dependency(
195        link_with: lib_common_glesv2,
196        include_directories: include_directories('libmatrix'),
197        )
198else
199    gl_glesv2_dep = declare_dependency()
200    common_glesv2_dep = declare_dependency()
201endif
202
203if need_egl
204    # gl-state-egl builds depend on both the GL type and the native type. To
205    # avoid creating all the required combinations explicitly, make this a
206    # source dependency which will be built properly as part of the final
207    # glmark2 executable.
208    wsi_egl_dep = declare_dependency(
209        sources: ['gl-state-egl.cpp', 'glad/src/egl.c'],
210        include_directories: [
211            include_directories('glad/include'),
212            include_directories('libmatrix'),
213            ],
214        compile_args: ['-DGLMARK2_USE_EGL'],
215        )
216else
217    wsi_egl_dep = declare_dependency()
218endif
219
220if need_glx
221    # Although there is a single valid flavor for glx (x11-gl) and we could
222    # build gl-state-glx here, make this a source dependency for convenience
223    # and parity with gl-state-egl.
224    wsi_glx_dep = declare_dependency(
225        sources: ['gl-state-glx.cpp', 'glad/src/glx.c'],
226        include_directories: [
227            include_directories('glad/include'),
228            include_directories('libmatrix'),
229            ],
230        compile_args: ['-DGLMARK2_USE_GLX'],
231        )
232else
233    wsi_glx_dep = declare_dependency()
234endif
235
236# Flavor info : [ binary, native, gl, wsi ]
237flavor_info = {
238  'drm-gl' : ['glmark2-drm', native_drm_dep, gl_gl_dep, wsi_egl_dep],
239  'drm-glesv2' : ['glmark2-es2-drm', native_drm_dep, gl_glesv2_dep, wsi_egl_dep],
240  'wayland-gl' : ['glmark2-wayland', native_wayland_dep, gl_gl_dep, wsi_egl_dep],
241  'wayland-glesv2' : ['glmark2-es2-wayland', native_wayland_dep, gl_glesv2_dep, wsi_egl_dep],
242  'x11-gl' : ['glmark2', native_x11_dep, gl_gl_dep, wsi_glx_dep],
243  'x11-glesv2' : ['glmark2-es2', native_x11_dep, gl_glesv2_dep, wsi_egl_dep],
244}
245
246foreach flavor : flavors
247    info = flavor_info[flavor]
248    binary = info[0]
249    native_dep = info[1]
250    gl_dep = info[2]
251    wsi_dep = info[3]
252    if gl_dep == gl_gl_dep
253        common_dep = common_gl_dep
254    elif gl_dep == gl_glesv2_dep
255        common_dep = common_glesv2_dep
256    endif
257    executable(
258        binary,
259        ['main.cpp', 'canvas-generic.cpp'],
260        dependencies: [common_dep, native_dep, gl_dep, wsi_dep],
261        install: true,
262    )
263endforeach
264