xref: /aosp_15_r20/external/libepoxy/test/meson.build (revision 706d0b42ae4182339789e08d473a0b312ecdc60f)
1dl_dep = cc.find_library('dl', required: false)
2has_dlvsym = cc.has_function('dlvsym', dependencies: dl_dep)
3
4has_gles1 = gles1_dep.found()
5has_gles2 = gles2_dep.found()
6build_x11_tests = enable_x11 and x11_dep.found()
7
8test_cflags = common_cflags
9if not has_dlvsym
10test_cflags += [
11  '-D_XOPEN_SOURCE',
12  '-D_POSIX_C_SOURCE=200809L',
13]
14endif
15
16# Unconditionally built tests
17test('header_guards',
18     executable('header guards', 'headerguards.c',
19                c_args: common_cflags,
20                dependencies: libepoxy_dep,
21                include_directories: libepoxy_inc))
22test('misc_defines',
23     executable('misc defines', 'miscdefines.c',
24                c_args: common_cflags,
25                dependencies: libepoxy_dep,
26                include_directories: libepoxy_inc))
27test('khronos_typedefs',
28     executable('khronos typedefs', [
29                  'khronos_typedefs.c',
30                  'khronos_typedefs.h',
31                  'khronos_typedefs_nonepoxy.c',
32                ],
33                c_args: common_cflags,
34                dependencies: libepoxy_dep,
35                include_directories: libepoxy_inc))
36test('gl_version',
37     executable('gl_version',
38                'gl_version.c',
39                c_args: common_cflags,
40                dependencies: libepoxy_dep,
41                include_directories: libepoxy_inc))
42
43if build_egl and build_x11_tests
44  egl_common_sources = [ 'egl_common.h', 'egl_common.c', ]
45  egl_common_lib = static_library('egl_common',
46                                  sources: egl_common_sources,
47                                  dependencies: libepoxy_dep,
48                                  include_directories: libepoxy_inc,
49                                  c_args: common_cflags,
50                                  install: false)
51
52  egl_tests = [
53    [ 'egl_has_extension_nocontext', [], [ 'egl_has_extension_nocontext.c' ], true, ],
54    [ 'egl_epoxy_api', [], [ 'egl_epoxy_api.c' ], true ],
55    [ 'egl_gles1_without_glx', [ '-DGLES_VERSION=1', ], [ 'egl_without_glx.c' ], has_gles1, ],
56    [ 'egl_gles2_without_glx', [ '-DGLES_VERSION=2', ], [ 'egl_without_glx.c' ], has_gles2, ],
57  ]
58
59  if build_glx
60    egl_tests += [
61      [ 'egl_gl', [], [ 'egl_gl.c' ], true, ],
62    ]
63  endif
64
65  foreach test: egl_tests
66    test_name = test[0]
67    test_source = test[2]
68    test_args = test[1]
69    test_run = test[3]
70
71    if test_run
72      test_bin = executable(test_name, test_source,
73                            c_args: test_cflags + test_args,
74                            include_directories: libepoxy_inc,
75                            dependencies: [ libepoxy_dep, x11_dep, egl_dep, dl_dep ],
76                            link_with: egl_common_lib,
77                            link_args: '-rdynamic')
78      test(test_name, test_bin)
79    endif
80  endforeach
81endif
82
83if build_glx and build_x11_tests
84  glx_common_sources = [ 'glx_common.h', 'glx_common.c', ]
85  glx_common_lib = static_library('glx_common',
86                                  sources: glx_common_sources,
87                                  dependencies: libepoxy_dep,
88                                  include_directories: libepoxy_inc,
89                                  c_args: common_cflags,
90                                  install: false)
91
92  # glx_beginend links directly with the GL library, so we need to check it
93  # separately
94  test('glx_beginend', executable('glx_beginend', 'glx_beginend.c',
95                                  c_args: test_cflags,
96                                  include_directories: libepoxy_inc,
97                                  dependencies: [ libepoxy_dep, x11_dep, gl_dep, dl_dep ],
98                                  link_with: glx_common_lib))
99
100  glx_tests = [
101    [ 'glx_public_api', [ 'glx_public_api.c' ], [], [], true ],
102    [ 'glx_public_api_core', [ 'glx_public_api_core.c' ], [], [], true ],
103    [ 'glx_glxgetprocaddress_nocontext', [ 'glx_glxgetprocaddress_nocontext.c' ], [], [], true ],
104    [ 'glx_has_extension_nocontext', [ 'glx_has_extension_nocontext.c' ], [], [], true ],
105    [ 'glx_static', [ 'glx_static.c' ], [ '-DNEEDS_TO_BE_STATIC'], [ '-static' ], libtype == 'static' ],
106    [ 'glx_shared_znow', [ 'glx_static.c', ], [], [ '-Wl,-z,now' ], has_znow ],
107    [ 'glx_alias_prefer_same_name', [ 'glx_alias_prefer_same_name.c', 'dlwrap.c', 'dlwrap.h' ], [], [ '-rdynamic' ], has_dlvsym ],
108    [ 'glx_gles2', [ 'glx_gles2.c', 'dlwrap.c', 'dlwrap.h' ], [], [ '-rdynamic' ], has_dlvsym ],
109  ]
110
111  foreach test: glx_tests
112    test_name = test[0]
113    test_source = test[1]
114    test_c_args = test[2]
115    test_link_args = test[3]
116    test_run = test[4]
117
118    if test_run
119      test_bin = executable(test_name, test_source,
120                            c_args: test_cflags + test_c_args,
121                            include_directories: libepoxy_inc,
122                            dependencies: [ libepoxy_dep, x11_dep, dl_dep ],
123                            link_with: glx_common_lib,
124                            link_args: test_link_args)
125      test(test_name, test_bin)
126    endif
127  endforeach
128endif
129
130# WGL
131if build_wgl
132  wgl_common_sources = [ 'wgl_common.h', 'wgl_common.c', ]
133  wgl_common_lib = static_library('wgl_common',
134                                  sources: wgl_common_sources,
135                                  dependencies: libepoxy_dep,
136                                  include_directories: libepoxy_inc,
137                                  c_args: common_cflags,
138                                  install: false)
139
140  wgl_tests = [
141    [ 'wgl_core_and_exts', [ 'wgl_core_and_exts.c' ], [], ],
142    [ 'wgl_per_context_funcptrs', [ 'wgl_per_context_funcptrs.c' ], [], ],
143    [ 'wgl_usefontbitmaps', [ 'wgl_usefontbitmaps.c'], [], ],
144    [ 'wgl_usefontbitmaps_unicode', [ 'wgl_usefontbitmaps.c' ], [ '-DUNICODE' ], ],
145  ]
146
147  foreach test: wgl_tests
148    test_name = test[0]
149    test_source = test[1]
150    test_c_args = test[2]
151
152    test_bin = executable(test_name, test_source,
153                          c_args: test_cflags + test_c_args,
154                          include_directories: libepoxy_inc,
155                          dependencies: [ libepoxy_dep ],
156                          link_with: wgl_common_lib)
157
158    test(test_name, test_bin)
159  endforeach
160endif
161
162# Apple
163if host_machine.system().contains('darwin')
164  opengl_dep = dependency('appleframeworks', modules: ['OpenGL', 'Carbon'], required: true)
165
166  cgl_tests = [
167    [ 'cgl_core', [ 'cgl_core.c' ] ],
168    [ 'cgl_epoxy_api', [ 'cgl_epoxy_api.c' ] ],
169  ]
170
171  foreach t: cgl_tests
172    test_name = t[0]
173    test_sources = t[1]
174
175    test(test_name,
176      executable(
177        test_name, test_sources,
178        c_args: test_cflags,
179        include_directories: libepoxy_inc,
180        dependencies: [ libepoxy_dep, opengl_dep ],
181      ),
182    )
183  endforeach
184endif
185