1 | Compilation and Installation Using Meson
|
---|
2 | ========================================
|
---|
3 |
|
---|
4 | 1. Introduction
|
---|
5 | ---------------
|
---|
6 |
|
---|
7 | For general information about Meson see the `Meson
|
---|
8 | website <https://mesonbuild.com/>`__.
|
---|
9 |
|
---|
10 | .. note::
|
---|
11 |
|
---|
12 | Mesa requires Meson >= 0.60.0 to build.
|
---|
13 |
|
---|
14 | If your distribution doesn't have something recent enough in its
|
---|
15 | repositories, you can `try the methods suggested here
|
---|
16 | <https://mesonbuild.com/Getting-meson.html>`__ to install the
|
---|
17 | current version of Meson.
|
---|
18 |
|
---|
19 | The Meson build of Mesa is tested on Linux, macOS, Windows, Cygwin,
|
---|
20 | Haiku, FreeBSD, DragonflyBSD, NetBSD, and should work on OpenBSD.
|
---|
21 |
|
---|
22 | Unix-like OSes
|
---|
23 | ^^^^^^^^^^^^^^
|
---|
24 |
|
---|
25 | If Meson is not already installed on your system, you can typically
|
---|
26 | install it with your package installer. For example:
|
---|
27 |
|
---|
28 | .. code-block:: console
|
---|
29 |
|
---|
30 | sudo apt-get install meson # Ubuntu
|
---|
31 |
|
---|
32 | or
|
---|
33 |
|
---|
34 | .. code-block:: console
|
---|
35 |
|
---|
36 | sudo dnf install meson # Fedora
|
---|
37 |
|
---|
38 | Some older versions of Meson do not check that they are too old and will
|
---|
39 | error out in odd ways.
|
---|
40 |
|
---|
41 | You'll also need `Ninja <https://ninja-build.org/>`__. If it's not
|
---|
42 | already installed, use apt-get or dnf to install the *ninja-build*
|
---|
43 | package.
|
---|
44 |
|
---|
45 | Windows
|
---|
46 | ^^^^^^^
|
---|
47 |
|
---|
48 | You will need to install Python 3 and Meson as a module using pip. This
|
---|
49 | is because we use Python for generating code, and rely on external
|
---|
50 | modules (Mako). You also need pkg-config (a hard dependency of Meson),
|
---|
51 | Flex, and Bison. The easiest way to install everything you need is with
|
---|
52 | `Chocolatey <https://chocolatey.org/>`__.
|
---|
53 |
|
---|
54 | .. code-block:: console
|
---|
55 |
|
---|
56 | choco install python3 winflexbison pkgconfiglite
|
---|
57 |
|
---|
58 | You can even use Chocolatey to install MinGW and Ninja (Ninja can be
|
---|
59 | used with MSVC as well)
|
---|
60 |
|
---|
61 | .. code-block:: console
|
---|
62 |
|
---|
63 | choco install ninja mingw
|
---|
64 |
|
---|
65 | Then install Meson using pip
|
---|
66 |
|
---|
67 | .. code-block:: console
|
---|
68 |
|
---|
69 | py -3 -m pip install meson packaging mako
|
---|
70 |
|
---|
71 | You may need to add the Python 3 scripts directory to your path for
|
---|
72 | Meson.
|
---|
73 |
|
---|
74 | 2. Basic Usage
|
---|
75 | --------------
|
---|
76 |
|
---|
77 | The Meson program is used to configure the source directory and
|
---|
78 | generates either a Ninja build file or Visual Studio® build files. The
|
---|
79 | latter must be enabled via the ``--backend`` switch, as Ninja is the
|
---|
80 | default backend on all operating systems.
|
---|
81 |
|
---|
82 | Meson only supports out-of-tree builds, and must be passed a directory
|
---|
83 | to put built and generated sources into. We'll call that directory
|
---|
84 | "build" here. It's recommended to create a `separate build
|
---|
85 | directory <https://mesonbuild.com/Using-multiple-build-directories.html>`__
|
---|
86 | for each configuration you might want to use.
|
---|
87 |
|
---|
88 | Basic configuration is done with:
|
---|
89 |
|
---|
90 | .. code-block:: console
|
---|
91 |
|
---|
92 | meson setup build/
|
---|
93 |
|
---|
94 | This will create the build directory. If any dependencies are missing,
|
---|
95 | you can install them, or try to remove the dependency with a Meson
|
---|
96 | configuration option (see below). Meson will print a summary of the
|
---|
97 | build options at the end.
|
---|
98 |
|
---|
99 | To review the options which Meson chose, run:
|
---|
100 |
|
---|
101 | .. code-block:: console
|
---|
102 |
|
---|
103 | meson configure build/
|
---|
104 |
|
---|
105 | Recent version of Meson can print the available options and their
|
---|
106 | default values by running ``meson configure`` in the source directory.
|
---|
107 | If your Meson version is too old, you can always look in the
|
---|
108 | `meson_options.txt <https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/meson_options.txt>`__
|
---|
109 | file at the root of the project.
|
---|
110 |
|
---|
111 | With additional arguments ``meson configure`` can be used to change
|
---|
112 | options for a previously configured build directory. All options passed
|
---|
113 | to this command are in the form ``-D "option"="value"``. For example:
|
---|
114 |
|
---|
115 | .. code-block:: console
|
---|
116 |
|
---|
117 | meson configure build/ -Dprefix=/tmp/install -Dglx=true
|
---|
118 |
|
---|
119 | Note that options taking lists (such as ``platforms``) are `a bit more
|
---|
120 | complicated <https://mesonbuild.com/Build-options.html#using-build-options>`__,
|
---|
121 | but the simplest form compatible with Mesa options is to use a comma to
|
---|
122 | separate values (``-D platforms=drm,wayland``) and brackets to represent
|
---|
123 | an empty list (``-D platforms=[]``).
|
---|
124 |
|
---|
125 | Once you've run the initial ``meson`` command successfully you can use
|
---|
126 | your configured backend to build the project in your build directory:
|
---|
127 |
|
---|
128 | .. code-block:: console
|
---|
129 |
|
---|
130 | ninja -C build/
|
---|
131 |
|
---|
132 | The next step is to install the Mesa libraries, drivers, etc. This also
|
---|
133 | finishes up some final steps of the build process (such as creating
|
---|
134 | symbolic links for drivers). To install:
|
---|
135 |
|
---|
136 | .. code-block:: console
|
---|
137 |
|
---|
138 | ninja -C build/ install
|
---|
139 |
|
---|
140 | Windows specific instructions
|
---|
141 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
---|
142 |
|
---|
143 | On Windows you have a couple of choices for compilers. If you installed
|
---|
144 | MinGW with Chocolatey and want to use Ninja you should be able to open
|
---|
145 | any shell and follow the instructions above. If you want to you MSVC,
|
---|
146 | clang-cl, or ICL (the Intel Compiler), read on.
|
---|
147 |
|
---|
148 | Both ICL and MSVC come with shell environments, the easiest way to use
|
---|
149 | Meson with these it to open a shell. For clang-cl you will need to open
|
---|
150 | an MSVC shell, and then override the compilers, either using a `native
|
---|
151 | file <https://mesonbuild.com/Native-environments.html>`__, or with the
|
---|
152 | CC and CXX environment variables.
|
---|
153 |
|
---|
154 | All of these compilers are tested and work with Ninja, but if you want
|
---|
155 | Visual Studio integration or you just like msbuild, passing
|
---|
156 | ``--backend=vs`` to Meson will generate a Visual Studio solution.
|
---|
157 |
|
---|
158 | 3. Advanced Usage
|
---|
159 | -----------------
|
---|
160 |
|
---|
161 | Installation Location
|
---|
162 | ^^^^^^^^^^^^^^^^^^^^^
|
---|
163 |
|
---|
164 | Meson default to installing :file:`libGL.so` in your system's main
|
---|
165 | :file:`lib/` directory and DRI drivers to a :file:`dri/` subdirectory.
|
---|
166 |
|
---|
167 | Developers will often want to install Mesa to a testing directory rather
|
---|
168 | than the system library directory. This can be done with the --prefix
|
---|
169 | option. For example:
|
---|
170 |
|
---|
171 | .. code-block:: console
|
---|
172 |
|
---|
173 | meson --prefix="${PWD}/build/install" build/
|
---|
174 |
|
---|
175 | will put the final libraries and drivers into the build/install/
|
---|
176 | directory. Then you can set LD_LIBRARY_PATH and LIBGL_DRIVERS_PATH to
|
---|
177 | that location to run/test the driver.
|
---|
178 |
|
---|
179 | Meson also honors ``DESTDIR`` for installs.
|
---|
180 |
|
---|
181 | Compiler Options
|
---|
182 | ^^^^^^^^^^^^^^^^
|
---|
183 |
|
---|
184 | Meson supports the common CFLAGS, CXXFLAGS, etc. environment variables
|
---|
185 | but their use is discouraged because of the many caveats in using them.
|
---|
186 |
|
---|
187 | Instead, it is recommended to use ``-D${lang}_args`` and
|
---|
188 | ``-D${lang}_link_args``. Among the benefits of these options is that
|
---|
189 | they are guaranteed to persist across rebuilds and reconfigurations.
|
---|
190 |
|
---|
191 | This example sets -fmax-errors for compiling C sources and -DMAGIC=123
|
---|
192 | for C++ sources:
|
---|
193 |
|
---|
194 | .. code-block:: console
|
---|
195 |
|
---|
196 | meson setup builddir/ -Dc_args=-fmax-errors=10 -Dcpp_args=-DMAGIC=123
|
---|
197 |
|
---|
198 | Compiler Specification
|
---|
199 | ^^^^^^^^^^^^^^^^^^^^^^
|
---|
200 |
|
---|
201 | Meson supports the standard CC and CXX environment variables for
|
---|
202 | changing the default compiler. Note that Meson does not allow changing
|
---|
203 | the compilers in a configured build directory so you will need to create
|
---|
204 | a new build dir for a different compiler.
|
---|
205 |
|
---|
206 | This is an example of specifying the Clang compilers and cleaning the
|
---|
207 | build directory before reconfiguring with an extra C option:
|
---|
208 |
|
---|
209 | .. code-block:: console
|
---|
210 |
|
---|
211 | CC=clang CXX=clang++ meson setup build-clang
|
---|
212 | ninja -C build-clang
|
---|
213 | ninja -C build-clang clean
|
---|
214 | meson configure build -Dc_args="-Wno-typedef-redefinition"
|
---|
215 | ninja -C build-clang
|
---|
216 |
|
---|
217 | The default compilers depends on your operating system. Meson supports
|
---|
218 | most of the popular compilers, a complete list is available
|
---|
219 | `here <https://mesonbuild.com/Reference-tables.html#compiler-ids>`__.
|
---|
220 |
|
---|
221 | LLVM
|
---|
222 | ^^^^
|
---|
223 |
|
---|
224 | Meson includes upstream logic to wrap llvm-config using its standard
|
---|
225 | dependency interface.
|
---|
226 |
|
---|
227 | Meson can use CMake to find LLVM. But due to the way LLVM implements its
|
---|
228 | CMake finder it will only find static libraries, it will never find
|
---|
229 | :file:`libllvm.so`. There is also a ``-Dcmake_module_path`` option,
|
---|
230 | which points to the root of an alternative installation (the prefix).
|
---|
231 | For example:
|
---|
232 |
|
---|
233 | .. code-block:: console
|
---|
234 |
|
---|
235 | meson setup builddir -Dcmake_module_path=/home/user/mycmake/prefix
|
---|
236 |
|
---|
237 | As of Meson 0.49.0 Meson also has the concept of a `"native
|
---|
238 | file" <https://mesonbuild.com/Native-environments.html>`__, these files
|
---|
239 | provide information about the native build environment (as opposed to a
|
---|
240 | cross build environment). They are INI formatted and can override where
|
---|
241 | to find llvm-config:
|
---|
242 |
|
---|
243 | .. code-block:: ini
|
---|
244 | :caption: custom-llvm.ini
|
---|
245 |
|
---|
246 | [binaries]
|
---|
247 | llvm-config = '/usr/local/bin/llvm/llvm-config'
|
---|
248 |
|
---|
249 | Then configure Meson:
|
---|
250 |
|
---|
251 | .. code-block:: console
|
---|
252 |
|
---|
253 | meson setup builddir/ --native-file custom-llvm.ini
|
---|
254 |
|
---|
255 | For selecting llvm-config for cross compiling a `"cross
|
---|
256 | file" <https://mesonbuild.com/Cross-compilation.html#defining-the-environment>`__
|
---|
257 | should be used. It uses the same format as the native file above:
|
---|
258 |
|
---|
259 | .. code-block:: ini
|
---|
260 | :caption: cross-llvm.ini
|
---|
261 |
|
---|
262 | [binaries]
|
---|
263 | ...
|
---|
264 | llvm-config = '/usr/lib/llvm-config-32'
|
---|
265 | cmake = '/usr/bin/cmake-for-my-arch'
|
---|
266 |
|
---|
267 | Obviously, only CMake or llvm-config is required.
|
---|
268 |
|
---|
269 | Then configure Meson:
|
---|
270 |
|
---|
271 | .. code-block:: console
|
---|
272 |
|
---|
273 | meson setup builddir/ --cross-file cross-llvm.ini
|
---|
274 |
|
---|
275 | See the :ref:`Cross Compilation <cross-compilation>` section for more
|
---|
276 | information.
|
---|
277 |
|
---|
278 | On Windows (and in other cases), using llvm-config or CMake may be
|
---|
279 | either undesirable or impossible. Meson's solution for this is a
|
---|
280 | `wrap <https://mesonbuild.com/Wrap-dependency-system-manual.html>`__, in
|
---|
281 | this case a "binary wrap". Follow the steps below:
|
---|
282 |
|
---|
283 | - Install the binaries and headers into the
|
---|
284 | ``$mesa_src/subprojects/llvm``
|
---|
285 | - Add a :file:`meson.build` file to that directory (more on that later)
|
---|
286 |
|
---|
287 | The wrap file must define the following:
|
---|
288 |
|
---|
289 | - ``dep_llvm``: a ``declare_dependency()`` object with
|
---|
290 | include_directories, dependencies, and version set)
|
---|
291 |
|
---|
292 | It may also define:
|
---|
293 |
|
---|
294 | - ``irbuilder_h``: a ``files()`` object pointing to llvm/IR/IRBuilder.h
|
---|
295 | - ``has_rtti``: a ``bool`` that declares whether LLVM was built with
|
---|
296 | RTTI. Defaults to true
|
---|
297 |
|
---|
298 | such a :file:`meson.build` file might look like:
|
---|
299 |
|
---|
300 | ::
|
---|
301 |
|
---|
302 | project('llvm', ['cpp'])
|
---|
303 |
|
---|
304 | cpp = meson.get_compiler('cpp')
|
---|
305 |
|
---|
306 | _deps = []
|
---|
307 | _search = join_paths(meson.current_source_dir(), 'lib')
|
---|
308 | foreach d : ['libLLVMCodeGen', 'libLLVMScalarOpts', 'libLLVMAnalysis',
|
---|
309 | 'libLLVMTransformUtils', 'libLLVMCore', 'libLLVMX86CodeGen',
|
---|
310 | 'libLLVMSelectionDAG', 'libLLVMipo', 'libLLVMAsmPrinter',
|
---|
311 | 'libLLVMInstCombine', 'libLLVMInstrumentation', 'libLLVMMC',
|
---|
312 | 'libLLVMGlobalISel', 'libLLVMObjectYAML', 'libLLVMDebugInfoPDB',
|
---|
313 | 'libLLVMVectorize', 'libLLVMPasses', 'libLLVMSupport',
|
---|
314 | 'libLLVMLTO', 'libLLVMObject', 'libLLVMDebugInfoCodeView',
|
---|
315 | 'libLLVMDebugInfoDWARF', 'libLLVMOrcJIT', 'libLLVMProfileData',
|
---|
316 | 'libLLVMObjCARCOpts', 'libLLVMBitReader', 'libLLVMCoroutines',
|
---|
317 | 'libLLVMBitWriter', 'libLLVMRuntimeDyld', 'libLLVMMIRParser',
|
---|
318 | 'libLLVMX86Desc', 'libLLVMAsmParser', 'libLLVMTableGen',
|
---|
319 | 'libLLVMFuzzMutate', 'libLLVMLinker', 'libLLVMMCParser',
|
---|
320 | 'libLLVMExecutionEngine', 'libLLVMCoverage', 'libLLVMInterpreter',
|
---|
321 | 'libLLVMTarget', 'libLLVMX86AsmParser', 'libLLVMSymbolize',
|
---|
322 | 'libLLVMDebugInfoMSF', 'libLLVMMCJIT', 'libLLVMXRay',
|
---|
323 | 'libLLVMX86AsmPrinter', 'libLLVMX86Disassembler',
|
---|
324 | 'libLLVMMCDisassembler', 'libLLVMOption', 'libLLVMIRReader',
|
---|
325 | 'libLLVMLibDriver', 'libLLVMDlltoolDriver', 'libLLVMDemangle',
|
---|
326 | 'libLLVMBinaryFormat', 'libLLVMLineEditor',
|
---|
327 | 'libLLVMWindowsManifest', 'libLLVMX86Info', 'libLLVMX86Utils']
|
---|
328 | _deps += cpp.find_library(d, dirs : _search)
|
---|
329 | endforeach
|
---|
330 |
|
---|
331 | dep_llvm = declare_dependency(
|
---|
332 | include_directories : include_directories('include'),
|
---|
333 | dependencies : _deps,
|
---|
334 | version : '6.0.0',
|
---|
335 | )
|
---|
336 |
|
---|
337 | has_rtti = false
|
---|
338 | irbuilder_h = files('include/llvm/IR/IRBuilder.h')
|
---|
339 |
|
---|
340 | It is very important that version is defined and is accurate, if it is
|
---|
341 | not, workarounds for the wrong version of LLVM might be used resulting
|
---|
342 | in build failures.
|
---|
343 |
|
---|
344 | ``PKG_CONFIG_PATH``
|
---|
345 | ^^^^^^^^^^^^^^^^^^^
|
---|
346 |
|
---|
347 | The ``pkg-config`` utility is a hard requirement for configuring and
|
---|
348 | building Mesa on Unix-like systems. It is used to search for external
|
---|
349 | libraries on the system. This environment variable is used to control
|
---|
350 | the search path for ``pkg-config``. For instance, setting
|
---|
351 | ``PKG_CONFIG_PATH=/usr/X11R6/lib/pkgconfig`` will search for package
|
---|
352 | metadata in ``/usr/X11R6`` before the standard directories.
|
---|
353 |
|
---|
354 | Options
|
---|
355 | ^^^^^^^
|
---|
356 |
|
---|
357 | One of the oddities of Meson is that some options are different when
|
---|
358 | passed to :program:`meson` than to ``meson configure``. These options are
|
---|
359 | passed as --option=foo to :program:`meson`, but -Doption=foo to
|
---|
360 | ``meson configure``. Mesa defined options are always passed as
|
---|
361 | -Doption=foo.
|
---|
362 |
|
---|
363 | For those coming from Autotools be aware of the following:
|
---|
364 |
|
---|
365 | ``--buildtype/-Dbuildtype``
|
---|
366 | This option will set the compiler debug/optimization levels to aid
|
---|
367 | debugging the Mesa libraries.
|
---|
368 |
|
---|
369 | Note that in Meson this defaults to ``debugoptimized``, and not
|
---|
370 | setting it to ``release`` will yield non-optimal performance and
|
---|
371 | binary size. Not using ``debug`` may interfere with debugging as some
|
---|
372 | code and validation will be optimized away.
|
---|
373 |
|
---|
374 | For those wishing to pass their own optimization flags, use the
|
---|
375 | ``plain`` buildtype, which causes Meson to inject no additional
|
---|
376 | compiler arguments, only those in the C/CXXFLAGS and those that mesa
|
---|
377 | itself defines.
|
---|
378 |
|
---|
379 | ``-Db_ndebug``
|
---|
380 | This option controls assertions in Meson projects. When set to
|
---|
381 | ``false`` (the default) assertions are enabled, when set to true they
|
---|
382 | are disabled. This is unrelated to the ``buildtype``; setting the
|
---|
383 | latter to ``release`` will not turn off assertions.
|
---|
384 |
|
---|
385 | .. _cross-compilation:
|
---|
386 |
|
---|
387 | 4. Cross-compilation and 32-bit builds
|
---|
388 | --------------------------------------
|
---|
389 |
|
---|
390 | `Meson supports
|
---|
391 | cross-compilation <https://mesonbuild.com/Cross-compilation.html>`__ by
|
---|
392 | specifying a number of binary paths and settings in a file and passing
|
---|
393 | this file to ``meson`` or ``meson configure`` with the ``--cross-file``
|
---|
394 | parameter.
|
---|
395 |
|
---|
396 | This file can live at any location, but you can use the bare filename
|
---|
397 | (without the folder path) if you put it in
|
---|
398 | :file:`$XDG_DATA_HOME/meson/cross` or :file:`~/.local/share/meson/cross`
|
---|
399 |
|
---|
400 | Below are a few example of cross files, but keep in mind that you will
|
---|
401 | likely have to alter them for your system.
|
---|
402 |
|
---|
403 | Those running on Arch Linux can use the AUR-maintained packages for some
|
---|
404 | of those, as they'll have the right values for your system:
|
---|
405 |
|
---|
406 | - `meson-cross-x86-linux-gnu <https://aur.archlinux.org/packages/meson-cross-x86-linux-gnu>`__
|
---|
407 | - `meson-cross-aarch64-linux-gnu <https://github.com/dcbaker/archlinux-meson-cross-aarch64-linux-gnu>`__
|
---|
408 |
|
---|
409 | 32-bit build on x86 linux:
|
---|
410 |
|
---|
411 | .. code-block:: ini
|
---|
412 |
|
---|
413 | [binaries]
|
---|
414 | c = '/usr/bin/gcc'
|
---|
415 | cpp = '/usr/bin/g++'
|
---|
416 | ar = '/usr/bin/gcc-ar'
|
---|
417 | strip = '/usr/bin/strip'
|
---|
418 | pkgconfig = '/usr/bin/pkg-config-32'
|
---|
419 | llvm-config = '/usr/bin/llvm-config32'
|
---|
420 |
|
---|
421 | [properties]
|
---|
422 | c_args = ['-m32']
|
---|
423 | c_link_args = ['-m32']
|
---|
424 | cpp_args = ['-m32']
|
---|
425 | cpp_link_args = ['-m32']
|
---|
426 |
|
---|
427 | [host_machine]
|
---|
428 | system = 'linux'
|
---|
429 | cpu_family = 'x86'
|
---|
430 | cpu = 'i686'
|
---|
431 | endian = 'little'
|
---|
432 |
|
---|
433 | 64-bit build on ARM linux:
|
---|
434 |
|
---|
435 | .. code-block:: ini
|
---|
436 |
|
---|
437 | [binaries]
|
---|
438 | c = '/usr/bin/aarch64-linux-gnu-gcc'
|
---|
439 | cpp = '/usr/bin/aarch64-linux-gnu-g++'
|
---|
440 | ar = '/usr/bin/aarch64-linux-gnu-gcc-ar'
|
---|
441 | strip = '/usr/bin/aarch64-linux-gnu-strip'
|
---|
442 | pkgconfig = '/usr/bin/aarch64-linux-gnu-pkg-config'
|
---|
443 | exe_wrapper = '/usr/bin/qemu-aarch64-static'
|
---|
444 |
|
---|
445 | [host_machine]
|
---|
446 | system = 'linux'
|
---|
447 | cpu_family = 'aarch64'
|
---|
448 | cpu = 'aarch64'
|
---|
449 | endian = 'little'
|
---|
450 |
|
---|
451 | 64-bit build on x86 Windows:
|
---|
452 |
|
---|
453 | .. code-block:: ini
|
---|
454 |
|
---|
455 | [binaries]
|
---|
456 | c = '/usr/bin/x86_64-w64-mingw32-gcc'
|
---|
457 | cpp = '/usr/bin/x86_64-w64-mingw32-g++'
|
---|
458 | ar = '/usr/bin/x86_64-w64-mingw32-ar'
|
---|
459 | strip = '/usr/bin/x86_64-w64-mingw32-strip'
|
---|
460 | pkgconfig = '/usr/bin/x86_64-w64-mingw32-pkg-config'
|
---|
461 | exe_wrapper = 'wine'
|
---|
462 |
|
---|
463 | [host_machine]
|
---|
464 | system = 'windows'
|
---|
465 | cpu_family = 'x86_64'
|
---|
466 | cpu = 'i686'
|
---|
467 | endian = 'little'
|
---|