1# Copyright © 2017 Dylan Baker
2# Copyright © 2018-2019 Intel Corporation
3#
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are met:
8#
9# - Redistributions of source code must retain the above copyright notice, this
10#   list of conditions and the following disclaimer.
11#
12# - Redistributions in binary form must reproduce the above copyright notice,
13#   this list of conditions and the following disclaimer in the documentation
14#   and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27# because of the way meson works and the use of preprocessor defines to guard
28# code puting all of the depends in one giant array is fine. If they weren't
29# found meson is fine with that, otherwise they'll be unnecissary and cause no
30# harm.
31deps_for_waffle = [
32  dep_gl,
33  dep_egl,
34  dep_gbm,
35  dep_udev,
36  dep_nacl,
37  dep_wayland_client,
38  dep_wayland_egl,
39  dep_wayland_protocols,
40  dep_wayland_scanner,
41  dep_x11_xcb,
42  dep_dl,
43  dep_cocoa,
44  dep_core_foundation,
45  dep_gl_headers,
46  idep_threads,
47]
48
49files_libwaffle = files(
50  'api/api_priv.c',
51  'api/waffle_attrib_list.c',
52  'api/waffle_config.c',
53  'api/waffle_context.c',
54  'api/waffle_display.c',
55  'api/waffle_dl.c',
56  'api/waffle_enum.c',
57  'api/waffle_error.c',
58  'api/waffle_gl_misc.c',
59  'api/waffle_init.c',
60  'api/waffle_window.c',
61  'core/wcore_attrib_list.c',
62  'core/wcore_config_attrs.c',
63  'core/wcore_display.c',
64  'core/wcore_error.c',
65  'core/wcore_tinfo.c',
66  'core/wcore_util.c',
67)
68
69if not ['darwin', 'windows'].contains(host_machine.system())
70  files_libwaffle += files('linux/linux_dl.c', 'linux/linux_platform.c')
71endif
72
73if build_x11_egl or build_wayland or build_gbm or build_surfaceless
74  files_libwaffle += files(
75    'egl/wegl_config.c',
76    'egl/wegl_context.c',
77    'egl/wegl_display.c',
78    'egl/wegl_platform.c',
79    'egl/wegl_util.c',
80    'egl/wegl_surface.c',
81  )
82endif
83
84if build_surfaceless
85  files_libwaffle += files(
86    'surfaceless_egl/sl_display.c',
87    'surfaceless_egl/sl_platform.c',
88    'surfaceless_egl/sl_window.c',
89  )
90endif
91
92if build_wayland
93  files_libwaffle += files(
94    'wayland/wayland_display.c',
95    'wayland/wayland_platform.c',
96    'wayland/wayland_window.c',
97    'wayland/wayland_wrapper.c',
98  )
99
100  wl_protocol_dir = dep_wayland_protocols.get_variable(pkgconfig: 'pkgdatadir')
101  xdg_protocol = wl_protocol_dir / 'stable/xdg-shell/xdg-shell.xml'
102  xdg_protocol_src = custom_target(
103    'xdg_shell_c',
104    input: xdg_protocol,
105    output: '@BASENAME@-protocol.c',
106    command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'],
107  )
108  files_libwaffle += xdg_protocol_src
109
110  xdg_protocol_client_header = custom_target(
111    'xdg_shell_client_h',
112    input: xdg_protocol,
113    output: '@BASENAME@-client-protocol.h',
114    command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'],
115  )
116  files_libwaffle += xdg_protocol_client_header
117
118endif
119
120if build_gbm
121  files_libwaffle += files(
122    'gbm/wgbm_config.c',
123    'gbm/wgbm_display.c',
124    'gbm/wgbm_platform.c',
125    'gbm/wgbm_window.c',
126  )
127endif
128
129if build_x11_egl
130  files_libwaffle += files(
131    'xegl/xegl_display.c',
132    'xegl/xegl_platform.c',
133    'xegl/xegl_window.c',
134  )
135endif
136
137if build_glx or build_x11_egl
138  files_libwaffle += files(
139    'x11/x11_display.c',
140    'x11/x11_window.c',
141  )
142endif
143
144if build_glx
145  files_libwaffle += files(
146    'glx/glx_config.c',
147    'glx/glx_context.c',
148    'glx/glx_display.c',
149    'glx/glx_platform.c',
150    'glx/glx_window.c',
151  )
152endif
153
154if build_nacl
155  files_libwaffle += files(
156    'nacl/nacl_config.c',
157    'nacl/nacl_context.c',
158    'nacl/nacl_display.c',
159    'nacl/nacl_dl.c',
160    'nacl/nacl_platform.c',
161    'nacl/nacl_window.c',
162    'nacl/nacl_container.cpp',
163  )
164endif
165
166if build_wgl
167  files_libwaffle += files(
168    'wgl/wgl_config.c',
169    'wgl/wgl_context.c',
170    'wgl/wgl_display.c',
171    'wgl/wgl_dl.c',
172    'wgl/wgl_error.c',
173    'wgl/wgl_platform.c',
174    'wgl/wgl_window.c',
175  )
176endif
177
178if build_cgl
179  files_libwaffle += files(
180    'cgl/cgl_config.m',
181    'cgl/cgl_context.m',
182    'cgl/cgl_display.m',
183    'cgl/cgl_dl.m',
184    'cgl/cgl_error.m',
185    'cgl/cgl_platform.m',
186    'cgl/cgl_window.m',
187    'cgl/WaffleGLView.m',
188  )
189endif
190
191include_libwaffle = include_directories(
192  'android', 'api', 'cgl', 'core', 'egl', 'glx', 'linux', 'nacl',
193  'surfaceless_egl', 'wayland', 'wgl', 'x11', 'xegl'
194)
195
196waffle_data = configuration_data()
197waffle_data.set('waffle_libname', waffle_name)
198
199waffle_defs = configure_file(
200  configuration : waffle_data,
201  input : 'waffle.def.in',
202  output : '@BASENAME@',
203)
204
205_ver = meson.project_version().split('.')
206_ver = '0.@0@.@1@'.format(_ver[1], _ver[2])
207
208libwaffle = library(
209  waffle_name,
210  [files_libwaffle, waffle_config_h],
211  include_directories : [include_libwaffle, inc_waffle, inc_include],
212  c_args : api_c_args,
213  cpp_args : api_c_args,
214  dependencies : deps_for_waffle,
215  soversion : host_machine.system() != 'windows' ? '0' : '',
216  version : _ver,
217  install : true,
218  vs_module_defs : waffle_defs,
219  gnu_symbol_visibility : 'hidden',
220)
221
222ext_waffle = declare_dependency(
223  link_with : libwaffle,
224  include_directories : [inc_waffle, inc_include],
225)
226
227pkg = import('pkgconfig')
228pkg.generate(
229  libwaffle,
230  version : meson.project_version(),
231  subdirs : waffle_name,
232  description : 'A library for selecting an OpenGL API and windows system at runtime.',
233)
234
235if meson.version().version_compare('>= 0.50')
236  cmake = import('cmake')
237  cmake.write_basic_package_version_file(
238    name : 'Waffle',
239    version : meson.project_version(),
240    compatibility : 'SameMajorVersion',
241  )
242
243  cmake_conf = configuration_data()
244  cmake_conf.set('waffle_libname', waffle_name)
245  cmake_conf.set('PACKAGE_CMAKE_INSTALL_INCLUDEDIR', join_paths('${PACKAGE_PREFIX_DIR}', get_option('includedir')))
246  cmake_conf.set('PACKAGE_CMAKE_INSTALL_LIBDIR', join_paths('${PACKAGE_PREFIX_DIR}', get_option('libdir')))
247
248  cmake.configure_package_config_file(
249    name : 'Waffle',
250    input : '../../cmake/Modules/WaffleConfig.cmake.in',
251    configuration : cmake_conf,
252  )
253endif
254
255if get_option('build-tests')
256  if get_option('default_library') == 'shared'
257    # The unit tests need to poke at internals of the library, but with a
258    # shared library and visibility=hidden it can't. If we have a shared
259    # library then we build a static library to link the unit tests against
260    testwaffle = static_library(
261      'testwaffle',
262      [files_libwaffle, waffle_config_h],
263      include_directories : [include_libwaffle, inc_waffle, inc_include],
264      c_args : api_c_args,
265      cpp_args : api_c_args,
266      dependencies : deps_for_waffle,
267    )
268  else
269    testwaffle = libwaffle
270  endif
271
272  foreach t : ['wcore_attrib_list', 'wcore_config_attrs', 'wcore_error']
273    test(
274      t,
275      executable(
276        '@0@_unittest'.format(t),
277        'core/@0@_unittest.c'.format(t),
278        dependencies : [dep_cmocka, idep_threads],
279        include_directories : [inc_waffle, inc_include],
280        link_with : testwaffle,
281      ),
282      suite : ['core'],
283    )
284  endforeach
285endif
286