summaryrefslogtreecommitdiff
path: root/meson.build
blob: 47f1d45b4a0cb2673c37ec76132440577d9d1e0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
project('libepoxy', 'c', version: '1.4.0',
        default_options: [
          'buildtype=debugoptimized',
          'c_std=gnu99',
          'warning_level=1',
        ],
        license: 'MIT',
        meson_version: '>= 0.36.0')

epoxy_version = meson.project_version().split('.')
epoxy_major_version = epoxy_version[0].to_int()
epoxy_minor_version = epoxy_version[1].to_int()
epoxy_micro_version = epoxy_version[2].to_int()

epoxy_prefix = get_option('prefix')
epoxy_libdir = join_paths(epoxy_prefix, get_option('libdir'))
epoxy_datadir = join_paths(epoxy_prefix, get_option('datadir'))
epoxy_includedir = join_paths(epoxy_prefix, get_option('includedir'))

cc = meson.get_compiler('c')
host_system = host_machine.system()

conf = configuration_data()
conf.set_quoted('PACKAGE_NAME', meson.project_name())
conf.set_quoted('PACKAGE_VERSION', meson.project_version())
conf.set_quoted('PACKAGE_STRING', '@0@-@1@'.format(meson.project_name(), meson.project_version()))
conf.set_quoted('PACKAGE_DATADIR', join_paths(get_option('prefix'), get_option('datadir')))
conf.set_quoted('PACKAGE_LIBDIR', join_paths(get_option('prefix'), get_option('libdir')))
conf.set_quoted('PACKAGE_LOCALEDIR', join_paths(get_option('prefix'), get_option('datadir'), 'locale'))
conf.set_quoted('PACKAGE_LIBEXECDIR', join_paths(get_option('prefix'), get_option('libexecdir')))
conf.set('HAVE_KHRPLATFORM_H', cc.has_header('KHR/khrplatform.h', required: false))

# GLX can be used on different platforms, so we expose a
# configure time switch to enable or disable it; in case
# the "auto" default value is set, we only enable GLX
# support on Linux and Unix
enable_glx = get_option('enable-glx')
if enable_glx == 'auto'
  if host_system == 'windows'
    build_glx = false
  elif host_system == 'darwin'
    build_glx = false
  elif host_system == 'android'
    build_glx = false
  else
    build_glx = true
  endif
elif enable_glx == 'yes'
  build_glx = true
elif enable_glx == 'no'
  build_glx = false
endif

# The remaining platform specific API for GL/GLES are enabled
# depending on the platform we're building for
if host_system == 'windows'
  build_egl = false
  build_apple = false
  build_wgl = true
  has_znow = true
elif host_system == 'darwin'
  build_egl = false
  build_apple = true
  build_wgl = false
  has_znow = false
else
  build_egl = true
  build_apple = false
  build_wgl = false
  has_znow = true
endif

conf.set10('ENABLE_GLX', build_glx)

# Compiler flags, taken from the Xorg macros
test_cflags = [
  '-Wpointer-arith',
  '-Wmissing-declarations',
  '-Wformat=2',
  '-Wstrict-prototypes',
  '-Wmissing-prototypes',
  '-Wnested-externs',
  '-Wbad-function-cast',
  '-Wold-style-definition',
  '-Wdeclaration-after-statement',
  '-Wunused',
  '-Wuninitialized',
  '-Wshadow',
  '-Wmissing-noreturn',
  '-Wmissing-format-attribute',
  '-Wredundant-decls',
  '-Wlogical-op',
  '-Werror=implicit',
  '-Werror=nonnull',
  '-Werror=init-self',
  '-Werror=main',
  '-Werror=missing-braces',
  '-Werror=sequence-point',
  '-Werror=return-type',
  '-Werror=trigraphs',
  '-Werror=array-bounds',
  '-Werror=write-strings',
  '-Werror=address',
  '-Werror=int-to-pointer-cast',
  '-Werror=pointer-to-int-cast',
  '-fno-strict-aliasing',
  '-Wno-int-conversion',
]
common_cflags = []
foreach cflag: test_cflags
  if cc.has_argument(cflag)
    common_cflags += [ cflag ]
  endif
endforeach

# Visibility compiler flags
visibility_cflags = []
if get_option('default_library') != 'static'
  if host_system == 'windows'
    conf.set('DLL_EXPORT', true)
    if cc.get_id() == 'msvc'
      conf.set('EPOXY_PUBLIC', '__declspec(dllexport) extern')
    else
      conf.set('EPOXY_PUBLIC', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
      visibility_cflags += [ '-fvisibility=hidden' ]
    endif
  else
    conf.set('EPOXY_PUBLIC', '__attribute__((visibility("default")))')
    visibility_cflags += [ '-fvisibility=hidden' ]
  endif
endif

# Dependencies
dl_dep = cc.find_library('dl', required: false)
gl_dep = dependency('gl', required: false)
egl_dep = dependency('egl', required: false)

# Optional dependencies for tests
x11_dep = dependency('x11', required: false)
gles1_dep = cc.find_library('libGLESv1_CM', required: false)
gles2_dep = cc.find_library('libGLESv2', required: false)

# On windows, the DLL has to have all of its functions
# resolved at link time, so we have to link directly aginst
# opengl32.  But that's the only GL provider, anyway.
if host_system == 'windows'
  opengl32_dep = cc.find_library('opengl32', required: true)

  # When building against static libraries, we need to control
  # the order of the dependencies, and gdi32 provides symbols
  # needed when using opengl32, like SetPixelFormat and
  # ChoosePixelFormat. This is mostly a workaround for older
  # versions of Meson.
  gdi32_dep = cc.find_library('gdi32', required: true)
endif

# PkgConfig file
pkgconf = configuration_data()
pkgconf.set('prefix', epoxy_prefix)
pkgconf.set('exec_prefix', epoxy_prefix)
pkgconf.set('libdir', epoxy_libdir)
pkgconf.set('includedir', epoxy_includedir)
pkgconf.set10('epoxy_has_glx', build_glx)
pkgconf.set10('epoxy_has_egl', build_egl)
pkgconf.set10('epoxy_has_wgl', build_wgl)
pkgconf.set('PACKAGE_VERSION', meson.project_version())
if dl_dep.found()
  pkgconf.set('DLOPEN_LIBS', '-ldl')
endif

configure_file(input: 'epoxy.pc.in',
               output: 'epoxy.pc',
               configuration: pkgconf,
               install: true,
               install_dir: join_paths(epoxy_libdir, 'pkgconfig'))

# Find Python for gen_dispatch
# XXX: With Meson 0.37 we should use
#   python = import('python3').find_python()
python = find_program('python3')

# Generates the dispatch tables
gen_dispatch_py = find_program('src/gen_dispatch.py')

gl_registry = files('registry/gl.xml')
egl_registry = files('registry/egl.xml')
glx_registry = files('registry/glx.xml')
wgl_registry = files('registry/wgl.xml')

libepoxy_inc = [
  include_directories('include'),
  include_directories('src'),
]

subdir('include/epoxy')
subdir('src')
subdir('test')

if get_option('enable-docs')
  doxygen = find_program('doxygen', required: false)
  if doxygen.found()
    subdir('doc')
  else
    message('Documentation disabled without doxygen')
  endif
endif