| 1 |
Compiling and Installing |
| 2 |
======================== |
| 3 |
|
| 4 |
.. toctree:: |
| 5 |
:maxdepth: 1 |
| 6 |
:hidden: |
| 7 |
|
| 8 |
meson |
| 9 |
|
| 10 |
1. Prerequisites for building |
| 11 |
----------------------------- |
| 12 |
|
| 13 |
1.1 General |
| 14 |
~~~~~~~~~~~ |
| 15 |
|
| 16 |
Build system |
| 17 |
^^^^^^^^^^^^ |
| 18 |
|
| 19 |
- `Meson <https://mesonbuild.com>`__ is required when building on \*nix |
| 20 |
platforms and on Windows. |
| 21 |
- Android Build system when building as native Android component. Meson |
| 22 |
is used when building ARC. |
| 23 |
|
| 24 |
Compiler |
| 25 |
^^^^^^^^ |
| 26 |
|
| 27 |
The following compilers are known to work, if you know of others or |
| 28 |
you're willing to maintain support for other compiler get in touch. |
| 29 |
|
| 30 |
- GCC 8.0.0 or later (some parts of Mesa may require later versions) |
| 31 |
- Clang 5.0 or later (some parts of Mesa may require later versions) |
| 32 |
- Microsoft Visual C++ compiler |
| 33 |
- Windows SDK of at least 20348 is required |
| 34 |
- Visual Studio 2022 version 17.9 or later for (ARM, AARCH64, ARM64EC, X86, X64) |
| 35 |
|
| 36 |
Third party/extra tools. |
| 37 |
^^^^^^^^^^^^^^^^^^^^^^^^ |
| 38 |
|
| 39 |
- `Python <https://www.python.org/>`__ - Python 3.9 or newer is required. |
| 40 |
- Python package ``packaging`` is required on Python 3.12+: |
| 41 |
``pip install packaging`` |
| 42 |
- `Python Mako module <https://www.makotemplates.org/>`__ - Python Mako |
| 43 |
module is required. Version 0.8.0 or later should work. |
| 44 |
- Lex / Yacc - for building the Mesa IR and GLSL compiler. |
| 45 |
|
| 46 |
On Linux systems, Flex and Bison versions 2.5.35 and 2.4.1, |
| 47 |
respectively, (or later) should work. On Windows with MinGW, install |
| 48 |
Flex and Bison with: |
| 49 |
|
| 50 |
.. code-block:: sh |
| 51 |
|
| 52 |
mingw-get install msys-flex msys-bison |
| 53 |
|
| 54 |
For MSVC on Windows, install `Win |
| 55 |
flex-bison <https://sourceforge.net/projects/winflexbison/>`__. |
| 56 |
|
| 57 |
.. note:: |
| 58 |
|
| 59 |
Some versions can be buggy (e.g. Flex 2.6.2) so do try others |
| 60 |
if things fail. |
| 61 |
|
| 62 |
1.2 Requirements |
| 63 |
~~~~~~~~~~~~~~~~ |
| 64 |
|
| 65 |
The requirements depends on the features selected at configure stage. |
| 66 |
Check/install the respective development package as prompted by the |
| 67 |
configure error message. |
| 68 |
|
| 69 |
Here are some common ways to retrieve most/all of the dependencies based |
| 70 |
on the packaging tool used by your distribution. |
| 71 |
|
| 72 |
.. code-block:: sh |
| 73 |
|
| 74 |
zypper source-install --build-deps-only Mesa # openSUSE/SLED/SLES |
| 75 |
yum-builddep mesa # yum Fedora, OpenSuse(?) |
| 76 |
dnf builddep mesa # dnf Fedora |
| 77 |
apt-get build-dep mesa # Debian and derivatives |
| 78 |
... # others |
| 79 |
|
| 80 |
2. Building with meson |
| 81 |
---------------------- |
| 82 |
|
| 83 |
Meson is the latest build system in mesa, it is currently able to build |
| 84 |
for \*nix systems like Linux and BSD, macOS, Haiku, and Windows. |
| 85 |
|
| 86 |
The general approach is: |
| 87 |
|
| 88 |
.. code-block:: sh |
| 89 |
|
| 90 |
meson setup builddir/ |
| 91 |
meson compile -C builddir/ |
| 92 |
sudo meson install -C builddir/ |
| 93 |
|
| 94 |
On Windows you can also use the Visual Studio backend |
| 95 |
|
| 96 |
.. code-block:: sh |
| 97 |
|
| 98 |
meson setup builddir --backend=vs |
| 99 |
cd builddir |
| 100 |
msbuild mesa.sln /m |
| 101 |
|
| 102 |
Please read the :doc:`detailed meson instructions <meson>` for more |
| 103 |
information |
| 104 |
|
| 105 |
3. Running against a local build (easy way) |
| 106 |
------------------------------------------- |
| 107 |
|
| 108 |
It's often necessary or useful when debugging driver issues or testing new |
| 109 |
branches to run against a local build of Mesa without doing a system-wide |
| 110 |
install. Meson has built-in support for this with its ``devenv`` subcommand: |
| 111 |
|
| 112 |
.. code-block:: sh |
| 113 |
|
| 114 |
meson devenv -C builddir glxinfo |
| 115 |
|
| 116 |
This will run the given command against the build in ``builddir``. Note that meson |
| 117 |
will ``chdir`` into the directory first, so any relative paths in the command line |
| 118 |
will be relative to ``builddir`` which may not be what you expect. |
| 119 |
|
| 120 |
4. Running against a local build (hard way) |
| 121 |
------------------------------------------- |
| 122 |
|
| 123 |
If you prefer you can configure your test environment manually. To do this, |
| 124 |
choose a temporary location for the install. A directory called ``installdir`` |
| 125 |
inside your mesa tree is as good as anything. All of the commands below will |
| 126 |
assume ``$MESA_INSTALLDIR`` is an absolute path to this location. |
| 127 |
|
| 128 |
First, configure Mesa and install in the temporary location: |
| 129 |
|
| 130 |
.. code-block:: sh |
| 131 |
|
| 132 |
meson setup builddir/ -Dprefix="$MESA_INSTALLDIR" OTHER_OPTIONS |
| 133 |
meson install -C builddir/ |
| 134 |
|
| 135 |
where ``OTHER_OPTIONS`` is replaced by any meson configuration options you may |
| 136 |
want. For instance, if you want to build the LLVMpipe drivers, it would look |
| 137 |
like this: |
| 138 |
|
| 139 |
.. code-block:: sh |
| 140 |
|
| 141 |
meson setup builddir/ -Dprefix="$MESA_INSTALLDIR" \ |
| 142 |
-Dgallium-drivers=llvmpipe -Dvulkan-drivers=swrast |
| 143 |
meson install -C builddir/ |
| 144 |
|
| 145 |
Once Mesa has built and installed to ``$MESA_INSTALLDIR``, you can run any app |
| 146 |
against your temporary install by setting the right environment variables. |
| 147 |
Which variable you have to set depends on the API. |
| 148 |
|
| 149 |
OpenGL |
| 150 |
~~~~~~ |
| 151 |
|
| 152 |
.. code-block:: sh |
| 153 |
|
| 154 |
LD_LIBRARY_PATH="$MESA_INSTALLDIR/lib64" glxinfo |
| 155 |
|
| 156 |
You may need to use ``lib`` instead of ``lib64`` on some systems or a full |
| 157 |
library specifier on Debian. Look inside ``installdir`` for the directory that |
| 158 |
contains ``libGL.so`` and use that one. |
| 159 |
|
| 160 |
Vulkan |
| 161 |
~~~~~~ |
| 162 |
|
| 163 |
.. code-block:: sh |
| 164 |
|
| 165 |
VK_DRIVER_FILES="$MESA_INSTALLDIR/share/vulkan/icd.d/my_icd.json" vulkaninfo |
| 166 |
|
| 167 |
where ``my_icd.json`` is replaced with the actual ICD json file name. This |
| 168 |
will depend on your driver. For instance, the 64-bit Lavapipe driver ICD file |
| 169 |
is named ``lvp_icd.x86_64.json``. |
| 170 |
|
| 171 |
OpenCL |
| 172 |
~~~~~~ |
| 173 |
|
| 174 |
.. code-block:: sh |
| 175 |
|
| 176 |
OCL_ICD_VENDORS="$MESA_INSTALLDIR/etc/OpenCL/vendors" clinfo |
| 177 |
|
| 178 |
Unlike Vulkan, OpenCL takes a path to the whole ``vendors`` folder and will |
| 179 |
enumerate any drivers found there. |
| 180 |
|
| 181 |
Troubleshooting local builds |
| 182 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 183 |
|
| 184 |
If you are trying to run an app against a local build and it's not working, |
| 185 |
here are a few things to check: |
| 186 |
|
| 187 |
1. Double-check your paths and try with the simplest app you can. Before |
| 188 |
banging your head on a Steam game, make sure your path works with |
| 189 |
``glxgears`` first. |
| 190 |
|
| 191 |
2. Watch out for wrapper scripts. Some more complex apps such as games have |
| 192 |
big start-up scripts. Sometimes those scripts scrub the environment or set |
| 193 |
``LD_LIBRARY_PATH`` to something in the game's install directory. |
| 194 |
|
| 195 |
3. Is your Mesa build the same arch as your app? Lots of games are still |
| 196 |
32-bit and your Mesa build is probably 64-bit by default. |
| 197 |
|
| 198 |
4. 32 and 64-bit builds in the same local install directory doesn't typically |
| 199 |
work. Distributions go to great lengths to make this work in your system |
| 200 |
install and it's hard to get it right for a local install. If you've |
| 201 |
recently built 64-bit and are now building 32-bit, throw away the install |
| 202 |
directory first to prevent conflicts. |
| 203 |
|
| 204 |
5. Building with AOSP (Android) |
| 205 |
------------------------------- |
| 206 |
|
| 207 |
See :doc:`detailed Android instructions <android>`. |
| 208 |
|
| 209 |
6. Library Information |
| 210 |
---------------------- |
| 211 |
|
| 212 |
When compilation has finished, look in the top-level ``lib/`` (or |
| 213 |
``lib64/``) directory. You'll see a set of library files similar to |
| 214 |
this: |
| 215 |
|
| 216 |
.. code-block:: text |
| 217 |
|
| 218 |
lrwxrwxrwx 1 brian users 10 Mar 26 07:53 libGL.so -> libGL.so.1* |
| 219 |
lrwxrwxrwx 1 brian users 19 Mar 26 07:53 libGL.so.1 -> libGL.so.1.5.060100* |
| 220 |
-rwxr-xr-x 1 brian users 3375861 Mar 26 07:53 libGL.so.1.5.060100* |
| 221 |
|
| 222 |
**libGL** is the main OpenGL library (i.e. Mesa). |
| 223 |
|
| 224 |
If you built the DRI hardware drivers, you'll also see the DRI drivers: |
| 225 |
|
| 226 |
.. code-block:: text |
| 227 |
|
| 228 |
-rwxr-xr-x 1 brian users 16895413 Jul 21 12:11 i915_dri.so |
| 229 |
-rwxr-xr-x 1 brian users 16895413 Jul 21 12:11 i965_dri.so |
| 230 |
-rwxr-xr-x 1 brian users 11849858 Jul 21 12:12 r200_dri.so |
| 231 |
-rwxr-xr-x 1 brian users 11757388 Jul 21 12:12 radeon_dri.so |
| 232 |
|
| 233 |
If you built with Gallium support, look in lib/gallium/ for |
| 234 |
Gallium-based versions of libGL and device drivers. |
| 235 |
|
| 236 |
7. Building OpenGL programs with pkg-config |
| 237 |
------------------------------------------- |
| 238 |
|
| 239 |
Running ``meson install`` will install package configuration files for |
| 240 |
the pkg-config utility. |
| 241 |
|
| 242 |
When compiling your OpenGL application you can use pkg-config to |
| 243 |
determine the proper compiler and linker flags. |
| 244 |
|
| 245 |
For example, compiling and linking a GLUT application can be done with: |
| 246 |
|
| 247 |
.. code-block:: sh |
| 248 |
|
| 249 |
gcc `pkg-config --cflags --libs glut` mydemo.c -o mydemo |