blob: f21479ce223b6db233d0af63b98c791f56fbdda9 [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>
20 <li><a href="#basic">Basic Usage</a></li>
21 <li><a href="#cross-compilation">Cross-compilation and 32-bit builds</a></li>
22</ul>
23
Dylan Bakerbc17ac52017-10-17 12:19:49 -070024<h2 id="basic">1. Basic Usage</h2>
25
Dylan Baker2aad12b2018-03-01 11:32:56 -080026<p><strong>The Meson build system is generally considered stable and ready
27for production</strong></p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -070028
Dylan Baker1da60662018-09-18 09:01:45 -070029<p>The meson build is tested on Linux, macOS, Cygwin and Haiku, FreeBSD,
30DragonflyBSD, NetBSD, and should work on OpenBSD.</p>
Dylan Baker2aad12b2018-03-01 11:32:56 -080031
Dylan Baker1da60662018-09-18 09:01:45 -070032<p><strong>Mesa requires Meson >= 0.45.0 to build.</strong>
Dylan Baker2aad12b2018-03-01 11:32:56 -080033
34Some older versions of meson do not check that they are too old and will error
35out in odd ways.
36</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -070037
38<p>
39The meson program is used to configure the source directory and generates
40either a ninja build file or Visual Studio® build files. The latter must
Eric Engestrom37d44e22018-05-14 16:47:57 +010041be enabled via the <code>--backend</code> switch, as ninja is the default backend on all
Dylan Bakerbc17ac52017-10-17 12:19:49 -070042operating systems. Meson only supports out-of-tree builds, and must be passed a
43directory to put built and generated sources into. We'll call that directory
44"build" for examples.
45</p>
46
47<pre>
48 meson build/
49</pre>
50
51<p>
52To see a description of your options you can run <code>meson configure</code>
53along with a build directory to view the selected options for. This will show
54your meson global arguments and project arguments, along with their defaults
55and your local settings.
Eric Engestromc4c5c902019-01-17 16:26:26 +000056</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -070057
Eric Engestromc4c5c902019-01-17 16:26:26 +000058<p>
Eric Engestromdc2dc1f2018-05-14 16:44:08 +010059Meson does not currently support listing options before configure a build
Dylan Bakerbc17ac52017-10-17 12:19:49 -070060directory, but this feature is being discussed upstream.
Eric Engestrom00be88a2019-01-17 18:04:42 +000061For now, we have a <code>bin/meson-options.py</code> script that prints
62the options for you.
63If that script doesn't work for some reason, you can always look in the
Eric Engestromc4c5c902019-01-17 16:26:26 +000064<code>meson_options.txt</code> file at the root of the project.
Dylan Bakerbc17ac52017-10-17 12:19:49 -070065</p>
66
67<pre>
68 meson configure build/
69</pre>
70
71<p>
72With additional arguments <code>meson configure</code> is used to change
73options on already configured build directory. All options passed to this
Eric Engestrom37d44e22018-05-14 16:47:57 +010074command are in the form <code>-D "command"="value"</code>.
Dylan Bakerbc17ac52017-10-17 12:19:49 -070075</p>
76
77<pre>
78 meson configure build/ -Dprefix=/tmp/install -Dglx=true
79</pre>
80
81<p>
Eric Engestrom57fbc2a2018-05-14 16:39:42 +010082Note that options taking lists (such as <code>platforms</code>) are
83<a href="http://mesonbuild.com/Build-options.html#using-build-options">a bit
84more complicated</a>, but the simplest form compatible with Mesa options
85is to use a comma to separate values (<code>-D platforms=drm,wayland</code>)
86and brackets to represent an empty list (<code>-D platforms=[]</code>).
87</p>
88
89<p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -070090Once you've run the initial <code>meson</code> command successfully you can use
91your configured backend to build the project. With ninja, the -C option can be
92be used to point at a directory to build.
93</p>
94
95<pre>
96 ninja -C build/
97</pre>
98
99<p>
100Without arguments, it will produce libGL.so and/or several other libraries
101depending on the options you have chosen. Later, if you want to rebuild for a
102different configuration, you should run <code>ninja clean</code> before
103changing the configuration, or create a new out of tree build directory for
Eric Engestrom5829f612018-05-14 16:47:18 +0100104each configuration you want to build
105<a href="http://mesonbuild.com/Using-multiple-build-directories.html">as
106recommended in the documentation</a>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700107</p>
108
Dylan Bakera8004ef2018-10-22 19:33:08 -0700109<p>
110Autotools automatically updates translation files as part of the build process,
111meson does not do this. Instead if you want translated drirc files you will need
112to invoke non-default targets for ninja to update them:
113<code>ninja -C build/ xmlpool-pot xmlpool-update-po xmlpool-gmo</code>
114</p>
115
Eric Engestrom67c55072018-05-14 16:45:31 +0100116<dl>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700117<dt><code>Environment Variables</code></dt>
Eric Engestromdc2dc1f2018-05-14 16:44:08 +0100118<dd><p>Meson supports the standard CC and CXX environment variables for
Dylan Baker0ff7eed2018-12-19 13:27:27 -0800119changing the default compiler. Meson does support CFLAGS, CXXFLAGS, etc. But
120their use is discouraged because of the many caveats in using them. Instead it
121is recomended to use <code>-D${lang}_args</code> and
122<code>-D${lang}_link_args</code> instead. Among the benefits of these options
123is that they are guaranteed to persist across rebuilds and reconfigurations.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700124
Dylan Baker0ff7eed2018-12-19 13:27:27 -0800125Meson does not allow changing compiler in a configured builddir, you will need
126to create a new build dir for a different compiler.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700127</p>
128
129<pre>
130 CC=clang CXX=clang++ meson build-clang
131 ninja -C build-clang
132 ninja -C build-clang clean
Dylan Bakere0829f92018-09-18 09:07:25 -0700133 meson configure build -Dc_args="-Wno-typedef-redefinition"
134 ninja -C build-clang
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700135</pre>
136
Dylan Bakere0829f92018-09-18 09:07:25 -0700137<p>
138The default compilers depends on your operating system. Meson supports most of
139the popular compilers, a complete list is available
140<a href="http://mesonbuild.com/Reference-tables.html#compiler-ids">here</a>.
141</p>
142
Eric Engestrom37d44e22018-05-14 16:47:57 +0100143<p>Meson also honors <code>DESTDIR</code> for installs</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700144</dd>
145
146
147<dt><code>LLVM</code></dt>
Dylan Bakerbe56f8a2018-09-18 09:09:47 -0700148<dd><p>Meson includes upstream logic to wrap llvm-config using its standard
Dylan Bakera57dbe62018-12-20 11:46:08 -0800149dependency interface.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700150</p></dd>
Dylan Bakera57dbe62018-12-20 11:46:08 -0800151
152<dd><p>
153As of meson 0.49.0 meson also has the concept of a
154<a href="https://mesonbuild.com/Native-environments.html">"native file"</a>,
155these files provide information about the native build environment (as opposed
156to a cross build environment). They are ini formatted and can override where to
157find llvm-config:
158
159custom-llvm.ini
160<pre>
161 [binaries]
162 llvm-config = '/usr/local/bin/llvm/llvm-config'
163</pre>
164
165Then configure meson:
166
167<pre>
168 meson builddir/ --native-file custom-llvm.ini
169</pre>
170</p></dd>
171
172<dd><p>
173For selecting llvm-config for cross compiling a
174<a href="https://mesonbuild.com/Cross-compilation.html#defining-the-environment">"cross file"</a>
175should be used. It uses the same format as the native file above:
176
177cross-llvm.ini
178<pre>
179 [binaries]
180 ...
181 llvm-config = '/usr/lib/llvm-config-32'
182</pre>
183
184Then configure meson:
185
186<pre>
187 meson builddir/ --cross-file cross-llvm.ini
188</pre>
189
190See the <a href="#cross-compilation">Cross Compilation</a> section for more information.
191</dd></p>
192
193<dd><p>
194For older versions of meson <code>$PATH</code> (or <code>%PATH%</code> on
195windows) will be searched for llvm-config (and llvm-config$version and
196llvm-config-$version), you can override this environment variable to control
197the search: <code>PATH=/path/with/llvm-config:$PATH meson build</code>.
198</dd></p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700199</dl>
200
Dylan Baker2aad12b2018-03-01 11:32:56 -0800201<dl>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700202<dt><code>PKG_CONFIG_PATH</code></dt>
203<dd><p>The
204<code>pkg-config</code> utility is a hard requirement for configuring and
Dylan Baker2aad12b2018-03-01 11:32:56 -0800205building Mesa on Unix-like systems. It is used to search for external libraries
206on the system. This environment variable is used to control the search path for
207<code>pkg-config</code>. For instance, setting
208<code>PKG_CONFIG_PATH=/usr/X11R6/lib/pkgconfig</code> will search for package
209metadata in <code>/usr/X11R6</code> before the standard directories.</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700210</dd>
211</dl>
212
213<p>
214One of the oddities of meson is that some options are different when passed to
215the <code>meson</code> than to <code>meson configure</code>. These options are
216passed as --option=foo to <code>meson</code>, but -Doption=foo to <code>meson
217configure</code>. Mesa defined options are always passed as -Doption=foo.
Eric Engestrom67c55072018-05-14 16:45:31 +0100218</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700219
220<p>For those coming from autotools be aware of the following:</p>
221
222<dl>
223<dt><code>--buildtype/-Dbuildtype</code></dt>
224<dd><p>This option will set the compiler debug/optimisation levels to aid
225debugging the Mesa libraries.</p>
226
Eric Engestrom37d44e22018-05-14 16:47:57 +0100227<p>Note that in meson this defaults to <code>debugoptimized</code>, and
228not setting it to <code>release</code> will yield non-optimal
229performance and binary size. Not using <code>debug</code> may interfere
230with debugging as some code and validation will be optimized away.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700231</p>
232
Eric Engestrom37d44e22018-05-14 16:47:57 +0100233<p> For those wishing to pass their own optimization flags, use the <code>plain</code>
Dylan Baker2aad12b2018-03-01 11:32:56 -0800234buildtype, which causes meson to inject no additional compiler arguments, only
235those in the C/CXXFLAGS and those that mesa itself defines.</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700236</dd>
237</dl>
238
239<dl>
240<dt><code>-Db_ndebug</code></dt>
Eric Engestrom37d44e22018-05-14 16:47:57 +0100241<dd><p>This option controls assertions in meson projects. When set to <code>false</code>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700242(the default) assertions are enabled, when set to true they are disabled. This
243is unrelated to the <code>buildtype</code>; setting the latter to
244<code>release</code> will not turn off assertions.
245</p>
246</dd>
247</dl>
Eric Engestrom67c55072018-05-14 16:45:31 +0100248
Eric Engestromb0319d02018-11-29 13:16:42 +0000249<h2 id="cross-compilation">2. Cross-compilation and 32-bit builds</h2>
250
251<p><a href="https://mesonbuild.com/Cross-compilation.html">Meson supports
252cross-compilation</a> by specifying a number of binary paths and
253settings in a file and passing this file to <code>meson</code> or
254<code>meson configure</code> with the <code>--cross-file</code>
255parameter.</p>
256
257<p>This file can live at any location, but you can use the bare filename
258(without the folder path) if you put it in $XDG_DATA_HOME/meson/cross or
259~/.local/share/meson/cross</p>
260
261<p>Below are a few example of cross files, but keep in mind that you
262will likely have to alter them for your system.</p>
263
264<p>
Eric Engestrom393a7562019-01-03 16:01:18 +0000265Those running on ArchLinux can use the AUR-maintained packages for some
266of those, as they'll have the right values for your system:
267<ul>
268 <li><a href="https://aur.archlinux.org/packages/meson-cross-x86-linux-gnu">meson-cross-x86-linux-gnu</a></li>
269 <li><a href="https://aur.archlinux.org/packages/meson-cross-aarch64-linux-gnu">meson-cross-aarch64-linux-gnu</a></li>
270</ul>
271</p>
272
273<p>
Eric Engestromb0319d02018-11-29 13:16:42 +000027432-bit build on x86 linux:
275<pre>
276[binaries]
277c = '/usr/bin/gcc'
278cpp = '/usr/bin/g++'
279ar = '/usr/bin/gcc-ar'
280strip = '/usr/bin/strip'
281pkgconfig = '/usr/bin/pkg-config-32'
282llvm-config = '/usr/bin/llvm-config32'
283
284[properties]
285c_args = ['-m32']
286c_link_args = ['-m32']
287cpp_args = ['-m32']
288cpp_link_args = ['-m32']
289
290[host_machine]
291system = 'linux'
292cpu_family = 'x86'
293cpu = 'i686'
294endian = 'little'
295</pre>
296</p>
297
298<p>
29964-bit build on ARM linux:
300<pre>
301[binaries]
302c = '/usr/bin/aarch64-linux-gnu-gcc'
303cpp = '/usr/bin/aarch64-linux-gnu-g++'
Eric Engestrom8b363bc2019-01-03 15:44:42 +0000304ar = '/usr/bin/aarch64-linux-gnu-gcc-ar'
Eric Engestromb0319d02018-11-29 13:16:42 +0000305strip = '/usr/bin/aarch64-linux-gnu-strip'
306pkgconfig = '/usr/bin/aarch64-linux-gnu-pkg-config'
307exe_wrapper = '/usr/bin/qemu-aarch64-static'
308
309[host_machine]
310system = 'linux'
Eric Engestrom8b363bc2019-01-03 15:44:42 +0000311cpu_family = 'aarch64'
Eric Engestromb0319d02018-11-29 13:16:42 +0000312cpu = 'aarch64'
313endian = 'little'
314</pre>
315</p>
316
317<p>
31864-bit build on x86 windows:
319<pre>
320[binaries]
321c = '/usr/bin/x86_64-w64-mingw32-gcc'
322cpp = '/usr/bin/x86_64-w64-mingw32-g++'
323ar = '/usr/bin/x86_64-w64-mingw32-ar'
324strip = '/usr/bin/x86_64-w64-mingw32-strip'
325pkgconfig = '/usr/bin/x86_64-w64-mingw32-pkg-config'
326exe_wrapper = 'wine'
327
328[host_machine]
329system = 'windows'
330cpu_family = 'x86_64'
331cpu = 'i686'
332endian = 'little'
333</pre>
334</p>
335
Eric Engestrom67c55072018-05-14 16:45:31 +0100336</div>
337</body>
338</html>