2023-01-12 20:49:14 +01:00
2023-04-06 23:28:17 +02:00
# Compiling for macOS
2022-03-18 17:46:08 +01:00
2023-04-06 23:28:17 +02:00
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` .
2022-03-18 17:46:08 +01:00
2023-04-06 23:28:17 +02:00
## Requirements
2022-03-18 17:46:08 +01:00
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 )`
2022-03-18 17:46:08 +01:00
(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).
2022-03-18 17:46:08 +01:00
2023-04-06 23:28:17 +02:00
### Note:
If you have `Homebrew ( https://brew.sh/ )` installed, you can easily install SCons and yasm using the following command:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
brew install scons yasm
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
2023-04-06 23:28:17 +02:00
Installing Homebrew will also fetch the Command Line Tools for Xcode automatically if you don't have them already.
2022-03-18 17:46:08 +01:00
2023-04-06 23:28:17 +02:00
Similarly, if you have `MacPorts ( https://www.macports.org/ )` installed, you can easily install
SCons and yasm using the following command:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
sudo port install scons yasm
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
2024-03-16 20:56:52 +01:00
To get the Pandemonium source code for compiling, see `doc_getting_source` .
2022-09-10 12:15:58 +02:00
2024-03-16 20:56:52 +01:00
For a general overview of SCons usage for Pandemonium, see `doc_introduction_to_the_buildsystem` .
2022-03-18 17:46:08 +01:00
2023-04-06 23:28:17 +02:00
## Compiling
2022-03-18 17:46:08 +01:00
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
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
scons platform=osx arch=x86_64 --jobs=$(sysctl -n hw.logicalcpu)
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
To compile for Apple Silicon (ARM64) powered Macs, use:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
scons platform=osx arch=arm64 --jobs=$(sysctl -n hw.logicalcpu)
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +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:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2024-03-16 20:56:52 +01:00
lipo -create bin/pandemonium.osx.tools.x86_64 bin/pandemonium.osx.tools.arm64 -output bin/pandemonium.osx.tools.universal
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
2023-04-06 23:28:17 +02: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.
2022-03-18 17:46:08 +01:00
2024-03-16 20:56:52 +01:00
If you want to use separate editor settings for your own Pandemonium builds and official releases, you can enable
2023-04-06 23:28:17 +02:00
`doc_data_paths_self_contained_mode` by creating a file called `._sc_` or `sc_` in the `bin/` folder.
2022-03-18 17:46:08 +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_tools.app` . Typically, for an optimized
2023-01-12 22:00:14 +01:00
editor binary built with `target=release_debug` :
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2024-03-16 20:56:52 +01:00
cp -r misc/dist/osx_tools.app ./Pandemonium.app
mkdir -p Pandemonium.app/Contents/MacOS
cp bin/pandemonium.osx.opt.tools.universal Pandemonium.app/Contents/MacOS/Pandemonium
chmod +x Pandemonium.app/Contents/MacOS/Pandemonium
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
2023-04-06 23:28:17 +02:00
## Compiling a headless/server build
2022-03-18 17:46:08 +01:00
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:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
scons platform=server tools=yes target=release_debug --jobs=$(sysctl -n hw.logicalcpu)
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +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:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
scons platform=server tools=no target=release_debug --jobs=$(sysctl -n hw.logicalcpu)
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +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:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
scons platform=server tools=no target=release --jobs=$(sysctl -n hw.logicalcpu)
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
2023-04-06 23:28:17 +02:00
## Building export templates
2022-03-18 17:46:08 +01:00
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` .
2022-03-18 17:46:08 +01:00
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.
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
- For Intel x86_64:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +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
```
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
- For ARM64 (Apple M1):
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +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
```
2022-03-18 17:46:08 +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:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2024-03-16 20:56:52 +01:00
lipo -create bin/pandemonium.osx.opt.x86_64 bin/pandemonium.osx.opt.arm64 -output bin/pandemonium.osx.opt.universal
lipo -create bin/pandemonium.osx.opt.debug.x86_64 bin/pandemonium.osx.opt.debug.arm64 -output bin/pandemonium.osx.opt.debug.universal
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +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
2024-03-16 20:56:52 +01:00
`pandemonium_osx_release.64` and `pandemonium_osx_debug.64` respectively. You can do so
2022-03-18 17:46:08 +01:00
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):
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
cp -r misc/dist/osx_template.app .
mkdir -p osx_template.app/Contents/MacOS
2024-03-16 20:56:52 +01:00
cp bin/pandemonium.osx.opt.universal osx_template.app/Contents/MacOS/pandemonium_osx_release.64
cp bin/pandemonium.osx.opt.debug.universal osx_template.app/Contents/MacOS/pandemonium_osx_debug.64
chmod +x osx_template.app/Contents/MacOS/pandemonium_osx*
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
2023-01-12 19:43:03 +01:00
You can then zip the `osx_template.app` folder to reproduce the `osx.zip`
2024-03-16 20:56:52 +01:00
template from the official Pandemonium distribution:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
zip -q -9 -r osx.zip osx_template.app
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
2023-04-06 23:28:17 +02:00
## Cross-compiling for macOS from Linux
2022-03-18 17:46:08 +01:00
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
2022-03-18 17:46:08 +01:00
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 )`
2022-03-18 17:46:08 +01:00
somewhere on your machine (or download a ZIP file and extract it somewhere),
2023-01-12 22:00:14 +01:00
e.g.:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
git clone --depth=1 https://github.com/tpoechtrager/osxcross.git "$HOME/osxcross"
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +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
2022-03-18 17:46:08 +01:00
the OSXCross installation (the same place where you cloned the
2023-01-12 22:00:14 +01:00
repository/extracted the zip), e.g.:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
export OSXCROSS_ROOT="$HOME/osxcross"
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
Now you can compile with SCons like you normally would:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
scons platform=osx
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +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:
2022-03-18 17:46:08 +01:00
2023-01-12 22:00:14 +01:00
```
2022-03-18 17:46:08 +01:00
scons platform=osx osxcross_sdk=darwin15
2023-01-12 22:00:14 +01:00
```