blob: 0291f90658b483aea5b837855f299816d66ef066 [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">
Erik Faye-Lund6e0e5502019-05-06 13:13:11 +02005 <title>Compilation and Installation Using Meson</title>
Dylan Bakerbc17ac52017-10-17 12:19:49 -07006 <link rel="stylesheet" type="text/css" href="mesa.css">
7</head>
8<body>
9
10<div class="header">
Erik Faye-Lundecdab0d2019-05-06 13:26:47 +020011 The Mesa 3D Graphics Library
Dylan Bakerbc17ac52017-10-17 12:19:49 -070012</div>
13
14<iframe src="contents.html"></iframe>
15<div class="content">
16
Erik Faye-Lund6e0e5502019-05-06 13:13:11 +020017<h1>Compilation and Installation Using Meson</h1>
Dylan Bakerbc17ac52017-10-17 12:19:49 -070018
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
Dylan Bakerbc2d73c2019-09-30 11:02:31 -070029<a href="https://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
Eric Engestrom4bf7e7b2019-07-30 00:44:21 +010047<p><strong>Mesa requires Meson &gt;= 0.46.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
Dylan Baker4913ad92019-09-30 11:02:41 -070064backend on all operating systems.
Dylan Bakerbc17ac52017-10-17 12:19:49 -070065</p>
66
Brian Paul45c6da52019-03-07 20:39:49 -070067<p>
68Meson only supports out-of-tree builds, and must be passed a
69directory to put built and generated sources into. We'll call that directory
70"build" here.
71It's recommended to create a
Dylan Bakerbc2d73c2019-09-30 11:02:31 -070072<a href="https://mesonbuild.com/Using-multiple-build-directories.html">
Brian Paul45c6da52019-03-07 20:39:49 -070073separate build directory</a> for each configuration you might want to use.
74</p>
75
76
77
Brian Paul45c6da52019-03-07 20:39:49 -070078<p>Basic configuration is done with:</p>
79
Dylan Bakerbc17ac52017-10-17 12:19:49 -070080<pre>
Brian Paul45c6da52019-03-07 20:39:49 -070081meson build/
Dylan Bakerbc17ac52017-10-17 12:19:49 -070082</pre>
83
84<p>
Brian Paul45c6da52019-03-07 20:39:49 -070085This will create the build directory.
86If any dependencies are missing, you can install them, or try to remove
87the dependency with a Meson configuration option (see below).
Eric Engestromc4c5c902019-01-17 16:26:26 +000088</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -070089
Eric Engestromc4c5c902019-01-17 16:26:26 +000090<p>
Brian Paul45c6da52019-03-07 20:39:49 -070091To review the options which Meson chose, run:
92</p>
93<pre>
94meson configure build/
95</pre>
96
97<p>
98Meson does not currently support listing configuration options before
99running "meson build/" but this feature is being discussed upstream.
Eric Engestrom00be88a2019-01-17 18:04:42 +0000100For now, we have a <code>bin/meson-options.py</code> script that prints
101the options for you.
102If that script doesn't work for some reason, you can always look in the
Brian Paule547a1c2019-03-11 19:58:04 -0600103<a href="https://gitlab.freedesktop.org/mesa/mesa/blob/master/meson_options.txt">
104meson_options.txt</a> file at the root of the project.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700105</p>
106
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700107<p>
Brian Paul45c6da52019-03-07 20:39:49 -0700108With additional arguments <code>meson configure</code> can be used to change
109options for a previously configured build directory.
110All options passed to this command are in the form
111<code>-D "option"="value"</code>.
112For example:
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700113</p>
114
115<pre>
Brian Paul45c6da52019-03-07 20:39:49 -0700116meson configure build/ -Dprefix=/tmp/install -Dglx=true
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700117</pre>
118
119<p>
Eric Engestrom57fbc2a2018-05-14 16:39:42 +0100120Note that options taking lists (such as <code>platforms</code>) are
Dylan Bakerbc2d73c2019-09-30 11:02:31 -0700121<a href="https://mesonbuild.com/Build-options.html#using-build-options">a bit
Eric Engestrom57fbc2a2018-05-14 16:39:42 +0100122more complicated</a>, but the simplest form compatible with Mesa options
123is to use a comma to separate values (<code>-D platforms=drm,wayland</code>)
124and brackets to represent an empty list (<code>-D platforms=[]</code>).
125</p>
126
127<p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700128Once you've run the initial <code>meson</code> command successfully you can use
Brian Paul45c6da52019-03-07 20:39:49 -0700129your configured backend to build the project in your build directory:
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700130</p>
131
132<pre>
Brian Paul45c6da52019-03-07 20:39:49 -0700133ninja -C build/
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700134</pre>
135
136<p>
Brian Paul45c6da52019-03-07 20:39:49 -0700137The next step is to install the Mesa libraries, drivers, etc.
138This also finishes up some final steps of the build process (such as creating
139symbolic links for drivers). To install:
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700140</p>
141
Brian Paul45c6da52019-03-07 20:39:49 -0700142<pre>
143ninja -C build/ install
144</pre>
145
Dylan Bakera8004ef2018-10-22 19:33:08 -0700146<p>
Eric Engestrom88ed5f62019-04-24 13:19:51 +0100147Note: autotools automatically updated translation files (used by the DRI
Brian Paul45c6da52019-03-07 20:39:49 -0700148configuration tool) as part of the build process,
149Meson does not do this. Instead, you will need do this:
Dylan Bakera8004ef2018-10-22 19:33:08 -0700150</p>
Brian Paul45c6da52019-03-07 20:39:49 -0700151<pre>
152ninja -C build/ xmlpool-pot xmlpool-update-po xmlpool-gmo
153</pre>
154
155<h2 id="advanced">3. Advanced Usage</h2>
Dylan Bakera8004ef2018-10-22 19:33:08 -0700156
Eric Engestrom67c55072018-05-14 16:45:31 +0100157<dl>
Brian Paul45c6da52019-03-07 20:39:49 -0700158
159<dt>Installation Location</dt>
160<dd>
161<p>
162Meson default to installing libGL.so in your system's main lib/ directory
163and DRI drivers to a dri/ subdirectory.
164</p>
165<p>
166Developers will often want to install Mesa to a testing directory rather
167than the system library directory.
168This can be done with the --prefix option. For example:
169</p>
Brian Paul16fb82d2019-03-08 10:31:11 -0700170<pre>
Brian Paul45c6da52019-03-07 20:39:49 -0700171meson --prefix="${PWD}/build/install" build/
Brian Paul16fb82d2019-03-08 10:31:11 -0700172</pre>
Brian Paul45c6da52019-03-07 20:39:49 -0700173<p>
174will put the final libraries and drivers into the build/install/
175directory.
176Then you can set LD_LIBRARY_PATH and LIBGL_DRIVERS_PATH to that location
177to run/test the driver.
178</p>
Brian Paul16fb82d2019-03-08 10:31:11 -0700179<p>
180Meson also honors <code>DESTDIR</code> for installs.
181</p>
Brian Paul45c6da52019-03-07 20:39:49 -0700182</dd>
183
Brian Paul16fb82d2019-03-08 10:31:11 -0700184<dt>Compiler Options</dt>
185<dd>
186<p>Meson supports the common CFLAGS, CXXFLAGS, etc. environment
187variables but their use is discouraged because of the many caveats
188in 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
Dylan Baker0ff7eed2018-12-19 13:27:27 -0800192is that they are guaranteed to persist across rebuilds and reconfigurations.
Brian Paul16fb82d2019-03-08 10:31:11 -0700193</p>
Erik Faye-Lund8ef86c92019-04-18 16:13:44 +0200194<p>
Brian Paul16fb82d2019-03-08 10:31:11 -0700195This example sets -fmax-errors for compiling C sources and -DMAGIC=123
196for C++ sources:
197</p>
Brian Paul16fb82d2019-03-08 10:31:11 -0700198<pre>
199meson builddir/ -Dc_args=-fmax-errors=10 -Dcpp_args=-DMAGIC=123
200</pre>
Brian Paul16fb82d2019-03-08 10:31:11 -0700201</dd>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700202
Brian Paul16fb82d2019-03-08 10:31:11 -0700203
204<dt>Compiler Specification</dt>
205<dd>
206<p>
207Meson supports the standard CC and CXX environment variables for
208changing the default compiler. Note that Meson does not allow
209changing the compilers in a configured builddir so you will need
Dylan Baker0ff7eed2018-12-19 13:27:27 -0800210to create a new build dir for a different compiler.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700211</p>
Brian Paul16fb82d2019-03-08 10:31:11 -0700212<p>
213This is an example of specifying the clang compilers and cleaning
214the build directory before reconfiguring with an extra C option:
215</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700216<pre>
Brian Paul16fb82d2019-03-08 10:31:11 -0700217CC=clang CXX=clang++ meson build-clang
218ninja -C build-clang
219ninja -C build-clang clean
220meson configure build -Dc_args="-Wno-typedef-redefinition"
221ninja -C build-clang
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700222</pre>
Dylan Bakere0829f92018-09-18 09:07:25 -0700223<p>
224The default compilers depends on your operating system. Meson supports most of
225the popular compilers, a complete list is available
Dylan Bakerbc2d73c2019-09-30 11:02:31 -0700226<a href="https://mesonbuild.com/Reference-tables.html#compiler-ids">here</a>.
Dylan Bakere0829f92018-09-18 09:07:25 -0700227</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700228</dd>
229
Brian Paul45c6da52019-03-07 20:39:49 -0700230<dt>LLVM</dt>
Dylan Bakerbe56f8a2018-09-18 09:09:47 -0700231<dd><p>Meson includes upstream logic to wrap llvm-config using its standard
Dylan Bakera57dbe62018-12-20 11:46:08 -0800232dependency interface.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700233</p></dd>
Dylan Bakera57dbe62018-12-20 11:46:08 -0800234
235<dd><p>
236As of meson 0.49.0 meson also has the concept of a
237<a href="https://mesonbuild.com/Native-environments.html">"native file"</a>,
238these files provide information about the native build environment (as opposed
239to a cross build environment). They are ini formatted and can override where to
240find llvm-config:
Erik Faye-Lund0ea4ef22019-04-18 16:16:06 +0200241</p>
Dylan Bakera57dbe62018-12-20 11:46:08 -0800242
243custom-llvm.ini
244<pre>
245 [binaries]
246 llvm-config = '/usr/local/bin/llvm/llvm-config'
247</pre>
248
249Then configure meson:
250
251<pre>
252 meson builddir/ --native-file custom-llvm.ini
253</pre>
Erik Faye-Lund0ea4ef22019-04-18 16:16:06 +0200254</dd>
Dylan Bakera57dbe62018-12-20 11:46:08 -0800255
256<dd><p>
Eric Engestroma563bb92019-07-31 11:49:03 +0100257Meson &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>,
261and <code>llvm-config-<i>$version</i></code>:
262</p>
263<pre>
264PATH=/path/to/folder/with/llvm-config:$PATH meson build
265</pre>
266</dd>
267
268<dd><p>
Dylan Bakera57dbe62018-12-20 11:46:08 -0800269For selecting llvm-config for cross compiling a
270<a href="https://mesonbuild.com/Cross-compilation.html#defining-the-environment">"cross file"</a>
271should be used. It uses the same format as the native file above:
Erik Faye-Lund767c5172019-04-18 16:27:26 +0200272</p>
Dylan Bakera57dbe62018-12-20 11:46:08 -0800273
Erik Faye-Lund767c5172019-04-18 16:27:26 +0200274<p>cross-llvm.ini</p>
Dylan Bakera57dbe62018-12-20 11:46:08 -0800275<pre>
276 [binaries]
277 ...
278 llvm-config = '/usr/lib/llvm-config-32'
279</pre>
280
Erik Faye-Lund767c5172019-04-18 16:27:26 +0200281<p>Then configure meson:</p>
Dylan Bakera57dbe62018-12-20 11:46:08 -0800282<pre>
283 meson builddir/ --cross-file cross-llvm.ini
284</pre>
285
286See the <a href="#cross-compilation">Cross Compilation</a> section for more information.
Erik Faye-Lund767c5172019-04-18 16:27:26 +0200287</dd>
Dylan Bakera57dbe62018-12-20 11:46:08 -0800288
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700289<dt><code>PKG_CONFIG_PATH</code></dt>
290<dd><p>The
291<code>pkg-config</code> utility is a hard requirement for configuring and
Dylan Baker2aad12b2018-03-01 11:32:56 -0800292building Mesa on Unix-like systems. It is used to search for external libraries
293on 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
296metadata in <code>/usr/X11R6</code> before the standard directories.</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700297</dd>
298</dl>
299
300<p>
301One of the oddities of meson is that some options are different when passed to
302the <code>meson</code> than to <code>meson configure</code>. These options are
303passed as --option=foo to <code>meson</code>, but -Doption=foo to <code>meson
304configure</code>. Mesa defined options are always passed as -Doption=foo.
Eric Engestrom67c55072018-05-14 16:45:31 +0100305</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700306
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
312debugging the Mesa libraries.</p>
313
Eric Engestrom37d44e22018-05-14 16:47:57 +0100314<p>Note that in meson this defaults to <code>debugoptimized</code>, and
315not setting it to <code>release</code> will yield non-optimal
316performance and binary size. Not using <code>debug</code> may interfere
317with debugging as some code and validation will be optimized away.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700318</p>
319
Eric Engestrom37d44e22018-05-14 16:47:57 +0100320<p> For those wishing to pass their own optimization flags, use the <code>plain</code>
Dylan Baker2aad12b2018-03-01 11:32:56 -0800321buildtype, which causes meson to inject no additional compiler arguments, only
322those in the C/CXXFLAGS and those that mesa itself defines.</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700323</dd>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700324
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700325<dt><code>-Db_ndebug</code></dt>
Eric Engestrom37d44e22018-05-14 16:47:57 +0100326<dd><p>This option controls assertions in meson projects. When set to <code>false</code>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700327(the default) assertions are enabled, when set to true they are disabled. This
328is 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>
Eric Engestrom67c55072018-05-14 16:45:31 +0100333
Brian Paul45c6da52019-03-07 20:39:49 -0700334<h2 id="cross-compilation">4. Cross-compilation and 32-bit builds</h2>
Eric Engestromb0319d02018-11-29 13:16:42 +0000335
336<p><a href="https://mesonbuild.com/Cross-compilation.html">Meson supports
337cross-compilation</a> by specifying a number of binary paths and
338settings in a file and passing this file to <code>meson</code> or
339<code>meson configure</code> with the <code>--cross-file</code>
340parameter.</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
347will likely have to alter them for your system.</p>
348
349<p>
Eric Engestrom393a7562019-01-03 16:01:18 +0000350Those running on ArchLinux can use the AUR-maintained packages for some
351of those, as they'll have the right values for your system:
Erik Faye-Lund92917e82019-04-18 15:38:01 +0200352</p>
Eric Engestrom393a7562019-01-03 16:01:18 +0000353<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>
Eric Engestrom393a7562019-01-03 16:01:18 +0000357
358<p>
Eric Engestromb0319d02018-11-29 13:16:42 +000035932-bit build on x86 linux:
Erik Faye-Lund41573d42019-04-18 16:12:08 +0200360</p>
Eric Engestromb0319d02018-11-29 13:16:42 +0000361<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>
Eric Engestromb0319d02018-11-29 13:16:42 +0000382
383<p>
38464-bit build on ARM linux:
Erik Faye-Lund41573d42019-04-18 16:12:08 +0200385</p>
Eric Engestromb0319d02018-11-29 13:16:42 +0000386<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>
Eric Engestromb0319d02018-11-29 13:16:42 +0000401
402<p>
40364-bit build on x86 windows:
Erik Faye-Lund41573d42019-04-18 16:12:08 +0200404</p>
Eric Engestromb0319d02018-11-29 13:16:42 +0000405<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>
Eric Engestromb0319d02018-11-29 13:16:42 +0000420
Eric Engestrom67c55072018-05-14 16:45:31 +0100421</div>
422</body>
423</html>