为X11平台(Linux、*BSD操作系统)编译

需求

要在Linux或其他类Unix系统下进行编译,需要满足以下条件:

  • GCC 7+ or Clang 6+.
  • Python 3.5+.
  • SCons 3.0+ build system. If your distribution uses Python 2 by default, or you are using a version of SCons prior to 3.1.2, you will need to change the version of Python that SCons uses by changing the shebang (the first line) of the SCons script file to #! /usr/bin/python3. Use the command which scons to find the location of the SCons script file.
  • pkg-config (used to detect the dependencies below).
  • X11, Xcursor, Xinerama, Xi and XRandR development libraries.
  • MesaGL development libraries.
  • ALSA development libraries.
  • PulseAudio development libraries.
  • Optional - libudev (build with udev=yes).
  • Optional - yasm (for WebM SIMD optimizations).

参见

有关Godot的SCons用法的一般概述,请参阅 构建系统介绍

Distro-specific one-liners

Alpine Linux
apk add scons pkgconf gcc g++ libx11-dev libxcursor-dev libxinerama-dev libxi-dev libxrandr-dev \
    libexecinfo-dev
Arch Linux
pacman -S --needed scons pkgconf gcc libxcursor libxinerama libxi libxrandr mesa glu libglvnd \
    alsa-lib pulseaudio yasm
Debian / Ubuntu
sudo apt-get install build-essential scons pkg-config libx11-dev libxcursor-dev libxinerama-dev \
    libgl1-mesa-dev libglu-dev libasound2-dev libpulse-dev libudev-dev libxi-dev libxrandr-dev yasm
Fedora
sudo dnf install scons pkgconfig libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel \
    libXi-devel mesa-libGL-devel mesa-libGLU-devel alsa-lib-devel pulseaudio-libs-devel \
    libudev-devel yasm gcc-c++
FreeBSD
sudo pkg install scons pkgconf xorg-libraries libXcursor libXrandr libXi xorgproto libGLU alsa-lib \
    pulseaudio yasm
Gentoo
emerge -an dev-util/scons x11-libs/libX11 x11-libs/libXcursor x11-libs/libXinerama x11-libs/libXi \
    media-libs/mesa media-libs/glu media-libs/alsa-lib media-sound/pulseaudio dev-lang/yasm
Mageia
urpmi scons task-c++-devel pkgconfig "pkgconfig(alsa)" "pkgconfig(glu)" "pkgconfig(libpulse)" \
    "pkgconfig(udev)" "pkgconfig(x11)" "pkgconfig(xcursor)" "pkgconfig(xinerama)" "pkgconfig(xi)" \
    "pkgconfig(xrandr)" yasm
OpenBSD
pkg_add python scons llvm yasm
openSUSE
sudo zypper install scons pkgconfig libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel \
        libXi-devel Mesa-libGL-devel alsa-devel libpulse-devel libudev-devel libGLU1 yasm
Solus
sudo eopkg install -c system.devel scons libxcursor-devel libxinerama-devel libxi-devel \
    libxrandr-devel mesalib-devel libglu alsa-lib-devel pulseaudio-devel yasm

开始编译

启动终端,然后进入引擎源代码的根目录。键入下面的指令:

scons -j8 platform=x11

-jjobs)标志的一个好的经验法则是,编译Godot的线程至少要与CPU中具有内核的线程数量一样多,甚至不多于一个或两个。随意将 -j 选项添加到下面显示的任何SCons命令中。

如果一切顺利,生成的二进制可执行文件将放在 `` bin`` 子目录中。该可执行文件包含整个引擎,并且运行时无需任何依赖项。 执行它将会启动项目管理器。

注解

如果您希望使用 Clang 而不是 GCC 编译器, 可以使用这个命令:

scons platform=x11 use_llvm=yes

使用Clang似乎是OpenBSD的要求,否则字体将无法生成。

注解

如果您正在编译Godot用于生产用途,那么您可以通过添加SCons选项 target=release_debug 来使最终的可执行文件更小更快。

If you are compiling Godot with GCC, you can make the binary even smaller and faster by adding the SCons option use_lto=yes. As link-time optimization is a memory-intensive process, this will require about 3 GB of available RAM while compiling.

注解

If you want to use separate editor settings for your own Godot builds and official releases, you can enable Self-contained mode by creating a file called ._sc_ or _sc_ in the bin/ folder.

编译无头/服务器构建

To compile a headless build which provides editor functionality to export projects in an automated manner, use:

scons -j8 platform=server tools=yes target=release_debug

To compile a server build which is optimized to run dedicated game servers, use:

scons -j8 platform=server tools=no target=release

构建导出模板

警告

Linux二进制文件通常不会在早于其构建版本的发行版上运行。如果您希望分发适用于大多数发行版的二进制文件,则应在较旧的发行版(例如Ubuntu 16.04)上构建它们。您可以使用虚拟机或容器来设置合适的构建环境。

要构建X11(Linux, *BSD)导出模板,请使用以下参数运行构建系统:

  • ( 32 位 )
scons platform=x11 tools=no target=release bits=32
scons platform=x11 tools=no target=release_debug bits=32
  • ( 64 位 )
scons platform=x11 tools=no target=release bits=64
scons platform=x11 tools=no target=release_debug bits=64

请注意,与您的主机平台相反的位(64/32)交叉编译并不总是直接的,并且可能需要chroot环境。

要创建标准导出模板,必须将生成的文件复制到:

$HOME/.local/share/godot/templates/[gd-version]/

并以此命名(即使对于*BSD,它也被Godot视为“ Linux X11”):

linux_x11_32_debug
linux_x11_32_release
linux_x11_64_debug
linux_x11_64_release

此外,如果要编写自定义模块或自定义C ++代码,则可能需要在此处将二进制文件配置为自定义导出模板:

../../_images/lintemplates.png

您甚至不需要复制它们,只需引用在Godot源文件夹的 bin/ 目录中生成的文件,因此下次构建时,将自动引用自定义模板。

Using Clang and LLD for faster development

You can also use Clang and LLD to build Godot. This has two upsides compared to the default GCC + GNU ld setup:

  • LLD links Godot significantly faster compared to GNU ld or gold. This leads to faster iteration times.
  • Clang tends to give more useful error messages compared to GCC.

To do so, install Clang and the lld package from your distribution's package manager then use the following SCons command:

scons platform=x11 use_llvm=yes use_lld=yes

It's still recommended to use GCC for production builds as they can be compiled using link-time optimization, making the resulting binaries smaller and faster.