travis: printout llvm-config --version
[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="#basic">Basic Usage</a></li>
21 <li><a href="#cross-compilation">Cross-compilation and 32-bit builds</a></li>
22 </ul>
23
24 <h2 id="basic">1. Basic Usage</h2>
25
26 <p><strong>The Meson build system is generally considered stable and ready
27 for production</strong></p>
28
29 <p>The meson build is tested on Linux, macOS, Cygwin and Haiku, FreeBSD,
30 DragonflyBSD, NetBSD, and should work on OpenBSD.</p>
31
32 <p><strong>Mesa requires Meson >= 0.45.0 to build.</strong>
33
34 Some older versions of meson do not check that they are too old and will error
35 out in odd ways.
36 </p>
37
38 <p>
39 The meson program is used to configure the source directory and generates
40 either a ninja build file or Visual Studio® build files. The latter must
41 be enabled via the <code>--backend</code> switch, as ninja is the default backend on all
42 operating systems. Meson only supports out-of-tree builds, and must be passed a
43 directory 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>
52 To see a description of your options you can run <code>meson configure</code>
53 along with a build directory to view the selected options for. This will show
54 your meson global arguments and project arguments, along with their defaults
55 and your local settings.
56
57 Meson does not currently support listing options before configure a build
58 directory, but this feature is being discussed upstream.
59 </p>
60
61 <pre>
62 meson configure build/
63 </pre>
64
65 <p>
66 With additional arguments <code>meson configure</code> is used to change
67 options on already configured build directory. All options passed to this
68 command are in the form <code>-D "command"="value"</code>.
69 </p>
70
71 <pre>
72 meson configure build/ -Dprefix=/tmp/install -Dglx=true
73 </pre>
74
75 <p>
76 Note that options taking lists (such as <code>platforms</code>) are
77 <a href="http://mesonbuild.com/Build-options.html#using-build-options">a bit
78 more complicated</a>, but the simplest form compatible with Mesa options
79 is to use a comma to separate values (<code>-D platforms=drm,wayland</code>)
80 and brackets to represent an empty list (<code>-D platforms=[]</code>).
81 </p>
82
83 <p>
84 Once you've run the initial <code>meson</code> command successfully you can use
85 your configured backend to build the project. With ninja, the -C option can be
86 be used to point at a directory to build.
87 </p>
88
89 <pre>
90 ninja -C build/
91 </pre>
92
93 <p>
94 Without arguments, it will produce libGL.so and/or several other libraries
95 depending on the options you have chosen. Later, if you want to rebuild for a
96 different configuration, you should run <code>ninja clean</code> before
97 changing the configuration, or create a new out of tree build directory for
98 each configuration you want to build
99 <a href="http://mesonbuild.com/Using-multiple-build-directories.html">as
100 recommended in the documentation</a>
101 </p>
102
103 <p>
104 Autotools automatically updates translation files as part of the build process,
105 meson does not do this. Instead if you want translated drirc files you will need
106 to invoke non-default targets for ninja to update them:
107 <code>ninja -C build/ xmlpool-pot xmlpool-update-po xmlpool-gmo</code>
108 </p>
109
110 <dl>
111 <dt><code>Environment Variables</code></dt>
112 <dd><p>Meson supports the standard CC and CXX environment variables for
113 changing the default compiler. Meson does support CFLAGS, CXXFLAGS, etc. But
114 their use is discouraged because of the many caveats in using them. Instead it
115 is recomended to use <code>-D${lang}_args</code> and
116 <code>-D${lang}_link_args</code> instead. Among the benefits of these options
117 is that they are guaranteed to persist across rebuilds and reconfigurations.
118
119 Meson does not allow changing compiler in a configured builddir, you will need
120 to create a new build dir for a different compiler.
121 </p>
122
123 <pre>
124 CC=clang CXX=clang++ meson build-clang
125 ninja -C build-clang
126 ninja -C build-clang clean
127 meson configure build -Dc_args="-Wno-typedef-redefinition"
128 ninja -C build-clang
129 </pre>
130
131 <p>
132 The default compilers depends on your operating system. Meson supports most of
133 the popular compilers, a complete list is available
134 <a href="http://mesonbuild.com/Reference-tables.html#compiler-ids">here</a>.
135 </p>
136
137 <p>Meson also honors <code>DESTDIR</code> for installs</p>
138 </dd>
139
140
141 <dt><code>LLVM</code></dt>
142 <dd><p>Meson includes upstream logic to wrap llvm-config using its standard
143 dependency interface. It will search <code>$PATH</code> (or <code>%PATH%</code> on windows) for
144 llvm-config (and llvm-config$version and llvm-config-$version), so using an
145 LLVM from a non-standard path is as easy as
146 <code>PATH=/path/with/llvm-config:$PATH meson build</code>.
147 </p></dd>
148 </dl>
149
150 <dl>
151 <dt><code>PKG_CONFIG_PATH</code></dt>
152 <dd><p>The
153 <code>pkg-config</code> utility is a hard requirement for configuring and
154 building Mesa on Unix-like systems. It is used to search for external libraries
155 on the system. This environment variable is used to control the search path for
156 <code>pkg-config</code>. For instance, setting
157 <code>PKG_CONFIG_PATH=/usr/X11R6/lib/pkgconfig</code> will search for package
158 metadata in <code>/usr/X11R6</code> before the standard directories.</p>
159 </dd>
160 </dl>
161
162 <p>
163 One of the oddities of meson is that some options are different when passed to
164 the <code>meson</code> than to <code>meson configure</code>. These options are
165 passed as --option=foo to <code>meson</code>, but -Doption=foo to <code>meson
166 configure</code>. Mesa defined options are always passed as -Doption=foo.
167 </p>
168
169 <p>For those coming from autotools be aware of the following:</p>
170
171 <dl>
172 <dt><code>--buildtype/-Dbuildtype</code></dt>
173 <dd><p>This option will set the compiler debug/optimisation levels to aid
174 debugging the Mesa libraries.</p>
175
176 <p>Note that in meson this defaults to <code>debugoptimized</code>, and
177 not setting it to <code>release</code> will yield non-optimal
178 performance and binary size. Not using <code>debug</code> may interfere
179 with debugging as some code and validation will be optimized away.
180 </p>
181
182 <p> For those wishing to pass their own optimization flags, use the <code>plain</code>
183 buildtype, which causes meson to inject no additional compiler arguments, only
184 those in the C/CXXFLAGS and those that mesa itself defines.</p>
185 </dd>
186 </dl>
187
188 <dl>
189 <dt><code>-Db_ndebug</code></dt>
190 <dd><p>This option controls assertions in meson projects. When set to <code>false</code>
191 (the default) assertions are enabled, when set to true they are disabled. This
192 is unrelated to the <code>buildtype</code>; setting the latter to
193 <code>release</code> will not turn off assertions.
194 </p>
195 </dd>
196 </dl>
197
198 <h2 id="cross-compilation">2. Cross-compilation and 32-bit builds</h2>
199
200 <p><a href="https://mesonbuild.com/Cross-compilation.html">Meson supports
201 cross-compilation</a> by specifying a number of binary paths and
202 settings in a file and passing this file to <code>meson</code> or
203 <code>meson configure</code> with the <code>--cross-file</code>
204 parameter.</p>
205
206 <p>This file can live at any location, but you can use the bare filename
207 (without the folder path) if you put it in $XDG_DATA_HOME/meson/cross or
208 ~/.local/share/meson/cross</p>
209
210 <p>Below are a few example of cross files, but keep in mind that you
211 will likely have to alter them for your system.</p>
212
213 <p>
214 32-bit build on x86 linux:
215 <pre>
216 [binaries]
217 c = '/usr/bin/gcc'
218 cpp = '/usr/bin/g++'
219 ar = '/usr/bin/gcc-ar'
220 strip = '/usr/bin/strip'
221 pkgconfig = '/usr/bin/pkg-config-32'
222 llvm-config = '/usr/bin/llvm-config32'
223
224 [properties]
225 c_args = ['-m32']
226 c_link_args = ['-m32']
227 cpp_args = ['-m32']
228 cpp_link_args = ['-m32']
229
230 [host_machine]
231 system = 'linux'
232 cpu_family = 'x86'
233 cpu = 'i686'
234 endian = 'little'
235 </pre>
236 </p>
237
238 <p>
239 64-bit build on ARM linux:
240 <pre>
241 [binaries]
242 c = '/usr/bin/aarch64-linux-gnu-gcc'
243 cpp = '/usr/bin/aarch64-linux-gnu-g++'
244 ar = '/usr/bin/aarch64-linux-gnu-ar'
245 strip = '/usr/bin/aarch64-linux-gnu-strip'
246 pkgconfig = '/usr/bin/aarch64-linux-gnu-pkg-config'
247 exe_wrapper = '/usr/bin/qemu-aarch64-static'
248
249 [host_machine]
250 system = 'linux'
251 cpu_family = 'arm'
252 cpu = 'aarch64'
253 endian = 'little'
254 </pre>
255 </p>
256
257 <p>
258 64-bit build on x86 windows:
259 <pre>
260 [binaries]
261 c = '/usr/bin/x86_64-w64-mingw32-gcc'
262 cpp = '/usr/bin/x86_64-w64-mingw32-g++'
263 ar = '/usr/bin/x86_64-w64-mingw32-ar'
264 strip = '/usr/bin/x86_64-w64-mingw32-strip'
265 pkgconfig = '/usr/bin/x86_64-w64-mingw32-pkg-config'
266 exe_wrapper = 'wine'
267
268 [host_machine]
269 system = 'windows'
270 cpu_family = 'x86_64'
271 cpu = 'i686'
272 endian = 'little'
273 </pre>
274 </p>
275
276 </div>
277 </body>
278 </html>