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