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