Skip to content

Building OpenRCT2 on macOS using CMake

Daniel Shusta edited this page Nov 7, 2021 · 8 revisions

To build natively on macOS, without using Xcode, you will need a set of libraries set up. This guide assumes you already have the following installed:

  • A copy of the game files, downloaded onto your machine.
  • OS X Developer Tools
  • Homebrew / MacPorts / Fink
  • Xcode (optional)

Installing libraries

We'll install the libraries OpenRCT2 depends on through a package manager using the Terminal. We will be using Homebrew in the example below, but the equivalent command for MacPorts and Fink should look pretty similar.

brew install cmake duktape freetype icu4c libpng libzip nlohmann-json openssl pkg-config sdl2 speexdsp

Building OpenRCT2

Navigate to the directory OpenRCT2 is in (cd), then make a build directory and invoke cmake:

cd /path/to/repo/OpenRCT2
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=./install
make -j$(sysctl -n hw.logicalcpu) install # the install step builds openrct, g2 and downloads OpenRCT2 data

If any libraries are missing, you will see an error message. Adjust as needed or check out the Troubleshooting section below. Once all errors have been fixed we can start building:

make -j$(sysctl -n hw.logicalcpu) install

Now, before executing the game, link the just installed openrct2 data folder to the current directory to help openrct2 find it. Then run the game.

ln -s ./install/share/openrct2 data
./openrct2

The game will ask for the RCT2 installation path and will build object indices the first time it is started.

After the first install, you can build the openrct2 binaries, no install required:

make -j$(sysctl -n hw.logicalcpu)

Troubleshooting

Problem 1: When running cmake, I get the error -- No package 'openssl' found

Try out both solutions in problem 2

Problem 2: When running cmake or make, I get some other weird error involving openssl

Solution 1

First check if you actually built openssl for both the i386 and x86_64 architectures by running the following command, replacing the openssl version with the version you installed:

file /usr/local/Cellar/openssl/1.0.2h_1/lib/libcrypto.1.0.0.dyl

This should output

/usr/local/Cellar/openssl/1.0.2h_1/lib/libcrypto.1.0.0.dylib: Mach-O universal binary with 2 architectures
/usr/local/Cellar/openssl/1.0.2h_1/lib/libcrypto.1.0.0.dylib (for architecture x86_64):	Mach-O 64-bit dynamically linked shared library x86_64
/usr/local/Cellar/openssl/1.0.2h_1/lib/libcrypto.1.0.0.dylib (for architecture i386):	Mach-O dynamically linked shared library i386

If only i386 or x86_64 are listed, then you will need to run brew reinstall openssl --universal.

Solution 2

If you are sure the library is built for both architectures, it is possible that the build script is using OS X's version of openssl instead of the one installed by brew. To fix this run:

brew link --force openssl

Anything that needs to build against openssl will use brew's version now. If you want to undo this in the future, you can always run brew unlink openssl.

Problem 3: When running cmake, I get the error -- No package 'gl' found

Solution

The reason this is happening is because pkg-config (run by cmake) is not finding a gl.pc file. To solve this we will create our own gl.pc file and tell pkg-config where to find it.

First create a pkgconfig folder in the directory where you cloned OpenRCT:

cd ..
mkdir pkgconfig
cd pkgconfig

Using your favourite editor, create a file called gl.pc with the following content:

PACKAGE=GL

Name: OpenGL
Description: OpenGL
Version: 11.1.1
Cflags: -framework OpenGL -framework AGL
Libs: -Wl,-framework,OpenGL,-framework,AGL

Now tell pkg-config where to find this file and go back to the build directory:

export PKG_CONFIG_PATH=$(pwd):$PKG_CONFIG_PATH
cd ../build

You should find that cmake will now find the gl package.

Problem 4: When running cmake, I get the error ld: library not found for -lSDL2

Solution

It is possible that brew was unable to create the relevant symlinks for SDL2 due to permissions problems. To fix this, do the following:

sudo chown root:wheel /usr/local/bin/brew
sudo brew link sdl2

If this doesn't work, chances are /usr/local/lib isn't in your LIBRARY_PATH. To fix this, add the following line to your ~/.bash_profile and then restart the Terminal.

export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/lib"

Problem 5: cmake cannot find the required ICU library

Solution

If your brew-installed ICU package cannot be found by cmake, it probably hasn't been linked to a common location. To work around this, invoke:

export CMAKE_PREFIX_PATH=/usr/local/opt/icu4c
cmake ..

Running OpenRCT2

Fire up the binary or application you just built. You should be good to go!

That's it! If you run into problems please paste all of the information you have into a GitHub issue and we'll take a look.

Clone this wiki locally