radv: Unset vk_info in radv_image_create_layout.
[mesa.git] / docs / meson.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html lang="en">
3 <head>
4 <meta http-equiv="content-type" content="text/html; charset=utf-8">
5 <title>Compilation and Installation Using Meson</title>
6 <link rel="stylesheet" type="text/css" href="mesa.css">
7 </head>
8 <body>
9
10 <div class="header">
11 The Mesa 3D Graphics Library
12 </div>
13
14 <iframe src="contents.html"></iframe>
15 <div class="content">
16
17 <h1>Compilation and Installation Using Meson</h1>
18
19 <ul>
20 <li><a href="#intro">Introduction</a></li>
21 <li><a href="#basic">Basic Usage</a></li>
22 <li><a href="#advanced">Advanced Usage</a></li>
23 <li><a href="#cross-compilation">Cross-compilation and 32-bit builds</a></li>
24 </ul>
25
26 <h2 id="intro">1. Introduction</h2>
27
28 <p>For general information about Meson see the
29 <a href="https://mesonbuild.com/">Meson website</a>.</p>
30
31 <p><strong>Mesa's Meson build system is generally considered stable and ready
32 for production.</strong></p>
33
34 <p>The Meson build of Mesa is tested on Linux, macOS, Cygwin and Haiku, FreeBSD,
35 DragonflyBSD, NetBSD, and should work on OpenBSD.</p>
36
37 <p>If Meson is not already installed on your system, you can typically
38 install it with your package installer. For example:</p>
39 <pre>
40 sudo apt-get install meson # Ubuntu
41 </pre>
42 or
43 <pre>
44 sudo dnf install meson # Fedora
45 </pre>
46
47 <p><strong>Mesa requires Meson &gt;= 0.46.0 to build.</strong>
48
49 Some older versions of meson do not check that they are too old and will error
50 out in odd ways.
51 </p>
52
53 <p>You'll also need <a href="https://ninja-build.org/">Ninja</a>.
54 If it's not already installed, use apt-get or dnf to install
55 the <em>ninja-build</em> package.
56 </p>
57
58 <h2 id="basic">2. Basic Usage</h2>
59
60 <p>
61 The meson program is used to configure the source directory and generates
62 either a ninja build file or Visual Studio® build files. The latter must
63 be enabled via the <code>--backend</code> switch, as ninja is the default
64 backend on all operating systems.
65 </p>
66
67 <p>
68 Meson only supports out-of-tree builds, and must be passed a
69 directory to put built and generated sources into. We'll call that directory
70 "build" here.
71 It's recommended to create a
72 <a href="https://mesonbuild.com/Using-multiple-build-directories.html">
73 separate build directory</a> for each configuration you might want to use.
74 </p>
75
76
77
78 <p>Basic configuration is done with:</p>
79
80 <pre>
81 meson build/
82 </pre>
83
84 <p>
85 This will create the build directory.
86 If any dependencies are missing, you can install them, or try to remove
87 the dependency with a Meson configuration option (see below).
88 </p>
89
90 <p>
91 To review the options which Meson chose, run:
92 </p>
93 <pre>
94 meson configure build/
95 </pre>
96
97 <p>
98 Meson does not currently support listing configuration options before
99 running "meson build/" but this feature is being discussed upstream.
100 For now, we have a <code>bin/meson-options.py</code> script that prints
101 the options for you.
102 If that script doesn't work for some reason, you can always look in the
103 <a href="https://gitlab.freedesktop.org/mesa/mesa/blob/master/meson_options.txt">
104 meson_options.txt</a> file at the root of the project.
105 </p>
106
107 <p>
108 With additional arguments <code>meson configure</code> can be used to change
109 options for a previously configured build directory.
110 All options passed to this command are in the form
111 <code>-D "option"="value"</code>.
112 For example:
113 </p>
114
115 <pre>
116 meson configure build/ -Dprefix=/tmp/install -Dglx=true
117 </pre>
118
119 <p>
120 Note that options taking lists (such as <code>platforms</code>) are
121 <a href="https://mesonbuild.com/Build-options.html#using-build-options">a bit
122 more complicated</a>, but the simplest form compatible with Mesa options
123 is to use a comma to separate values (<code>-D platforms=drm,wayland</code>)
124 and brackets to represent an empty list (<code>-D platforms=[]</code>).
125 </p>
126
127 <p>
128 Once you've run the initial <code>meson</code> command successfully you can use
129 your configured backend to build the project in your build directory:
130 </p>
131
132 <pre>
133 ninja -C build/
134 </pre>
135
136 <p>
137 The next step is to install the Mesa libraries, drivers, etc.
138 This also finishes up some final steps of the build process (such as creating
139 symbolic links for drivers). To install:
140 </p>
141
142 <pre>
143 ninja -C build/ install
144 </pre>
145
146 <p>
147 Note: autotools automatically updated translation files (used by the DRI
148 configuration tool) as part of the build process,
149 Meson does not do this. Instead, you will need do this:
150 </p>
151 <pre>
152 ninja -C build/ xmlpool-pot xmlpool-update-po xmlpool-gmo
153 </pre>
154
155 <h2 id="advanced">3. Advanced Usage</h2>
156
157 <dl>
158
159 <dt>Installation Location</dt>
160 <dd>
161 <p>
162 Meson default to installing libGL.so in your system's main lib/ directory
163 and DRI drivers to a dri/ subdirectory.
164 </p>
165 <p>
166 Developers will often want to install Mesa to a testing directory rather
167 than the system library directory.
168 This can be done with the --prefix option. For example:
169 </p>
170 <pre>
171 meson --prefix="${PWD}/build/install" build/
172 </pre>
173 <p>
174 will put the final libraries and drivers into the build/install/
175 directory.
176 Then you can set LD_LIBRARY_PATH and LIBGL_DRIVERS_PATH to that location
177 to run/test the driver.
178 </p>
179 <p>
180 Meson also honors <code>DESTDIR</code> for installs.
181 </p>
182 </dd>
183
184 <dt>Compiler Options</dt>
185 <dd>
186 <p>Meson supports the common CFLAGS, CXXFLAGS, etc. environment
187 variables but their use is discouraged because of the many caveats
188 in using them.
189 </p>
190 <p>Instead, it is recomended to use <code>-D${lang}_args</code> and
191 <code>-D${lang}_link_args</code>. Among the benefits of these options
192 is that they are guaranteed to persist across rebuilds and reconfigurations.
193 </p>
194 <p>
195 This example sets -fmax-errors for compiling C sources and -DMAGIC=123
196 for C++ sources:
197 </p>
198 <pre>
199 meson builddir/ -Dc_args=-fmax-errors=10 -Dcpp_args=-DMAGIC=123
200 </pre>
201 </dd>
202
203
204 <dt>Compiler Specification</dt>
205 <dd>
206 <p>
207 Meson supports the standard CC and CXX environment variables for
208 changing the default compiler. Note that Meson does not allow
209 changing the compilers in a configured builddir so you will need
210 to create a new build dir for a different compiler.
211 </p>
212 <p>
213 This is an example of specifying the clang compilers and cleaning
214 the build directory before reconfiguring with an extra C option:
215 </p>
216 <pre>
217 CC=clang CXX=clang++ meson build-clang
218 ninja -C build-clang
219 ninja -C build-clang clean
220 meson configure build -Dc_args="-Wno-typedef-redefinition"
221 ninja -C build-clang
222 </pre>
223 <p>
224 The default compilers depends on your operating system. Meson supports most of
225 the popular compilers, a complete list is available
226 <a href="https://mesonbuild.com/Reference-tables.html#compiler-ids">here</a>.
227 </p>
228 </dd>
229
230 <dt>LLVM</dt>
231 <dd><p>Meson includes upstream logic to wrap llvm-config using its standard
232 dependency interface.
233 </p></dd>
234
235 <dd><p>
236 As of meson 0.49.0 meson also has the concept of a
237 <a href="https://mesonbuild.com/Native-environments.html">"native file"</a>,
238 these files provide information about the native build environment (as opposed
239 to a cross build environment). They are ini formatted and can override where to
240 find llvm-config:
241 </p>
242
243 custom-llvm.ini
244 <pre>
245 [binaries]
246 llvm-config = '/usr/local/bin/llvm/llvm-config'
247 </pre>
248
249 Then configure meson:
250
251 <pre>
252 meson builddir/ --native-file custom-llvm.ini
253 </pre>
254 </dd>
255
256 <dd><p>
257 Meson &lt; 0.49 doesn't support native files, so to specify a custom
258 <code>llvm-config</code> you need to modify your <code>$PATH</code> (or
259 <code>%PATH%</code> on windows), which will be searched for
260 <code>llvm-config</code>, <code>llvm-config<i>$version</i></code>,
261 and <code>llvm-config-<i>$version</i></code>:
262 </p>
263 <pre>
264 PATH=/path/to/folder/with/llvm-config:$PATH meson build
265 </pre>
266 </dd>
267
268 <dd><p>
269 For selecting llvm-config for cross compiling a
270 <a href="https://mesonbuild.com/Cross-compilation.html#defining-the-environment">"cross file"</a>
271 should be used. It uses the same format as the native file above:
272 </p>
273
274 <p>cross-llvm.ini</p>
275 <pre>
276 [binaries]
277 ...
278 llvm-config = '/usr/lib/llvm-config-32'
279 </pre>
280
281 <p>Then configure meson:</p>
282 <pre>
283 meson builddir/ --cross-file cross-llvm.ini
284 </pre>
285
286 See the <a href="#cross-compilation">Cross Compilation</a> section for more information.
287 </dd>
288
289 <dt><code>PKG_CONFIG_PATH</code></dt>
290 <dd><p>The
291 <code>pkg-config</code> utility is a hard requirement for configuring and
292 building Mesa on Unix-like systems. It is used to search for external libraries
293 on the system. This environment variable is used to control the search path for
294 <code>pkg-config</code>. For instance, setting
295 <code>PKG_CONFIG_PATH=/usr/X11R6/lib/pkgconfig</code> will search for package
296 metadata in <code>/usr/X11R6</code> before the standard directories.</p>
297 </dd>
298 </dl>
299
300 <p>
301 One of the oddities of meson is that some options are different when passed to
302 the <code>meson</code> than to <code>meson configure</code>. These options are
303 passed as --option=foo to <code>meson</code>, but -Doption=foo to <code>meson
304 configure</code>. Mesa defined options are always passed as -Doption=foo.
305 </p>
306
307 <p>For those coming from autotools be aware of the following:</p>
308
309 <dl>
310 <dt><code>--buildtype/-Dbuildtype</code></dt>
311 <dd><p>This option will set the compiler debug/optimisation levels to aid
312 debugging the Mesa libraries.</p>
313
314 <p>Note that in meson this defaults to <code>debugoptimized</code>, and
315 not setting it to <code>release</code> will yield non-optimal
316 performance and binary size. Not using <code>debug</code> may interfere
317 with debugging as some code and validation will be optimized away.
318 </p>
319
320 <p> For those wishing to pass their own optimization flags, use the <code>plain</code>
321 buildtype, which causes meson to inject no additional compiler arguments, only
322 those in the C/CXXFLAGS and those that mesa itself defines.</p>
323 </dd>
324
325 <dt><code>-Db_ndebug</code></dt>
326 <dd><p>This option controls assertions in meson projects. When set to <code>false</code>
327 (the default) assertions are enabled, when set to true they are disabled. This
328 is unrelated to the <code>buildtype</code>; setting the latter to
329 <code>release</code> will not turn off assertions.
330 </p>
331 </dd>
332 </dl>
333
334 <h2 id="cross-compilation">4. Cross-compilation and 32-bit builds</h2>
335
336 <p><a href="https://mesonbuild.com/Cross-compilation.html">Meson supports
337 cross-compilation</a> by specifying a number of binary paths and
338 settings in a file and passing this file to <code>meson</code> or
339 <code>meson configure</code> with the <code>--cross-file</code>
340 parameter.</p>
341
342 <p>This file can live at any location, but you can use the bare filename
343 (without the folder path) if you put it in $XDG_DATA_HOME/meson/cross or
344 ~/.local/share/meson/cross</p>
345
346 <p>Below are a few example of cross files, but keep in mind that you
347 will likely have to alter them for your system.</p>
348
349 <p>
350 Those running on ArchLinux can use the AUR-maintained packages for some
351 of those, as they'll have the right values for your system:
352 </p>
353 <ul>
354 <li><a href="https://aur.archlinux.org/packages/meson-cross-x86-linux-gnu">meson-cross-x86-linux-gnu</a></li>
355 <li><a href="https://aur.archlinux.org/packages/meson-cross-aarch64-linux-gnu">meson-cross-aarch64-linux-gnu</a></li>
356 </ul>
357
358 <p>
359 32-bit build on x86 linux:
360 </p>
361 <pre>
362 [binaries]
363 c = '/usr/bin/gcc'
364 cpp = '/usr/bin/g++'
365 ar = '/usr/bin/gcc-ar'
366 strip = '/usr/bin/strip'
367 pkgconfig = '/usr/bin/pkg-config-32'
368 llvm-config = '/usr/bin/llvm-config32'
369
370 [properties]
371 c_args = ['-m32']
372 c_link_args = ['-m32']
373 cpp_args = ['-m32']
374 cpp_link_args = ['-m32']
375
376 [host_machine]
377 system = 'linux'
378 cpu_family = 'x86'
379 cpu = 'i686'
380 endian = 'little'
381 </pre>
382
383 <p>
384 64-bit build on ARM linux:
385 </p>
386 <pre>
387 [binaries]
388 c = '/usr/bin/aarch64-linux-gnu-gcc'
389 cpp = '/usr/bin/aarch64-linux-gnu-g++'
390 ar = '/usr/bin/aarch64-linux-gnu-gcc-ar'
391 strip = '/usr/bin/aarch64-linux-gnu-strip'
392 pkgconfig = '/usr/bin/aarch64-linux-gnu-pkg-config'
393 exe_wrapper = '/usr/bin/qemu-aarch64-static'
394
395 [host_machine]
396 system = 'linux'
397 cpu_family = 'aarch64'
398 cpu = 'aarch64'
399 endian = 'little'
400 </pre>
401
402 <p>
403 64-bit build on x86 windows:
404 </p>
405 <pre>
406 [binaries]
407 c = '/usr/bin/x86_64-w64-mingw32-gcc'
408 cpp = '/usr/bin/x86_64-w64-mingw32-g++'
409 ar = '/usr/bin/x86_64-w64-mingw32-ar'
410 strip = '/usr/bin/x86_64-w64-mingw32-strip'
411 pkgconfig = '/usr/bin/x86_64-w64-mingw32-pkg-config'
412 exe_wrapper = 'wine'
413
414 [host_machine]
415 system = 'windows'
416 cpu_family = 'x86_64'
417 cpu = 'i686'
418 endian = 'little'
419 </pre>
420
421 </div>
422 </body>
423 </html>