2019-10-17 18:42:13 +00:00
|
|
|
# Compiling OpenTTD
|
|
|
|
|
|
|
|
## Required/optional libraries
|
|
|
|
|
2021-04-21 17:42:42 +00:00
|
|
|
OpenTTD makes use of the following external libraries:
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2023-05-02 18:45:04 +00:00
|
|
|
- (encouraged) nlohmann-json: JSON handling
|
2021-04-21 17:42:42 +00:00
|
|
|
- (encouraged) zlib: (de)compressing of old (0.3.0-1.0.5) savegames, content downloads,
|
2019-10-17 18:42:13 +00:00
|
|
|
heightmaps
|
2021-04-21 17:42:42 +00:00
|
|
|
- (encouraged) liblzma: (de)compressing of savegames (1.1.0 and later)
|
|
|
|
- (encouraged) libpng: making screenshots and loading heightmaps
|
|
|
|
- (optional) liblzo2: (de)compressing of old (pre 0.3.0) savegames
|
|
|
|
|
2023-02-12 11:07:31 +00:00
|
|
|
For Linux, the following additional libraries are used:
|
2021-04-21 17:42:42 +00:00
|
|
|
|
2023-02-12 11:07:31 +00:00
|
|
|
- (encouraged) libcurl: content downloads
|
2021-04-21 17:42:42 +00:00
|
|
|
- libSDL2: hardware access (video, sound, mouse)
|
2019-10-17 18:42:13 +00:00
|
|
|
- libfreetype: loading generic fonts and rendering them
|
|
|
|
- libfontconfig: searching for fonts, resolving font names to actual fonts
|
2023-04-30 18:37:40 +00:00
|
|
|
- harfbuzz: handling of right-to-left scripts (e.g. Arabic and Persian) (required libicu)
|
2019-10-17 18:42:13 +00:00
|
|
|
- libicu: handling of right-to-left scripts (e.g. Arabic and Persian) and
|
2021-04-21 17:42:42 +00:00
|
|
|
natural sorting of strings
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2023-02-12 11:07:31 +00:00
|
|
|
If you are building a dedicated-server only, you don't need the last four.
|
|
|
|
|
2019-10-17 18:42:13 +00:00
|
|
|
OpenTTD does not require any of the libraries to be present, but without
|
|
|
|
liblzma you cannot open most recent savegames and without zlib you cannot
|
|
|
|
open most older savegames or use the content downloading system.
|
|
|
|
|
2021-04-21 17:42:42 +00:00
|
|
|
## Windows
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
You need Microsoft Visual Studio 2017 or more recent.
|
2019-10-17 18:42:13 +00:00
|
|
|
|
|
|
|
You can download the free Visual Studio Community Edition from Microsoft at
|
|
|
|
https://visualstudio.microsoft.com/vs/community/.
|
|
|
|
|
|
|
|
OpenTTD needs the Platform SDK, if it isn't installed already. This can be
|
|
|
|
done during installing Visual Studio, by selecting
|
|
|
|
`Visual C++ MFC for x86 and x64` (and possibly
|
|
|
|
`Visual C++ ATL for x86 and x64` depending on your version). If not, you
|
|
|
|
can get download it as [MS Windows Platform SDK](https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk).
|
|
|
|
|
|
|
|
Install the SDK by following the instructions as given.
|
|
|
|
|
|
|
|
Dependencies for OpenTTD on Windows are handled via
|
|
|
|
[vcpkg](https://github.com/Microsoft/vcpkg/). First you need to install vcpkg
|
|
|
|
by following the `Quick Start` instructions of their
|
|
|
|
[README](https://github.com/Microsoft/vcpkg/blob/master/README.md).
|
|
|
|
|
|
|
|
After this, you can install the dependencies OpenTTD needs. We advise to use
|
|
|
|
the `static` versions, and OpenTTD currently needs the following dependencies:
|
|
|
|
|
|
|
|
- liblzma
|
|
|
|
- libpng
|
|
|
|
- lzo
|
2023-05-02 18:45:04 +00:00
|
|
|
- nlohmann-json
|
2019-10-17 18:42:13 +00:00
|
|
|
- zlib
|
|
|
|
|
|
|
|
To install both the x64 (64bit) and x86 (32bit) variants (though only one is necessary), you can use:
|
|
|
|
|
|
|
|
```ps
|
2023-05-02 18:45:04 +00:00
|
|
|
.\vcpkg install liblzma:x64-windows-static libpng:x64-windows-static lzo:x64-windows-static nlohmann-json:x64-windows-static zlib:x64-windows-static
|
|
|
|
.\vcpkg install liblzma:x86-windows-static libpng:x86-windows-static lzo:x86-windows-static nlohmann-json:x86-windows-static zlib:x86-windows-static
|
2019-10-17 18:42:13 +00:00
|
|
|
```
|
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
You can open the folder (as a CMake project). CMake will be detected, and you can compile from there.
|
2021-02-05 15:10:42 +00:00
|
|
|
If libraries are installed but not found, you need to set VCPKG_TARGET_TRIPLET in CMake parameters.
|
|
|
|
For Visual Studio 2017 you also need to set CMAKE_TOOLCHAIN_FILE.
|
|
|
|
(Typical values are shown in the MSVC project file command line example)
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
Alternatively, you can create a MSVC project file via CMake. For this
|
|
|
|
either download CMake from https://cmake.org/download/ or use the version
|
|
|
|
that comes with vcpkg. After that, you can run something similar to this:
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
```powershell
|
|
|
|
mkdir build
|
|
|
|
cd build
|
2021-12-22 18:32:48 +00:00
|
|
|
cmake.exe .. -G"Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE="<location of vcpkg>\vcpkg\scripts\buildsystems\vcpkg.cmake" -DVCPKG_TARGET_TRIPLET="x64-windows-static"
|
2019-04-07 10:02:34 +00:00
|
|
|
```
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
Change `<location of vcpkg>` to where you have installed vcpkg. After this
|
|
|
|
in the build folder are MSVC project files. MSVC can rebuild the project
|
|
|
|
files himself via the `ZERO_CHECK` project.
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
## All other platforms
|
2021-02-05 15:10:42 +00:00
|
|
|
Minimum required version of CMake is 3.9.
|
2021-04-21 17:43:00 +00:00
|
|
|
By default this produces a Debug build with assertations enabled.
|
|
|
|
This is a far slower build than release builds.
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
```bash
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
cmake ..
|
|
|
|
make
|
|
|
|
```
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2021-01-02 19:54:57 +00:00
|
|
|
For more information on how to use CMake (including how to make Release builds),
|
|
|
|
we urge you to read [their excellent manual](https://cmake.org/cmake/help/latest/guide/user-interaction/index.html).
|
|
|
|
|
2021-04-21 17:43:00 +00:00
|
|
|
## CMake Options
|
|
|
|
|
|
|
|
Via CMake, several options can be influenced to get different types of
|
|
|
|
builds.
|
|
|
|
|
|
|
|
- `-DCMAKE_BUILD_TYPE=RelWithDebInfo`: build a release build. This is
|
2023-01-07 17:32:25 +00:00
|
|
|
significantly faster than a debug build, but has far less useful information
|
2021-04-21 17:43:00 +00:00
|
|
|
in case of a crash.
|
|
|
|
- `-DOPTION_DEDICATED=ON`: build OpenTTD without a GUI. Useful if you are
|
|
|
|
running a headless server, as it requires less libraries to operate.
|
|
|
|
- `-DOPTION_USE_ASSERTS=OFF`: disable asserts. Use with care, as assert
|
|
|
|
statements capture early signs of trouble. Release builds have them
|
|
|
|
disabled by default.
|
|
|
|
- `-DOPTION_USE_THREADS=OFF`: disable the use of threads. This will block
|
|
|
|
the interface in many places, and in general gives a worse experience of
|
|
|
|
the game. Use with care.
|
|
|
|
- `-DOPTION_TOOLS_ONLY=ON`: only build tools like `strgen`. Does not build
|
|
|
|
the game itself. Useful for cross-compiling.
|
|
|
|
|
2019-10-17 18:42:13 +00:00
|
|
|
## Supported compilers
|
|
|
|
|
2020-12-13 21:24:36 +00:00
|
|
|
Every compiler that is supported by CMake and supports C++17, should be
|
2019-04-07 10:02:34 +00:00
|
|
|
able to compile OpenTTD. As the exact list of compilers changes constantly,
|
2020-12-13 21:24:36 +00:00
|
|
|
we refer to the compiler manual to see if it supports C++17, and to CMake
|
2019-04-07 10:02:34 +00:00
|
|
|
to see if it supports your compiler.
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
## Compilation of base sets
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
To recompile the extra graphics needed to play with the original Transport
|
|
|
|
Tycoon Deluxe graphics you need GRFCodec (which includes NFORenum) as well.
|
|
|
|
GRFCodec can be found at
|
|
|
|
https://www.openttd.org/downloads/grfcodec-releases/latest.html.
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
Having GRFCodec installed can cause regeneration of the `.grf` files, which
|
|
|
|
are written in the source directory. This can leave your repository in a
|
|
|
|
modified state, as different GRFCodec versions can cause binary differences
|
|
|
|
in the resulting `.grf` files. Also translations might have been added for
|
|
|
|
the base sets which are not yet included in the base set information files.
|
|
|
|
To avoid this behaviour, disable GRFCodec (and NFORenum) in CMake cache
|
|
|
|
(`GRFCODEC_EXECUTABLE` and `NFORENUM_EXECUTABLE`).
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
## Developers settings
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
You can control some flags directly via `CXXFLAGS` (any combination
|
|
|
|
of these flags will work fine too):
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
- `-DRANDOM_DEBUG`: this helps with debugging desyncs.
|
|
|
|
- `-fno-inline`: this avoids creating inline functions; this can make
|
|
|
|
debugging a lot easier.
|
|
|
|
- `-O0`: this disables all optimizations; this can make debugging a
|
|
|
|
lot easier.
|
|
|
|
- `-p`: this enables profiling.
|
2019-10-17 18:42:13 +00:00
|
|
|
|
2019-04-07 10:02:34 +00:00
|
|
|
Always use a clean buildfolder if you changing `CXXFLAGS`, as this
|
|
|
|
value is otherwise cached. Example use:
|
|
|
|
|
|
|
|
`CXXFLAGS="-fno-inline" cmake ..`
|