为macOS平台编译

需求

在macOS下编译时,需要以下条件:

注解

如果你安装了 Homebrew ,你可以使用以下命令轻松地安装SCons和yasm:

  1. brew install scons yasm

如果你还没有Xcode的命令行工具,安装Homebrew也会自动获取它们.

Similarly, if you have MacPorts installed, you can easily install SCons and yasm using the following command:

  1. sudo port install scons yasm

参见

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

开始编译

启动终端,进入引擎源代码的根目录.

若要为英特尔(x86-64)架构的Mac编译,请使用:

  1. scons platform=osx arch=x86_64 --jobs=$(sysctl -n hw.logicalcpu)

要为Apple硅(ARM64)驱动的Mac编译,请使用:

  1. scons platform=osx arch=arm64 --jobs=$(sysctl -n hw.logicalcpu)

要在一个 “Universal 2 “二进制中支持这两种架构,请运行上述两个命令,然后使用``lipo``将它们捆绑在一起:

  1. lipo -create bin/godot.osx.tools.x86_64 bin/godot.osx.tools.arm64 -output bin/godot.osx.tools.universal

如果一切顺利,产生的二进制可执行文件将被放置在 bin/ 子目录中.这个可执行文件包含整个引擎,运行时没有任何依赖性.执行它将会弹出项目管理器.

注解

如果你想为自己的Godot构建和官方发布使用单独的编辑器设置,你可以通过在 bin/ 文件夹中创建一个名为 ._sc__sc_ 的文件来启用 自包含模式.

要创建一个像官方构建的 .app 捆绑包,你需要使用位于 misc/dist/osx_tools.app 的模板.通常,对于用 target=release_debug' 构建的优化编辑器可执行文件:

  1. cp -r misc/dist/osx_tools.app ./Godot.app
  2. mkdir -p Godot.app/Contents/MacOS
  3. cp bin/godot.osx.opt.tools.universal Godot.app/Contents/MacOS/Godot
  4. chmod +x Godot.app/Contents/MacOS/Godot

编译精简和服务器构建

要编译一个 精简 构建,它提供了编辑器功能,可以自动导出项目,使用:

  1. scons platform=server tools=yes target=release_debug --jobs=$(sysctl -n hw.logicalcpu)

要编译一个经过优化以运行专用游戏的 服务器 版本,使用以下构建选项:

  1. scons platform=server tools=no target=release --jobs=$(sysctl -n hw.logicalcpu)

构建导出模板

To build macOS export templates, you have to compile with tools=no (no editor) and respectively for target=release (release template) and target=release_debug.

Official templates are universal binaries which support both Intel x86_64 and ARM64 architectures. You can also create export templates that support only one of those two architectures by leaving out the lipo step below.

  • For Intel x86_64:

    1. scons platform=osx tools=no target=release arch=x86_64 --jobs=$(sysctl -n hw.logicalcpu)
    2. scons platform=osx tools=no target=release_debug arch=x86_64 --jobs=$(sysctl -n hw.logicalcpu)
  • For ARM64 (Apple M1):

    1. scons platform=osx tools=no target=release arch=arm64 --jobs=$(sysctl -n hw.logicalcpu)
    2. scons platform=osx tools=no target=release_debug arch=arm64 --jobs=$(sysctl -n hw.logicalcpu)

To support both architectures in a single “Universal 2” binary, run the above two commands blocks and then use lipo to bundle them together:

  1. lipo -create bin/godot.osx.opt.x86_64 bin/godot.osx.opt.arm64 -output bin/godot.osx.opt.universal
  2. lipo -create bin/godot.osx.opt.debug.x86_64 bin/godot.osx.opt.debug.arm64 -output bin/godot.osx.opt.debug.universal

To create an .app bundle like in the official builds, you need to use the template located in misc/dist/osx_template.app. The release and debug builds should be placed in osx_template.app/Contents/MacOS with the names godot_osx_release.64 and godot_osx_debug.64 respectively. You can do so with the following commands (assuming a universal build, otherwise replace the .universal extension with the one of your arch-specific binaries):

  1. cp -r misc/dist/osx_template.app .
  2. mkdir -p osx_template.app/Contents/MacOS
  3. cp bin/godot.osx.opt.universal osx_template.app/Contents/MacOS/godot_osx_release.64
  4. cp bin/godot.osx.opt.debug.universal osx_template.app/Contents/MacOS/godot_osx_debug.64
  5. chmod +x Godot.app/Contents/MacOS/godot_osx*

You can then zip the osx_template.app folder to reproduce the osx.zip template from the official Godot distribution:

  1. zip -q -9 -r osx.zip osx_template.app

从Linux交叉编译macOS

在Linux环境下为macOS进行编译是可行的(也许也可以在Windows中使用Windows Subsystem for Linux).为此,你需要安装 OSXCross ,以便能够使用macOS作为目标.首先,按照说明来安装它:

在你的机器上某处克隆 `OSXCross资源库<https://github.com/tpoechtrager/osxcross>`__ (或者下载一个ZIP文件并解压缩),例如:

  1. git clone --depth=1 https://github.com/tpoechtrager/osxcross.git "$HOME/osxcross"
  1. 按照说明打包SDK:https://github.com/tpoechtrager/osxcross#packaging-the-sdk

  2. 按照说明安装OSXCross:https://github.com/tpoechtrager/osxcross#installation

之后,你需要将 OSXCROSS_ROOT 定义为OSXCross的安装路径(与你克隆软件库/提取压缩包的地方相同),例如:

  1. export OSXCROSS_ROOT="$HOME/osxcross"

现在你可以像平时一样用SCons进行编译:

  1. scons platform=osx

如果你的OSXCross SDK版本与SCons构建系统所期望的不同,你可以用 osxcross_sdk 参数指定一个自定义的版本:

  1. scons platform=osx osxcross_sdk=darwin15