Skip to content

Building OpenRCT2 on Linux

Michał Janiszewski edited this page Jan 4, 2019 · 91 revisions

You can only build OpenRCT2 on little-endian architectures for now.

This page tells you how to build the project. For instructions on how to get assets and run it check https://github.com/OpenRCT2/OpenRCT2/wiki/Installation-on-Linux-and-macOS.

Required Packages (General)

To build natively on Linux, you will need a set of libraries set up. Since most distributions come with a package manager, we expect you to use that. Required libraries include:

  • sdl2 (only for UI client)
  • fontconfig (can be disabled)
  • libzip (>= 1.0)
  • libpng (>= 1.2)
  • speexdsp (only for UI client)
  • curl (only if building with http support)
  • jansson (>= 2.5)
  • openssl (>= 1.0; only if building with multiplayer support)
  • icu (>= 59.0)
  • zlib
  • gl (commonly provided by Mesa or GPU vendors; only for UI client, can be disabled)
  • cmake

Additionally, you can add support for Discord's Rich Presence API by cloning https://github.com/discordapp/discord-rpc into the root clone directory. Do note discord-rpc requires rapidjson, which don't bother fixing their bugs and you may need the hackish workaround: https://github.com/janisozaur/rapidjson/commit/20f8604ee6cd078c1cb2346148c69c0c2c160db2

APT (Debian, Ubuntu)

This solution is tested continuously by Travis.

The exact package names will differ from distribution to distribution, but here's a short list of the common ones:

sudo apt-get install --no-install-recommends -y cmake libsdl2-dev libicu-dev \
    gcc pkg-config libjansson-dev libspeex-dev libspeexdsp-dev libcurl4-openssl-dev \
    libcrypto++-dev libfontconfig1-dev libfreetype6-dev libpng-dev libssl-dev libzip-dev

This listing should work on Debian and Ubuntu.

pacman (Arch)

This solution is tested continuously with our own dockerfile and then travis.

Install dependencies:

sudo pacman -S sdl2 curl jansson speexdsp fontconfig libpng openssl libzip gcc gcc-libs icu

DNF (Fedora):

Run the following for depdencies, then proceed with Linux build instructions.

sudo dnf install gcc gcc-c++ jansson-devel \
    openssl-devel SDL2-devel libicu-devel \
    speexdsp-devel libcurl-devel \
    cmake fontconfig-devel freetype-devel \
    libpng-devel libzip-devel mesa-libGL-devel

Gentoo

This section is outdated and needs an update to reflect we can now build for x86_64 and other little-endian platforms.

This install requires either plain x86 system or amd64 with multilib enabled.

With regular x86 system, you just need to configure the sources with cmake (see below) and compile.

On amd64 you first need to enable multilib and then add abi_x86_32 to at least following libraries:

# cat /etc/portage/package.use/abi_x86_32
## Please note that this library list may be incomplete due to USE flag differences
dev-libs/jansson        abi_x86_32
media-libs/libsdl2      abi_x86_32
media-libs/sdl2-mixer   abi_x86_32
media-libs/speex        abi_x86_32
net-misc/curl           abi_x86_32

Then you need to emerge required libraries and in case portage gives shows some dependency issues, fix up the libraries with missing abi_x86_32 flags by adding them to the list above.

openSUSE

Install dependencies:

# Outdated as of 2019-01-04, OpenRCT2 requires C++17 which ships with GCC7+
sudo zypper in SDL2-devel fontconfig libzip5 libzip-devel libpng speexdsp-devel curl libjansson-devel openssl glibc zlib cmake gcc gcc5 gcc5-c++

Notes for Leap

Leap uses gcc4 by default, OpenRCT2 needs gcc5. You'll need to fix the symlinks for g++ and c++ to point to g++-5. Tumbleweed is using gcc5 by default now. Outdated as of 2019-01-04, OpenRCT2 requires C++17 which ships with GCC7+

Alpine Linux

Install dependancies:

apk add git gcc g++ jansson-dev libzip-dev curl-dev libressl-dev sdl2-dev fontconfig-dev fts-dev

(Dependency fts may not be required in the future, see #5520)
(You may wish to install Zenity or KDialog, see #5521)

Compiling

mkdir build && cd build
cmake .. # remember to set your build flags, e.g. -DCMAKE_BUILD_TYPE=RelWithDebInfo
make

This will generate a openrct2 binary in the build directory. To run you have two options: make install or running it locally.

make install

make install

make install will download required resources (json objects, title sequences) and installs openrct2 under /usr/local by default, but DESTDIR will be properly honoured (see below).

Running it from the build directory

Alternatively you can install the required resources manually so can launch openrct2 from the project directory. You need a functional data directory next to the current working directory when you start openrct2.

An easy way to generate such a data directory is by leveraging make install. Type the following in the build directory:

DESTDIR=. make install

Alternatively you can install these assets yourself. The following needs to satisfied:

$XDG_CONFIG_HOME/OpenRCT2/ (or ~/.config/OpenRCT2/ in its absence) has to have config.ini with game_path set to an RCT install. openrct2 will ask you for this directory when it first starts.

Keep in mind you can symlink stuff and that filesystems are case sensitive!

Alternatively you can specify the data directory like this

./openrct2 --openrct-data-path=../data

OR

Just symlink the data directory in the current build directory, which is the easiest approach for development

ln -s ../data data

Clang

Building with clang works the same way as building with GCC, you just need to change the CXX environment variable. Keep in mind, that you need to have an empty build directory as cmake will not switch compilers after it has already generated a Makefile.

mkdir build && cd build
export CXX=$(which clang++)
# OpenRCT2 is purely a C++ project, there's no need to set CC
cmake ..
make

See the optimisation note above.

discord-rpc

https://github.com/OpenRCT2/OpenRCT2/pull/6658 added support for discord-rpc, Discord's Rich Presence client library. It gets automatically picked up when cloned into the root of repository. Our Travis-CI jobs offer packages with discord-rpc compiled in.

Docker

Docker is a nice way of doing things when you have problems installing all the dependencies or just want to test on clean system. Docker containers are ephemeral snapshots of a specified system (described via Dockerfile), where you can run your commands.

Let's see example from our current build.sh:

PARENT=`readlink -f ../`
chmod a+rwx `pwd`
chmod g+s `pwd`
docker run -u travis -v $PARENT:/work/openrct2 -w /work/openrct2/build -i -t openrct2/openrct2:32bit-only bash -c "cmake ../ $OPENRCT2_CMAKE_OPTS && make"

This runs specified command (bash -c "cmake ../ $OPENRCT2_CMAKE_OPTS && make") interactively as a travis user (https://github.com/OpenRCT2/OpenRCT2/blob/develop/dockerfiles/32bit/Dockerfile#L7), having previously mounted your local (host's) $PARENT as container's /work/openrct2, and will use /work/openrct2/build as cwd.

You may want to update mountpoints so you can reflect your local paths easily, especially when debugging.

Apart from contents of mounted volumes, all results of commands you executed in this container will be gone after it exits.

MinGW

To build using mingw toolchain, you will need the toolchain itself, cmake and some basic system utilities you likely already have (bash, unzip, wget, sha256sum).

The install.sh script should largely handle that case. Said script should also download latest version of zip including precompiled libraries we use in the project and copy extracted contents to places where you could expect to find them.

Keep in mind we have no capacity to test the script thoroughly and while some caution and code review has been applied, it's possible that the script doesn't work properly or even breaks things. We welcome any patch to solve these kinds of problems.

The most competent part of the script has been written to support travis, if in doubt do as travis would do.

Consult build matrix in .travis.yml or study CMakeLists.txt file to see what options are there, but in most basic case you should be fine with just

export OPENRCT2_CMAKE_OPTS="-DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows

build.sh is (roughly) just a fancy wrapper for

cmake -DCMAKE_BUILD_TYPE=Debug $OPENRCT2_CMAKE_OPTS ..
make

You can use either the script or invoke make directly.

To launch the game, you would simply start openrct2.exe using wine or windows.

Clone this wiki locally
You can’t perform that action at this time.