blob: 08e4d1a27e64b4167be0dd7e9b8770ea5836fc6f [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
Brian Paule547a1c2019-03-11 19:58:04 -0600106<a href="https://gitlab.freedesktop.org/mesa/mesa/blob/master/meson_options.txt">
107meson_options.txt</a> file at the root of the project.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700108</p>
109
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700110<p>
Brian Paul45c6da52019-03-07 20:39:49 -0700111With additional arguments <code>meson configure</code> can be used to change
112options for a previously configured build directory.
113All options passed to this command are in the form
114<code>-D "option"="value"</code>.
115For example:
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700116</p>
117
118<pre>
Brian Paul45c6da52019-03-07 20:39:49 -0700119meson configure build/ -Dprefix=/tmp/install -Dglx=true
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700120</pre>
121
122<p>
Eric Engestrom57fbc2a2018-05-14 16:39:42 +0100123Note that options taking lists (such as <code>platforms</code>) are
124<a href="http://mesonbuild.com/Build-options.html#using-build-options">a bit
125more complicated</a>, but the simplest form compatible with Mesa options
126is to use a comma to separate values (<code>-D platforms=drm,wayland</code>)
127and brackets to represent an empty list (<code>-D platforms=[]</code>).
128</p>
129
130<p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700131Once you've run the initial <code>meson</code> command successfully you can use
Brian Paul45c6da52019-03-07 20:39:49 -0700132your configured backend to build the project in your build directory:
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700133</p>
134
135<pre>
Brian Paul45c6da52019-03-07 20:39:49 -0700136ninja -C build/
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700137</pre>
138
139<p>
Brian Paul45c6da52019-03-07 20:39:49 -0700140The next step is to install the Mesa libraries, drivers, etc.
141This also finishes up some final steps of the build process (such as creating
142symbolic links for drivers). To install:
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700143</p>
144
Brian Paul45c6da52019-03-07 20:39:49 -0700145<pre>
146ninja -C build/ install
147</pre>
148
Dylan Bakera8004ef2018-10-22 19:33:08 -0700149<p>
Brian Paul45c6da52019-03-07 20:39:49 -0700150Note: autotools automatically updates translation files (used by the DRI
151configuration tool) as part of the build process,
152Meson does not do this. Instead, you will need do this:
Dylan Bakera8004ef2018-10-22 19:33:08 -0700153</p>
Brian Paul45c6da52019-03-07 20:39:49 -0700154<pre>
155ninja -C build/ xmlpool-pot xmlpool-update-po xmlpool-gmo
156</pre>
157
158<h2 id="advanced">3. Advanced Usage</h2>
Dylan Bakera8004ef2018-10-22 19:33:08 -0700159
Eric Engestrom67c55072018-05-14 16:45:31 +0100160<dl>
Brian Paul45c6da52019-03-07 20:39:49 -0700161
162<dt>Installation Location</dt>
163<dd>
164<p>
165Meson default to installing libGL.so in your system's main lib/ directory
166and DRI drivers to a dri/ subdirectory.
167</p>
168<p>
169Developers will often want to install Mesa to a testing directory rather
170than the system library directory.
171This can be done with the --prefix option. For example:
172</p>
Brian Paul16fb82d2019-03-08 10:31:11 -0700173<pre>
Brian Paul45c6da52019-03-07 20:39:49 -0700174meson --prefix="${PWD}/build/install" build/
Brian Paul16fb82d2019-03-08 10:31:11 -0700175</pre>
Brian Paul45c6da52019-03-07 20:39:49 -0700176<p>
177will put the final libraries and drivers into the build/install/
178directory.
179Then you can set LD_LIBRARY_PATH and LIBGL_DRIVERS_PATH to that location
180to run/test the driver.
181</p>
Brian Paul16fb82d2019-03-08 10:31:11 -0700182<p>
183Meson also honors <code>DESTDIR</code> for installs.
184</p>
Brian Paul45c6da52019-03-07 20:39:49 -0700185</dd>
186
Brian Paul16fb82d2019-03-08 10:31:11 -0700187<dt>Compiler Options</dt>
188<dd>
189<p>Meson supports the common CFLAGS, CXXFLAGS, etc. environment
190variables but their use is discouraged because of the many caveats
191in using them.
192</p>
193<p>Instead, it is recomended to use <code>-D${lang}_args</code> and
194<code>-D${lang}_link_args</code>. Among the benefits of these options
Dylan Baker0ff7eed2018-12-19 13:27:27 -0800195is that they are guaranteed to persist across rebuilds and reconfigurations.
Brian Paul16fb82d2019-03-08 10:31:11 -0700196</p>
197This example sets -fmax-errors for compiling C sources and -DMAGIC=123
198for C++ sources:
199</p>
200<p>
201<pre>
202meson builddir/ -Dc_args=-fmax-errors=10 -Dcpp_args=-DMAGIC=123
203</pre>
204</p>
205</dd>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700206
Brian Paul16fb82d2019-03-08 10:31:11 -0700207
208<dt>Compiler Specification</dt>
209<dd>
210<p>
211Meson supports the standard CC and CXX environment variables for
212changing the default compiler. Note that Meson does not allow
213changing the compilers in a configured builddir so you will need
Dylan Baker0ff7eed2018-12-19 13:27:27 -0800214to create a new build dir for a different compiler.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700215</p>
Brian Paul16fb82d2019-03-08 10:31:11 -0700216<p>
217This is an example of specifying the clang compilers and cleaning
218the build directory before reconfiguring with an extra C option:
219</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700220<pre>
Brian Paul16fb82d2019-03-08 10:31:11 -0700221CC=clang CXX=clang++ meson build-clang
222ninja -C build-clang
223ninja -C build-clang clean
224meson configure build -Dc_args="-Wno-typedef-redefinition"
225ninja -C build-clang
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700226</pre>
Dylan Bakere0829f92018-09-18 09:07:25 -0700227<p>
228The default compilers depends on your operating system. Meson supports most of
229the popular compilers, a complete list is available
230<a href="http://mesonbuild.com/Reference-tables.html#compiler-ids">here</a>.
231</p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700232</dd>
233
Brian Paul45c6da52019-03-07 20:39:49 -0700234<dt>LLVM</dt>
Dylan Bakerbe56f8a2018-09-18 09:09:47 -0700235<dd><p>Meson includes upstream logic to wrap llvm-config using its standard
Dylan Bakera57dbe62018-12-20 11:46:08 -0800236dependency interface.
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700237</p></dd>
Dylan Bakera57dbe62018-12-20 11:46:08 -0800238
239<dd><p>
240As of meson 0.49.0 meson also has the concept of a
241<a href="https://mesonbuild.com/Native-environments.html">"native file"</a>,
242these files provide information about the native build environment (as opposed
243to a cross build environment). They are ini formatted and can override where to
244find llvm-config:
245
246custom-llvm.ini
247<pre>
248 [binaries]
249 llvm-config = '/usr/local/bin/llvm/llvm-config'
250</pre>
251
252Then configure meson:
253
254<pre>
255 meson builddir/ --native-file custom-llvm.ini
256</pre>
257</p></dd>
258
259<dd><p>
260For selecting llvm-config for cross compiling a
261<a href="https://mesonbuild.com/Cross-compilation.html#defining-the-environment">"cross file"</a>
262should be used. It uses the same format as the native file above:
263
264cross-llvm.ini
265<pre>
266 [binaries]
267 ...
268 llvm-config = '/usr/lib/llvm-config-32'
269</pre>
270
271Then configure meson:
272
273<pre>
274 meson builddir/ --cross-file cross-llvm.ini
275</pre>
276
277See the <a href="#cross-compilation">Cross Compilation</a> section for more information.
278</dd></p>
279
280<dd><p>
281For older versions of meson <code>$PATH</code> (or <code>%PATH%</code> on
282windows) will be searched for llvm-config (and llvm-config$version and
283llvm-config-$version), you can override this environment variable to control
284the search: <code>PATH=/path/with/llvm-config:$PATH meson build</code>.
285</dd></p>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700286</dl>
287
Dylan Baker2aad12b2018-03-01 11:32:56 -0800288<dl>
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>
324</dl>
325
326<dl>
327<dt><code>-Db_ndebug</code></dt>
Eric Engestrom37d44e22018-05-14 16:47:57 +0100328<dd><p>This option controls assertions in meson projects. When set to <code>false</code>
Dylan Bakerbc17ac52017-10-17 12:19:49 -0700329(the default) assertions are enabled, when set to true they are disabled. This
330is unrelated to the <code>buildtype</code>; setting the latter to
331<code>release</code> will not turn off assertions.
332</p>
333</dd>
334</dl>
Eric Engestrom67c55072018-05-14 16:45:31 +0100335
Brian Paul45c6da52019-03-07 20:39:49 -0700336<h2 id="cross-compilation">4. Cross-compilation and 32-bit builds</h2>
Eric Engestromb0319d02018-11-29 13:16:42 +0000337
338<p><a href="https://mesonbuild.com/Cross-compilation.html">Meson supports
339cross-compilation</a> by specifying a number of binary paths and
340settings in a file and passing this file to <code>meson</code> or
341<code>meson configure</code> with the <code>--cross-file</code>
342parameter.</p>
343
344<p>This file can live at any location, but you can use the bare filename
345(without the folder path) if you put it in $XDG_DATA_HOME/meson/cross or
346~/.local/share/meson/cross</p>
347
348<p>Below are a few example of cross files, but keep in mind that you
349will likely have to alter them for your system.</p>
350
351<p>
Eric Engestrom393a7562019-01-03 16:01:18 +0000352Those running on ArchLinux can use the AUR-maintained packages for some
353of those, as they'll have the right values for your system:
354<ul>
355 <li><a href="https://aur.archlinux.org/packages/meson-cross-x86-linux-gnu">meson-cross-x86-linux-gnu</a></li>
356 <li><a href="https://aur.archlinux.org/packages/meson-cross-aarch64-linux-gnu">meson-cross-aarch64-linux-gnu</a></li>
357</ul>
358</p>
359
360<p>
Eric Engestromb0319d02018-11-29 13:16:42 +000036132-bit build on x86 linux:
362<pre>
363[binaries]
364c = '/usr/bin/gcc'
365cpp = '/usr/bin/g++'
366ar = '/usr/bin/gcc-ar'
367strip = '/usr/bin/strip'
368pkgconfig = '/usr/bin/pkg-config-32'
369llvm-config = '/usr/bin/llvm-config32'
370
371[properties]
372c_args = ['-m32']
373c_link_args = ['-m32']
374cpp_args = ['-m32']
375cpp_link_args = ['-m32']
376
377[host_machine]
378system = 'linux'
379cpu_family = 'x86'
380cpu = 'i686'
381endian = 'little'
382</pre>
383</p>
384
385<p>
38664-bit build on ARM linux:
387<pre>
388[binaries]
389c = '/usr/bin/aarch64-linux-gnu-gcc'
390cpp = '/usr/bin/aarch64-linux-gnu-g++'
Eric Engestrom8b363bc2019-01-03 15:44:42 +0000391ar = '/usr/bin/aarch64-linux-gnu-gcc-ar'
Eric Engestromb0319d02018-11-29 13:16:42 +0000392strip = '/usr/bin/aarch64-linux-gnu-strip'
393pkgconfig = '/usr/bin/aarch64-linux-gnu-pkg-config'
394exe_wrapper = '/usr/bin/qemu-aarch64-static'
395
396[host_machine]
397system = 'linux'
Eric Engestrom8b363bc2019-01-03 15:44:42 +0000398cpu_family = 'aarch64'
Eric Engestromb0319d02018-11-29 13:16:42 +0000399cpu = 'aarch64'
400endian = 'little'
401</pre>
402</p>
403
404<p>
40564-bit build on x86 windows:
406<pre>
407[binaries]
408c = '/usr/bin/x86_64-w64-mingw32-gcc'
409cpp = '/usr/bin/x86_64-w64-mingw32-g++'
410ar = '/usr/bin/x86_64-w64-mingw32-ar'
411strip = '/usr/bin/x86_64-w64-mingw32-strip'
412pkgconfig = '/usr/bin/x86_64-w64-mingw32-pkg-config'
413exe_wrapper = 'wine'
414
415[host_machine]
416system = 'windows'
417cpu_family = 'x86_64'
418cpu = 'i686'
419endian = 'little'
420</pre>
421</p>
422
Eric Engestrom67c55072018-05-14 16:45:31 +0100423</div>
424</body>
425</html>