为 macOS 平台编译

需求

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

  • Python 3.5+.
  • SCons 3.0+ 构建系统.
  • Xcode (或更轻巧的Xcode命令行工具).
  • 可选 - yasm (用于WebM SIMD优化). 注解 Homebrew,你可以使用以下命令轻松地安装 SCons 和 yasm:
    1. brew install scons yasm
    如果你还没有Xcode的命令行工具, 安装Homebrew也会自动获取它们. MacPorts,你可以使用以下命令轻松安装 SCons 和 yasm:
    1. sudo port install scons yasm
    参见 构建系统介绍。

    编译

    启动终端, 进入引擎源代码的根目录. 若要为英特尔(x86-64)架构的 Mac 编译,请使用:
    1. scons platform=osx arch=x86_64 --jobs=$(sysctl -n hw.logicalcpu)
    要为 Apple Silicon(ARM64)驱动的 Mac 编译,请使用:
    1. scons platform=osx arch=arm64 --jobs=$(sysctl -n hw.logicalcpu)
    lipo 将它们打包在一起:
    1. lipo -create bin/godot.osx.tools.x86_64 bin/godot.osx.tools.arm64 -output bin/godot.osx.tools.universal
    bin/ 子目录中. 这个可执行文件包含整个引擎, 运行时没有任何依赖性. 执行它将会弹出项目管理器. 注解 bin/ 文件夹中创建一个名为 ._sc__sc_ 的文件来启用 自包含模式. .app 捆绑包,你需要使用位于 misc/dist/osx_tools.app 的模板。通常,对于用 target=release_debug' 构建的优化编辑器可执行文件:
    1. cp -r misc/dist/osx_tools.app ./Godot.appmkdir -p Godot.app/Contents/MacOScp bin/godot.osx.opt.tools.universal Godot.app/Contents/MacOS/Godotchmod +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_debug --jobs=$(sysctl -n hw.logicalcpu)
    服务器,针对运行专门的游戏服务器进行优化,那么请使用:
    1. scons platform=server tools=no target=release --jobs=$(sysctl -n hw.logicalcpu)

    构建导出模板

    tools=no (无编辑器)进行编译,并分别为 target=release (发布模板)和 target=release_debug. lipo 步骤,创建只支持架构中的一种的导出模板。
  • 对于英特尔 x86_64:
  1. scons platform=osx tools=no target=release arch=x86_64 --jobs=$(sysctl -n hw.logicalcpu)scons platform=osx tools=no target=release_debug arch=x86_64 --jobs=$(sysctl -n hw.logicalcpu)
  • 对于 ARM64(Apple M1):
  1. scons platform=osx tools=no target=release arch=arm64 --jobs=$(sysctl -n hw.logicalcpu)scons platform=osx tools=no target=release_debug arch=arm64 --jobs=$(sysctl -n hw.logicalcpu)

lipo 将它们捆绑在一起:

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

.app 捆绑包,你需要使用位于 misc/dist/osx_template.app 的模板。发布版和调试版应该放在 osx_template.app/Contents/MacOS 里,名称分别为 godot_osx_release.64godot_osx_debug.64。你可以用下面的命令来做(假设是通用构建,否则将 .universal 扩展名替换为你的特定档案的二进制文件):

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

osx_template.app 文件夹来复制 Godot 官方发行的 osx.zip 模板:

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

从Linux交叉编译macOS

OSXCross , 以便能够使用macOS作为目标. 首先, 按照说明来安装它: OSXCross 资源库(或者下载一个 ZIP 文件并解压缩),例如:

  1. git clone --depth=1 https://github.com/tpoechtrager/osxcross.git "$HOME/osxcross"
  1. https://github.com/tpoechtrager/osxcross#packaging-the-sdk
  2. https://github.com/tpoechtrager/osxcross#installation OSXCROSS_ROOT 定义为 OSXCross 的安装路径(与你克隆软件库/提取压缩包的地方相同),例如:
    1. export OSXCROSS_ROOT="$HOME/osxcross"
    现在你可以像平时一样用 SCons 进行编译:
    1. scons platform=osx
    osxcross_sdk 参数指定一个自定义的版本:
    1. scons platform=osx osxcross_sdk=darwin15