compiling_for_x11.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. .. _doc_compiling_for_x11:
  2. Compiling for X11 (Linux, \*BSD)
  3. ================================
  4. .. highlight:: shell
  5. Requirements
  6. ------------
  7. For compiling under Linux or other Unix variants, the following is
  8. required:
  9. - GCC 7+ or Clang 6+.
  10. - Python 3.5+.
  11. - SCons 3.0+ build system. If your distribution uses Python 2 by default,
  12. or you are using a version of SCons prior to 3.1.2, you will need to change
  13. the version of Python that SCons uses by changing the shebang (the first line)
  14. of the SCons script file to ``#! /usr/bin/python3``.
  15. Use the command ``which scons`` to find the location of the SCons script file.
  16. - pkg-config (used to detect the dependencies below).
  17. - X11, Xcursor, Xinerama, Xi and XRandR development libraries.
  18. - MesaGL development libraries.
  19. - ALSA development libraries.
  20. - PulseAudio development libraries.
  21. - *Optional* - libudev (build with ``udev=yes``).
  22. - *Optional* - yasm (for WebM SIMD optimizations).
  23. .. seealso:: For a general overview of SCons usage for Godot, see
  24. :ref:`doc_introduction_to_the_buildsystem`.
  25. Distro-specific one-liners
  26. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  27. +------------------+-----------------------------------------------------------------------------------------------------------+
  28. | **Alpine Linux** | :: |
  29. | | |
  30. | | apk add scons pkgconf gcc g++ libx11-dev libxcursor-dev libxinerama-dev libxi-dev libxrandr-dev \ |
  31. | | libexecinfo-dev |
  32. +------------------+-----------------------------------------------------------------------------------------------------------+
  33. | **Arch Linux** | :: |
  34. | | |
  35. | | pacman -S --needed scons pkgconf gcc libxcursor libxinerama libxi libxrandr mesa glu libglvnd \ |
  36. | | alsa-lib pulseaudio yasm |
  37. +------------------+-----------------------------------------------------------------------------------------------------------+
  38. | **Debian** / | :: |
  39. | **Ubuntu** | |
  40. | | sudo apt-get install build-essential scons pkg-config libx11-dev libxcursor-dev libxinerama-dev \ |
  41. | | libgl1-mesa-dev libglu-dev libasound2-dev libpulse-dev libudev-dev libxi-dev libxrandr-dev yasm |
  42. +------------------+-----------------------------------------------------------------------------------------------------------+
  43. | **Fedora** | :: |
  44. | | |
  45. | | sudo dnf install scons pkgconfig libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel \ |
  46. | | libXi-devel mesa-libGL-devel mesa-libGLU-devel alsa-lib-devel pulseaudio-libs-devel \ |
  47. | | libudev-devel yasm gcc-c++ libstdc++-static |
  48. +------------------+-----------------------------------------------------------------------------------------------------------+
  49. | **FreeBSD** | :: |
  50. | | |
  51. | | sudo pkg install py37-scons pkgconf xorg-libraries libXcursor libXrandr libXi xorgproto libGLU \ |
  52. | | alsa-lib pulseaudio yasm |
  53. | | |
  54. +------------------+-----------------------------------------------------------------------------------------------------------+
  55. | **Gentoo** | :: |
  56. | | |
  57. | | emerge -an dev-util/scons x11-libs/libX11 x11-libs/libXcursor x11-libs/libXinerama x11-libs/libXi \ |
  58. | | media-libs/mesa media-libs/glu media-libs/alsa-lib media-sound/pulseaudio dev-lang/yasm |
  59. +------------------+-----------------------------------------------------------------------------------------------------------+
  60. | **Mageia** | :: |
  61. | | |
  62. | | urpmi scons task-c++-devel pkgconfig "pkgconfig(alsa)" "pkgconfig(glu)" "pkgconfig(libpulse)" \ |
  63. | | "pkgconfig(udev)" "pkgconfig(x11)" "pkgconfig(xcursor)" "pkgconfig(xinerama)" "pkgconfig(xi)" \ |
  64. | | "pkgconfig(xrandr)" yasm |
  65. +------------------+-----------------------------------------------------------------------------------------------------------+
  66. | **OpenBSD** | :: |
  67. | | |
  68. | | pkg_add python scons llvm yasm |
  69. +------------------+-----------------------------------------------------------------------------------------------------------+
  70. | **openSUSE** | :: |
  71. | | |
  72. | | sudo zypper install scons pkgconfig libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel \ |
  73. | | libXi-devel Mesa-libGL-devel alsa-devel libpulse-devel libudev-devel libGLU1 yasm |
  74. +------------------+-----------------------------------------------------------------------------------------------------------+
  75. | **NetBSD** | :: |
  76. | | |
  77. | | pkg_add pkg-config py37-scons yasm |
  78. | | |
  79. | | For audio support, you can optionally install ``pulseaudio``. |
  80. +------------------+-----------------------------------------------------------------------------------------------------------+
  81. | **Solus** | :: |
  82. | | |
  83. | | sudo eopkg install -c system.devel scons libxcursor-devel libxinerama-devel libxi-devel \ |
  84. | | libxrandr-devel mesalib-devel libglu alsa-lib-devel pulseaudio-devel yasm |
  85. +------------------+-----------------------------------------------------------------------------------------------------------+
  86. Compiling
  87. ---------
  88. Start a terminal, go to the root dir of the engine source code and type:
  89. ::
  90. scons -j8 platform=x11
  91. A good rule of thumb for the ``-j`` (*jobs*) flag, is to have at least as many
  92. threads compiling Godot as you have cores in your CPU, if not one or two more.
  93. Feel free to add the ``-j`` option to any SCons command you see below.
  94. If all goes well, the resulting binary executable will be placed in the
  95. "bin" subdirectory. This executable file contains the whole engine and
  96. runs without any dependencies. Executing it will bring up the project
  97. manager.
  98. .. note::
  99. If you wish to compile using Clang rather than GCC, use this command:
  100. ::
  101. scons platform=x11 use_llvm=yes
  102. Using Clang appears to be a requirement for OpenBSD, otherwise fonts
  103. would not build.
  104. .. note:: If you are compiling Godot for production use, then you can
  105. make the final executable smaller and faster by adding the
  106. SCons option ``target=release_debug``.
  107. If you are compiling Godot with GCC, you can make the binary
  108. even smaller and faster by adding the SCons option ``use_lto=yes``.
  109. As link-time optimization is a memory-intensive process,
  110. this will require about 7 GB of available RAM while compiling.
  111. .. note:: If you want to use separate editor settings for your own Godot builds
  112. and official releases, you can enable
  113. :ref:`doc_data_paths_self_contained_mode` by creating a file called
  114. ``._sc_`` or ``_sc_`` in the ``bin/`` folder.
  115. Compiling a headless/server build
  116. ---------------------------------
  117. To compile a *headless* build which provides editor functionality to export
  118. projects in an automated manner, use::
  119. scons -j8 platform=server tools=yes target=release_debug
  120. To compile a *server* build which is optimized to run dedicated game servers,
  121. use::
  122. scons -j8 platform=server tools=no target=release
  123. Building export templates
  124. -------------------------
  125. .. warning:: Linux binaries usually won't run on distributions that are
  126. older than the distribution they were built on. If you wish to
  127. distribute binaries that work on most distributions,
  128. you should build them on an old distribution such as Ubuntu 16.04.
  129. You can use a virtual machine or a container to set up a suitable
  130. build environment.
  131. To build X11 (Linux, \*BSD) export templates, run the build system with the
  132. following parameters:
  133. - (32 bits)
  134. ::
  135. scons platform=x11 tools=no target=release bits=32
  136. scons platform=x11 tools=no target=release_debug bits=32
  137. - (64 bits)
  138. ::
  139. scons platform=x11 tools=no target=release bits=64
  140. scons platform=x11 tools=no target=release_debug bits=64
  141. Note that cross-compiling for the opposite bits (64/32) as your host
  142. platform is not always straight-forward and might need a chroot environment.
  143. To create standard export templates, the resulting files must be copied to:
  144. ::
  145. $HOME/.local/share/godot/templates/[gd-version]/
  146. and named like this (even for \*BSD which is seen as "Linux X11" by Godot):
  147. ::
  148. linux_x11_32_debug
  149. linux_x11_32_release
  150. linux_x11_64_debug
  151. linux_x11_64_release
  152. However, if you are writing your custom modules or custom C++ code, you
  153. might instead want to configure your binaries as custom export templates
  154. here:
  155. .. image:: img/lintemplates.png
  156. You don't even need to copy them, you can just reference the resulting
  157. files in the ``bin/`` directory of your Godot source folder, so the next
  158. time you build, you automatically have the custom templates referenced.
  159. Using Clang and LLD for faster development
  160. ------------------------------------------
  161. You can also use Clang and LLD to build Godot. This has two upsides compared to
  162. the default GCC + GNU ld setup:
  163. - LLD links Godot significantly faster compared to GNU ld or gold. This leads to
  164. faster iteration times.
  165. - Clang tends to give more useful error messages compared to GCC.
  166. To do so, install Clang and the ``lld`` package from your distribution's package manager
  167. then use the following SCons command::
  168. scons platform=x11 use_llvm=yes use_lld=yes
  169. After the build is completed, a new binary with a ``.llvm`` suffix will be
  170. created in the ``bin/`` folder.
  171. It's still recommended to use GCC for production builds as they can be compiled using
  172. link-time optimization, making the resulting binaries smaller and faster.