pandemonium_engine_docs/engine_development/compiling/compiling_for_osx.md

192 lines
6.7 KiB
Markdown
Raw Normal View History

2023-01-12 20:49:14 +01:00
# Compiling for macOS
This page describes how to compile macOS editor and export template binaries from source. If you're looking to
export your project to macOS instead, read `doc_exporting_for_macos`.
## Requirements
For compiling under macOS, the following is required:
2023-01-12 20:57:31 +01:00
- `Python 3.5+ ( https://www.python.org )`.
- `SCons 3.0+ ( https://www.scons.org )` build system.
- `Xcode ( https://apps.apple.com/us/app/xcode/id497799835 )`
(or the more lightweight Command Line Tools for Xcode).
2023-01-12 20:57:31 +01:00
- *Optional* - `yasm ( https://yasm.tortall.net/ )` (for WebM SIMD optimizations).
### Note:
If you have `Homebrew ( https://brew.sh/ )` installed, you can easily install SCons and yasm using the following command:
2023-01-12 22:00:14 +01:00
```
brew install scons yasm
2023-01-12 22:00:14 +01:00
```
Installing Homebrew will also fetch the Command Line Tools for Xcode automatically if you don't have them already.
Similarly, if you have `MacPorts ( https://www.macports.org/ )` installed, you can easily install
SCons and yasm using the following command:
2023-01-12 22:00:14 +01:00
```
sudo port install scons yasm
2023-01-12 22:00:14 +01:00
```
To get the Godot source code for compiling, see `doc_getting_source`.
For a general overview of SCons usage for Godot, see `doc_introduction_to_the_buildsystem`.
## Compiling
Start a terminal, go to the root directory of the engine source code.
2023-01-12 22:00:14 +01:00
To compile for Intel (x86-64) powered Macs, use
2023-01-12 22:00:14 +01:00
```
scons platform=osx arch=x86_64 --jobs=$(sysctl -n hw.logicalcpu)
2023-01-12 22:00:14 +01:00
```
2023-01-12 22:00:14 +01:00
To compile for Apple Silicon (ARM64) powered Macs, use:
2023-01-12 22:00:14 +01:00
```
scons platform=osx arch=arm64 --jobs=$(sysctl -n hw.logicalcpu)
2023-01-12 22:00:14 +01:00
```
2023-01-12 22:00:14 +01:00
To support both architectures in a single "Universal 2" binary, run the above two commands and then use `lipo` to bundle them together:
2023-01-12 22:00:14 +01:00
```
lipo -create bin/godot.osx.tools.x86_64 bin/godot.osx.tools.arm64 -output bin/godot.osx.tools.universal
2023-01-12 22:00:14 +01:00
```
If all goes well, the resulting binary executable will be placed in the `bin/` subdirectory. This executable
file contains the whole engine and runs without any dependencies. Executing it will bring up the project manager.
If you want to use separate editor settings for your own Godot builds and official releases, you can enable
`doc_data_paths_self_contained_mode` by creating a file called `._sc_` or `sc_` in the `bin/` folder.
2023-01-12 19:43:03 +01:00
To create an `.app` bundle like in the official builds, you need to use the
template located in `misc/dist/osx_tools.app`. Typically, for an optimized
2023-01-12 22:00:14 +01:00
editor binary built with `target=release_debug`:
2023-01-12 22:00:14 +01:00
```
cp -r misc/dist/osx_tools.app ./Godot.app
mkdir -p Godot.app/Contents/MacOS
cp bin/godot.osx.opt.tools.universal Godot.app/Contents/MacOS/Godot
chmod +x Godot.app/Contents/MacOS/Godot
2023-01-12 22:00:14 +01:00
```
## Compiling a headless/server build
To compile a *headless* build which provides editor functionality to export
2023-01-12 22:00:14 +01:00
projects in an automated manner, use:
2023-01-12 22:00:14 +01:00
```
scons platform=server tools=yes target=release_debug --jobs=$(sysctl -n hw.logicalcpu)
2023-01-12 22:00:14 +01:00
```
To compile a debug *server* build which can be used with
2023-01-12 22:00:14 +01:00
`remote debugging tools ( doc_command_line_tutorial )`, use:
2023-01-12 22:00:14 +01:00
```
scons platform=server tools=no target=release_debug --jobs=$(sysctl -n hw.logicalcpu)
2023-01-12 22:00:14 +01:00
```
To compile a release *server* build which is optimized to run dedicated game servers,
2023-01-12 22:00:14 +01:00
use:
2023-01-12 22:00:14 +01:00
```
scons platform=server tools=no target=release --jobs=$(sysctl -n hw.logicalcpu)
2023-01-12 22:00:14 +01:00
```
## Building export templates
2023-01-12 19:43:03 +01:00
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
2023-01-12 19:43:03 +01:00
of those two architectures by leaving out the `lipo` step below.
2023-01-12 22:00:14 +01:00
- For Intel x86_64:
2023-01-12 22:00:14 +01:00
```
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)
2023-01-12 22:00:14 +01:00
```
2023-01-12 22:00:14 +01:00
- For ARM64 (Apple M1):
2023-01-12 22:00:14 +01:00
```
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)
2023-01-12 22:00:14 +01:00
```
To support both architectures in a single "Universal 2" binary, run the above
2023-01-12 22:00:14 +01:00
two commands blocks and then use `lipo` to bundle them together:
2023-01-12 22:00:14 +01:00
```
lipo -create bin/godot.osx.opt.x86_64 bin/godot.osx.opt.arm64 -output bin/godot.osx.opt.universal
lipo -create bin/godot.osx.opt.debug.x86_64 bin/godot.osx.opt.debug.arm64 -output bin/godot.osx.opt.debug.universal
2023-01-12 22:00:14 +01:00
```
2023-01-12 19:43:03 +01:00
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
2023-01-12 22:00:14 +01:00
`.universal` extension with the one of your arch-specific binaries):
2023-01-12 22:00:14 +01:00
```
cp -r misc/dist/osx_template.app .
mkdir -p osx_template.app/Contents/MacOS
cp bin/godot.osx.opt.universal osx_template.app/Contents/MacOS/godot_osx_release.64
cp bin/godot.osx.opt.debug.universal osx_template.app/Contents/MacOS/godot_osx_debug.64
chmod +x osx_template.app/Contents/MacOS/godot_osx*
2023-01-12 22:00:14 +01:00
```
2023-01-12 19:43:03 +01:00
You can then zip the `osx_template.app` folder to reproduce the `osx.zip`
2023-01-12 22:00:14 +01:00
template from the official Godot distribution:
2023-01-12 22:00:14 +01:00
```
zip -q -9 -r osx.zip osx_template.app
2023-01-12 22:00:14 +01:00
```
## Cross-compiling for macOS from Linux
It is possible to compile for macOS in a Linux environment (and maybe also in
Windows using the Windows Subsystem for Linux). For that, you'll need to install
2023-01-12 20:39:50 +01:00
`OSXCross ( https://github.com/tpoechtrager/osxcross )` to be able to use macOS
as a target. First, follow the instructions to install it:
2023-01-12 20:39:50 +01:00
Clone the `OSXCross repository ( https://github.com/tpoechtrager/osxcross )`
somewhere on your machine (or download a ZIP file and extract it somewhere),
2023-01-12 22:00:14 +01:00
e.g.:
2023-01-12 22:00:14 +01:00
```
git clone --depth=1 https://github.com/tpoechtrager/osxcross.git "$HOME/osxcross"
2023-01-12 22:00:14 +01:00
```
1. Follow the instructions to package the SDK:
https://github.com/tpoechtrager/osxcross#packaging-the-sdk
2. Follow the instructions to install OSXCross:
https://github.com/tpoechtrager/osxcross#installation
2023-01-12 19:43:03 +01:00
After that, you will need to define the `OSXCROSS_ROOT` as the path to
the OSXCross installation (the same place where you cloned the
2023-01-12 22:00:14 +01:00
repository/extracted the zip), e.g.:
2023-01-12 22:00:14 +01:00
```
export OSXCROSS_ROOT="$HOME/osxcross"
2023-01-12 22:00:14 +01:00
```
2023-01-12 22:00:14 +01:00
Now you can compile with SCons like you normally would:
2023-01-12 22:00:14 +01:00
```
scons platform=osx
2023-01-12 22:00:14 +01:00
```
2023-01-12 22:00:14 +01:00
If you have an OSXCross SDK version different from the one expected by the SCons buildsystem, you can specify a custom one with the `osxcross_sdk` argument:
2023-01-12 22:00:14 +01:00
```
scons platform=osx osxcross_sdk=darwin15
2023-01-12 22:00:14 +01:00
```