blob: 09b45bed007c806fda1058acb615eeaa90667bae [file] [log] [blame]
Dylan Bakerbc17ac52017-10-17 12:19:49 -07001<!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 <h1>The Mesa 3D Graphics Library</h1>
12</div>
13
14<iframe src="contents.html"></iframe>
15<div class="content">
16
17<h1>Compilation and Installation using Meson</h1>
18
Eric Engestromb0319d02018-11-29 13:16:42 +000019<ul>
Brian Paul45c6da52019-03-07 20:39:49 -070020 <li><a href="#intro">Introduction</a></li>
Eric Engestromb0319d02018-11-29 13:16:42 +000021 <li><a href="#basic">Basic Usage</a></li>
Brian Paul45c6da52019-03-07 20:39:49 -070022 <li><a href="#advanced">Advanced Usage</a></li>
Eric Engestromb0319d02018-11-29 13:16:42 +000023 <li><a href="#cross-compilation">Cross-compilation and 32-bit builds</a></li>
24</ul>
25
Brian Paul45c6da52019-03-07 20:39:49 -070026<h2 id="intro">1. Introduction</h2>
Dylan Bakerbc17ac52017-10-17 12:19:49 -070027
Brian Paul45c6da52019-03-07 20:39:49 -070028<p>For general information about Meson see the
29<a href="http://mesonbuild.com/">Meson website</a>.</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -070030
Brian Paul45c6da52019-03-07 20:39:49 -070031<p><strong>Mesa's Meson build system is generally considered stable and ready
32for production.</strong></p>
33
34<p>The Meson build of Mesa is tested on Linux, macOS, Cygwin and Haiku, FreeBSD,
Dylan Baker1da60662018-09-18 09:01:45 -070035DragonflyBSD, NetBSD, and should work on OpenBSD.</p>
Dylan Baker2aad12b2018-03-01 11:32:56 -080036
Brian Paul45c6da52019-03-07 20:39:49 -070037<p>If Meson is not already installed on your system, you can typically
38install it with your package installer. For example:</p>
39<pre>
40sudo apt-get install meson # Ubuntu
41</pre>
42or
43<pre>
44sudo dnf install meson # Fedora
45</pre>
46
Dylan Baker1da60662018-09-18 09:01:45 -070047<p><strong>Mesa requires Meson >= 0.45.0 to build.</strong>
Dylan Baker2aad12b2018-03-01 11:32:56 -080048
49Some older versions of meson do not check that they are too old and will error
50out in odd ways.
51</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -070052
Brian Paul45c6da52019-03-07 20:39:49 -070053<p>You'll also need <a href="https://ninja-build.org/">Ninja</a>.
54If it's not already installed, use apt-get or dnf to install
55the <em>ninja-build</em> package.
56</p>
57
58<h2 id="basic">2. Basic Usage</h2>
59
Dylan Bakerbc17ac52017-10-17 12:19:49 -070060<p>
61The meson program is used to configure the source directory and generates
62either a ninja build file or Visual Studio® build files. The latter must
Brian Paul45c6da52019-03-07 20:39:49 -070063be enabled via the <code>--backend</code> switch, as ninja is the default
64backend on all
65operating systems.
Dylan Bakerbc17ac52017-10-17 12:19:49 -070066</p>
67
Brian Paul45c6da52019-03-07 20:39:49 -070068<p>
69Meson only supports out-of-tree builds, and must be passed a
70directory to put built and generated sources into. We'll call that directory
71"build" here.
72It's recommended to create a
73<a href="http://mesonbuild.com/Using-multiple-build-directories.html">
74separate build directory</a> for each configuration you might want to use.
75</p>
76
77
78
79</p>
80
81<p>Basic configuration is done with:</p>
82
Dylan Bakerbc17ac52017-10-17 12:19:49 -070083<pre>
Brian Paul45c6da52019-03-07 20:39:49 -070084meson build/
Dylan Bakerbc17ac52017-10-17 12:19:49 -070085</pre>
86
87<p>
Brian Paul45c6da52019-03-07 20:39:49 -070088This will create the build directory.
89If any dependencies are missing, you can install them, or try to remove
90the dependency with a Meson configuration option (see below).
Eric Engestromc4c5c902019-01-17 16:26:26 +000091</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -070092
Eric Engestromc4c5c902019-01-17 16:26:26 +000093<p>
Brian Paul45c6da52019-03-07 20:39:49 -070094To review the options which Meson chose, run:
95</p>
96<pre>
97meson configure build/
98</pre>
99
100<p>
101Meson does not currently support listing configuration options before
102running "meson build/" but this feature is being discussed upstream.
Eric Engestrom00be88a2019-01-17 18:04:42 +0000103For now, we have a <code>bin/meson-options.py</code> script that prints
104the options for you.
105If that script doesn't work for some reason, you can always look in the
Eric Engestromc4c5c902019-01-17 16:26:26 +0000106<code>meson_options.txt</code> file at the root of the project.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700107</p>
108
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700109<p>
Brian Paul45c6da52019-03-07 20:39:49 -0700110With additional arguments <code>meson configure</code> can be used to change
111options for a previously configured build directory.
112All options passed to this command are in the form
113<code>-D "option"="value"</code>.
114For example:
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700115</p>
116
117<pre>
Brian Paul45c6da52019-03-07 20:39:49 -0700118meson configure build/ -Dprefix=/tmp/install -Dglx=true
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700119</pre>
120
121<p>
Eric Engestrom57fbc2a2018-05-14 16:39:42 +0100122Note that options taking lists (such as <code>platforms</code>) are
123<a href="http://mesonbuild.com/Build-options.html#using-build-options">a bit
124more complicated</a>, but the simplest form compatible with Mesa options
125is to use a comma to separate values (<code>-D platforms=drm,wayland</code>)
126and brackets to represent an empty list (<code>-D platforms=[]</code>).
127</p>
128
129<p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700130Once you've run the initial <code>meson</code> command successfully you can use
Brian Paul45c6da52019-03-07 20:39:49 -0700131your configured backend to build the project in your build directory:
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700132</p>
133
134<pre>
Brian Paul45c6da52019-03-07 20:39:49 -0700135ninja -C build/
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700136</pre>
137
138<p>
Brian Paul45c6da52019-03-07 20:39:49 -0700139The next step is to install the Mesa libraries, drivers, etc.
140This also finishes up some final steps of the build process (such as creating
141symbolic links for drivers). To install:
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700142</p>
143
Brian Paul45c6da52019-03-07 20:39:49 -0700144<pre>
145ninja -C build/ install
146</pre>
147
Dylan Bakera8004ef2018-10-22 19:33:08 -0700148<p>
Brian Paul45c6da52019-03-07 20:39:49 -0700149Note: autotools automatically updates translation files (used by the DRI
150configuration tool) as part of the build process,
151Meson does not do this. Instead, you will need do this:
Dylan Bakera8004ef2018-10-22 19:33:08 -0700152</p>
Brian Paul45c6da52019-03-07 20:39:49 -0700153<pre>
154ninja -C build/ xmlpool-pot xmlpool-update-po xmlpool-gmo
155</pre>
156
157<h2 id="advanced">3. Advanced Usage</h2>
Dylan Bakera8004ef2018-10-22 19:33:08 -0700158
Eric Engestrom67c55072018-05-14 16:45:31 +0100159<dl>
Brian Paul45c6da52019-03-07 20:39:49 -0700160
161<dt>Installation Location</dt>
162<dd>
163<p>
164Meson default to installing libGL.so in your system's main lib/ directory
165and DRI drivers to a dri/ subdirectory.
166</p>
167<p>
168Developers will often want to install Mesa to a testing directory rather
169than the system library directory.
170This can be done with the --prefix option. For example:
171</p>
Brian Paul16fb82d2019-03-08 10:31:11 -0700172<pre>
Brian Paul45c6da52019-03-07 20:39:49 -0700173meson --prefix="${PWD}/build/install" build/
Brian Paul16fb82d2019-03-08 10:31:11 -0700174</pre>
Brian Paul45c6da52019-03-07 20:39:49 -0700175<p>
176will put the final libraries and drivers into the build/install/
177directory.
178Then you can set LD_LIBRARY_PATH and LIBGL_DRIVERS_PATH to that location
179to run/test the driver.
180</p>
Brian Paul16fb82d2019-03-08 10:31:11 -0700181<p>
182Meson also honors <code>DESTDIR</code> for installs.
183</p>
Brian Paul45c6da52019-03-07 20:39:49 -0700184</dd>
185
Brian Paul16fb82d2019-03-08 10:31:11 -0700186<dt>Compiler Options</dt>
187<dd>
188<p>Meson supports the common CFLAGS, CXXFLAGS, etc. environment
189variables but their use is discouraged because of the many caveats
190in using them.
191</p>
192<p>Instead, it is recomended to use <code>-D${lang}_args</code> and
193<code>-D${lang}_link_args</code>. Among the benefits of these options
Dylan Baker0ff7eed2018-12-19 13:27:27 -0800194is that they are guaranteed to persist across rebuilds and reconfigurations.
Brian Paul16fb82d2019-03-08 10:31:11 -0700195</p>
196This example sets -fmax-errors for compiling C sources and -DMAGIC=123
197for C++ sources:
198</p>
199<p>
200<pre>
201meson builddir/ -Dc_args=-fmax-errors=10 -Dcpp_args=-DMAGIC=123
202</pre>
203</p>
204</dd>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700205
Brian Paul16fb82d2019-03-08 10:31:11 -0700206
207<dt>Compiler Specification</dt>
208<dd>
209<p>
210Meson supports the standard CC and CXX environment variables for
211changing the default compiler. Note that Meson does not allow
212changing the compilers in a configured builddir so you will need
Dylan Baker0ff7eed2018-12-19 13:27:27 -0800213to create a new build dir for a different compiler.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700214</p>
Brian Paul16fb82d2019-03-08 10:31:11 -0700215<p>
216This is an example of specifying the clang compilers and cleaning
217the build directory before reconfiguring with an extra C option:
218</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700219<pre>
Brian Paul16fb82d2019-03-08 10:31:11 -0700220CC=clang CXX=clang++ meson build-clang
221ninja -C build-clang
222ninja -C build-clang clean
223meson configure build -Dc_args="-Wno-typedef-redefinition"
224ninja -C build-clang
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700225</pre>
Dylan Bakere0829f92018-09-18 09:07:25 -0700226<p>
227The default compilers depends on your operating system. Meson supports most of
228the popular compilers, a complete list is available
229<a href="http://mesonbuild.com/Reference-tables.html#compiler-ids">here</a>.
230</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700231</dd>
232
Brian Paul45c6da52019-03-07 20:39:49 -0700233<dt>LLVM</dt>
Dylan Bakerbe56f8a2018-09-18 09:09:47 -0700234<dd><p>Meson includes upstream logic to wrap llvm-config using its standard
Dylan Bakera57dbe62018-12-20 11:46:08 -0800235dependency interface.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700236</p></dd>
Dylan Bakera57dbe62018-12-20 11:46:08 -0800237
238<dd><p>
239As of meson 0.49.0 meson also has the concept of a
240<a href="https://mesonbuild.com/Native-environments.html">"native file"</a>,
241these files provide information about the native build environment (as opposed
242to a cross build environment). They are ini formatted and can override where to
243find llvm-config:
244
245custom-llvm.ini
246<pre>
247 [binaries]
248 llvm-config = '/usr/local/bin/llvm/llvm-config'
249</pre>
250
251Then configure meson:
252
253<pre>
254 meson builddir/ --native-file custom-llvm.ini
255</pre>
256</p></dd>
257
258<dd><p>
259For selecting llvm-config for cross compiling a
260<a href="https://mesonbuild.com/Cross-compilation.html#defining-the-environment">"cross file"</a>
261should be used. It uses the same format as the native file above:
262
263cross-llvm.ini
264<pre>
265 [binaries]
266 ...
267 llvm-config = '/usr/lib/llvm-config-32'
268</pre>
269
270Then configure meson:
271
272<pre>
273 meson builddir/ --cross-file cross-llvm.ini
274</pre>
275
276See the <a href="#cross-compilation">Cross Compilation</a> section for more information.
277</dd></p>
278
279<dd><p>
280For older versions of meson <code>$PATH</code> (or <code>%PATH%</code> on
281windows) will be searched for llvm-config (and llvm-config$version and
282llvm-config-$version), you can override this environment variable to control
283the search: <code>PATH=/path/with/llvm-config:$PATH meson build</code>.
284</dd></p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700285</dl>
286
Dylan Baker2aad12b2018-03-01 11:32:56 -0800287<dl>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700288<dt><code>PKG_CONFIG_PATH</code></dt>
289<dd><p>The
290<code>pkg-config</code> utility is a hard requirement for configuring and
Dylan Baker2aad12b2018-03-01 11:32:56 -0800291building Mesa on Unix-like systems. It is used to search for external libraries
292on the system. This environment variable is used to control the search path for
293<code>pkg-config</code>. For instance, setting
294<code>PKG_CONFIG_PATH=/usr/X11R6/lib/pkgconfig</code> will search for package
295metadata in <code>/usr/X11R6</code> before the standard directories.</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700296</dd>
297</dl>
298
299<p>
300One of the oddities of meson is that some options are different when passed to
301the <code>meson</code> than to <code>meson configure</code>. These options are
302passed as --option=foo to <code>meson</code>, but -Doption=foo to <code>meson
303configure</code>. Mesa defined options are always passed as -Doption=foo.
Eric Engestrom67c55072018-05-14 16:45:31 +0100304</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700305
306<p>For those coming from autotools be aware of the following:</p>
307
308<dl>
309<dt><code>--buildtype/-Dbuildtype</code></dt>
310<dd><p>This option will set the compiler debug/optimisation levels to aid
311debugging the Mesa libraries.</p>
312
Eric Engestrom37d44e22018-05-14 16:47:57 +0100313<p>Note that in meson this defaults to <code>debugoptimized</code>, and
314not setting it to <code>release</code> will yield non-optimal
315performance and binary size. Not using <code>debug</code> may interfere
316with debugging as some code and validation will be optimized away.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700317</p>
318
Eric Engestrom37d44e22018-05-14 16:47:57 +0100319<p> For those wishing to pass their own optimization flags, use the <code>plain</code>
Dylan Baker2aad12b2018-03-01 11:32:56 -0800320buildtype, which causes meson to inject no additional compiler arguments, only
321those in the C/CXXFLAGS and those that mesa itself defines.</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700322</dd>
323</dl>
324
325<dl>
326<dt><code>-Db_ndebug</code></dt>
Eric Engestrom37d44e22018-05-14 16:47:57 +0100327<dd><p>This option controls assertions in meson projects. When set to <code>false</code>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700328(the default) assertions are enabled, when set to true they are disabled. This
329is unrelated to the <code>buildtype</code>; setting the latter to
330<code>release</code> will not turn off assertions.
331</p>
332</dd>
333</dl>
Eric Engestrom67c55072018-05-14 16:45:31 +0100334
Brian Paul45c6da52019-03-07 20:39:49 -0700335<h2 id="cross-compilation">4. Cross-compilation and 32-bit builds</h2>
Eric Engestromb0319d02018-11-29 13:16:42 +0000336
337<p><a href="https://mesonbuild.com/Cross-compilation.html">Meson supports
338cross-compilation</a> by specifying a number of binary paths and
339settings in a file and passing this file to <code>meson</code> or
340<code>meson configure</code> with the <code>--cross-file</code>
341parameter.</p>
342
343<p>This file can live at any location, but you can use the bare filename
344(without the folder path) if you put it in $XDG_DATA_HOME/meson/cross or
345~/.local/share/meson/cross</p>
346
347<p>Below are a few example of cross files, but keep in mind that you
348will likely have to alter them for your system.</p>
349
350<p>
Eric Engestrom393a7562019-01-03 16:01:18 +0000351Those running on ArchLinux can use the AUR-maintained packages for some
352of those, as they'll have the right values for your system:
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</p>
358
359<p>
Eric Engestromb0319d02018-11-29 13:16:42 +000036032-bit build on x86 linux:
361<pre>
362[binaries]
363c = '/usr/bin/gcc'
364cpp = '/usr/bin/g++'
365ar = '/usr/bin/gcc-ar'
366strip = '/usr/bin/strip'
367pkgconfig = '/usr/bin/pkg-config-32'
368llvm-config = '/usr/bin/llvm-config32'
369
370[properties]
371c_args = ['-m32']
372c_link_args = ['-m32']
373cpp_args = ['-m32']
374cpp_link_args = ['-m32']
375
376[host_machine]
377system = 'linux'
378cpu_family = 'x86'
379cpu = 'i686'
380endian = 'little'
381</pre>
382</p>
383
384<p>
38564-bit build on ARM linux:
386<pre>
387[binaries]
388c = '/usr/bin/aarch64-linux-gnu-gcc'
389cpp = '/usr/bin/aarch64-linux-gnu-g++'
Eric Engestrom8b363bc2019-01-03 15:44:42 +0000390ar = '/usr/bin/aarch64-linux-gnu-gcc-ar'
Eric Engestromb0319d02018-11-29 13:16:42 +0000391strip = '/usr/bin/aarch64-linux-gnu-strip'
392pkgconfig = '/usr/bin/aarch64-linux-gnu-pkg-config'
393exe_wrapper = '/usr/bin/qemu-aarch64-static'
394
395[host_machine]
396system = 'linux'
Eric Engestrom8b363bc2019-01-03 15:44:42 +0000397cpu_family = 'aarch64'
Eric Engestromb0319d02018-11-29 13:16:42 +0000398cpu = 'aarch64'
399endian = 'little'
400</pre>
401</p>
402
403<p>
40464-bit build on x86 windows:
405<pre>
406[binaries]
407c = '/usr/bin/x86_64-w64-mingw32-gcc'
408cpp = '/usr/bin/x86_64-w64-mingw32-g++'
409ar = '/usr/bin/x86_64-w64-mingw32-ar'
410strip = '/usr/bin/x86_64-w64-mingw32-strip'
411pkgconfig = '/usr/bin/x86_64-w64-mingw32-pkg-config'
412exe_wrapper = 'wine'
413
414[host_machine]
415system = 'windows'
416cpu_family = 'x86_64'
417cpu = 'i686'
418endian = 'little'
419</pre>
420</p>
421
Eric Engestrom67c55072018-05-14 16:45:31 +0100422</div>
423</body>
424</html>