Loading...
 

Compiling Simutrans


Normally you install and run Simutrans from one of the available downloads, but if you wish to modify the source code yourself, and perhaps create patches and contribute to the development of the executable, you will need to be able to compile Simutrans yourself. This is a short guide on how to do just that.

If you are on Windows, download either Microsoft Visual Studiolink-external or MSYS2link-external. MSVC is easy for debugging, MSYS2 is easy to set up (but it has to
be done on the command line).

These instruction are based on the readme.txt distributed with the source code. Please consult that document for any updates that might have been added since this page was last updated. You can also check the Development Support sub-forum link-external

Getting the Source Codelink

You can download the latest version with a SVN client. The primary repository for the Simutrans source code is
$ svn checkout svn://servers.simutrans.org/simutrans/trunk

If you prefer to use git, there is a mirror of the svn repository available thanks to aburch at github which you can make a local clone of:
$ git clone http://github.com/aburch/simutrans.git

Note that the svn repository is the main repository, and the git repository is just a mirror. If you use git instead of svn, you will need to set the game version manually for network play.

Getting the librarieslink


Simutrans required librarieslink

This is a list of libraries used by Simutrans. Not all of them are necessary, some are optional, so pick them according to your needs.
Library Website Necessary? Notes
zlib https://zlib.net/link-external Necessary Basic compression support
bzip2  https://www.bzip.org/downloads.htmllink-external Necessary Alternative compression. You can pick this or zstd
libpng http://www.libpng.org/pub/png/link-external Necessary Image manipulation
libSDL2  http://www.libsdl.org/link-external Necessary* *On Linux & Mac. Optional but recommended for Windows. Graphics back-end
libzstd https://github.com/facebook/zstdlink-external Optional Alternative compression (larger save files than bzip2, but faster)
libfreetype http://www.freetype.org/link-external Optional TrueType font support
libminiupnpc http://miniupnp.free.fr/link-external Optional Easy Server option
libfluidsynth https://www.fluidsynth.org/link-external Optional MIDI playback recommended on Linux & temporarily on Mac.
libSDL2_mixer http://www.libsdl.org/link-external Optional Alternative MIDI playback and sound system.


Libraries for MSYS2 / Linux / Maclink

  • You'll additionally need pkgconf installed (it usually comes pre-installed).
  • For Linux/Unix you can use pkgs.orglink-external to search for packages if they are unlisted (or outdated) below.
  • For Mac you will need to install libraries via Homebrew link-external.
  • MSYS2 libraries marked with "*" need manual compiling/intervention.

Library Brew (Mac) Debian/Ubuntu Arch Linux Fedora OpenSUSE MSYS2
zlib zlib zlib1g-dev zlib zlib-devel zlib-devel mingw-w64-x86_64-zlib
libSDL2  sdl2 libsdl2-dev sdl2 SDL2-devel libSDL2-devel mingw-w64-x86_64-SDL2
bzip2  bzip2  libbz2-dev bzip2  bzip2-devel libbz2-devel mingw-w64-x86_64-bzip2
libzstd zstd libzstd-dev zstd libzstd-devel libzstd-devel mingw-w64-x86_64-zstd
pkgconf pkg-config pkgconf pkgconf pkgconf pkgconf mingw-w64-x86_64-pkg-config
libpng libpng libpng-dev libpng libpng-devel libpng16-devel mingw-w64-x86_64-libpng
libfreetype freetype libfreetype6-dev freetype2  freetype-devel freetype2-devel mingw-w64-x86_64-freetype*
libminiupnpc miniupnpc libminiupnpc-dev miniupnpc miniupnpc-devel miniupnpc-devel mingw-w64-x86_64-miniupnpc*
libfluidsynth fluidsynth libfluidsynth-dev fluidsynth fluidsynth-devel fluidsynth-devel mingw-w64-x86_64-fluidsynth*
libSDL2_mixer sdl2_mixer libsdl2-mixer-dev sdl2_mixer SDL2_mixer-devel libSDL2_mixer-devel mingw-w64-x86_64-SDL2_mixer


Libraries for Microsoft Visual Studiolink

Note: Simutrans Extended (without CMake) does not support using vcpkg. If you wish to compile without CMake, check this forum threadlink-external that explain in more detail how to set libraries for Simutrans Extended in MSVC.
  1. Download a git tool and clone https://github.com/Microsoft/vcpkglink-external to an arbitrary directory that we will call vcpkg-root.
  2. Run bootstrap-vcpkg.bat
  3. Copy tools/install-building-libs-x64.bat to this folder and execute it, or install the libraries you want manually:
./vcpkg/vcpkg --triplet x64-windows-static install zlib bzip2 libpng zstd sdl2 freetype miniupnpc

Change the triplet according to your system (for example, "x86-windows-static" for 32-bit builds).

Compilinglink

Go to the source code directory of simutrans (simutrans/trunk if you downloaded from svn). You have three build systems to choose from: make, MSVC, and CMake. We recommend make or MSVC for debug builds.

Compiling will give you only the executable, you still need a Simutrans installation to run the program. You can start simutrans with `-use_workdir` to point it to an existing installation.

Compiling with CMakelink

CMake makes easy to generate build files for various build systems, and the steps for doing so are pretty standard.

1. Create the build directorylink

mkdir build && cd build

2. Generate build fileslink

Options will be set automatically depending on the libraries found. You may want to set options manually when generating build files, for example the graphics backend (gdi, sdl2 or none) can be set with option -DSIMUTRANS_BACKEND=sdl2. For a list of options execute:
cmake -LH ..

Linux & MacOSlink

Change "Release" to "Debug" if you want a debug build.
cmake -DCMAKE_BUILD_TYPE=Release ..

MSYS MinGWlink

Change "Release" to "Debug" if you want a debug build.
cmake -DCMAKE_BUILD_TYPE=Release -G "MSYS Makefiles" ..

MSVClink

For generating build files using the command line run the following. If you want a 32 bit executable change "x64" to "Win32"
cmake.exe .. -G "Visual Studio 16 2019" -A x64 -DCMAKE_TOOLCHAIN_FILE=[vcpkg-root]/scripts/buildsystems/vcpkg.cmake

If you are using the GUI, Visual Studio will try to generate the cache automatically if you open the simutrans source directory, but it will probably fail if you have not set the path to vcpkg toolcchain. So first go to Project -> Configuration and set the "CMake toolchain file" to "vcpkg-root/scripts/buildsystems/vcpkg.cmake" and the re-generate the cache with Project -> Generate Cache.

3. Build Simutranslink

The executable will be built in build/simutrans.

Linux /MinGW/MacOSlink

cmake --build . -j cores

Replace "cores" with the number of cores in your procesor. You can find that number running the following command:
  • Linux: nproc
  • Mac: sysctl -n hw.logicalcpu

MSVClink

With MSVC you need to set the build type at this step in the command line:
cmake --build . --target install --config Release

If you are using the GUI, just select Compile.

Compiling with makelink

The executable will be built in build/default.

MacOSlink

Compiling with make on MacOS is currently not supported. Use CMake instead.
  1. Open a terminal and run autoreconf -ivf
  2. Now run ./configure
  3. Type make AV_FOUNDATION=1 -j $(sysctl -n hw.logicalcpu) to compile Simutrans*
  4. Also type make OSX/getversion

  • AVFoundation must be specified on MacOS 10.12 or later, but the midi playback is currently broken. If you care about music try Fluidsynth (USE_FLUIDSYNTH_MIDI=1) instead.

GCC Systemslink

  1. Open a terminal and run autoconf
  2. Now run ./configure
  3. Finally type make -j $(nproc) to compile Simutrans

Manual configuration with makelink

  1. Go to the source code directory of simutrans
  2. Copy the file config.template to config.default and edit the file. You need to specify:
    • BACKEND = sdl2
    • OSTYPE = (you should know it)
  3. Additionally, you may want to set the following flags too:
Flag Description
OPTIMISE=1  Add umpteen optimisation flags
DEBUG= 1  Up to 3, enable the debug build
MULTI_THREAD = 1  Enable multi-core CPU support
USE_FREETYPE = 1  Enable Truetype font support. Set also FREETYPE_CONFIG
FREETYPE_CONFIG=freetype-config If it fails, try with FREETYPE_CONFIG=pkg-config freetype2
USE_UPNP = 1  Easy server hosting behind routers
USE_ZSTD = 1  Compression for savegames
USE_FLUIDSYNTH_MIDI = 1  Use Fluidsynth music backend for MIDI playback


Finally, type make. If you want a smaller program and do not care about error messages, you can comment out #DEBUG=1 and run strip sim (Unix) or strip sim.exe (Windows) after compiling and linking.

Compiling with Microsoft Visual Studiolink

Simutrans solution is a single solution file with 4 projects:
  • Simutrans-Main: The project that holds the shared, non back-end specific, files. All the followings use Main to build the specific back-end executables.
  • Simutrans SDL2: Preferred back-end for Simutrans.
  • Simutrans GDI: Windows-only back-end.
  • Simutrans Server: Server back-end with no graphical interface.

There are 3 compilation configurations for the main executable:
  • Debug is meant for developing
  • Stable is meant for compiling stable versions
  • Release builds optimized code but using revision data just like debug. This is meant for creating optimized nightly builds for servers.

Cross-Compilinglink

If you want to cross-compile Simutrans from Linux for Windows, see en_Cross-Compiling_Simutrans page.

Distributionlink

When you compile Simutrans you will only get the executable file. If you want a full distribution ready to play, follow the next steps.

(Windows only) Setting up NSISlink

NSIS must be properly installed and configured to build the pakset installer with the following plugins:

MinGWlink

1. Install the package mingw-w64-x86_64-nsis
2. Unpack the unicode version of the plugins in "/msys64/mingw64/share/nsis/unicode"

MSVClink

1. Download NSIS https://nsis.sourceforge.io/Downloadlink-external
2. Install NSIS in the default location (Program Files (x86))
3. Install the plugins either unpacking manually the unicode version in /Program Files (x86)/NSIS/Plugins/x86-unicode or by running in Powershell the prepare-nsis.ps1 script you can find in the .github directory of simutrans source code.

Prepare the distributionlink

This step will generate automatically a ready to play installation of Simutrans by doing the following:

  • Copy the contents of the simutrans directory into the executable location.
  • Update the language files with the latest translations.
  • In MacOS it will also generate an app bundle.
  • In Windows it will also build the pakset installer if NSIS is found.

Mingw/Linux/Maclink

You can run ./distribute.sh which will give you a zip file that contains everything needed to run simutrans.

CMakelink

Run the build step with the "--target install" option to generate a ready to play installation in build/simutrans.

Contributelink

If you want to contribute, read the coding guidelines in simutrans/documentation/coding_styles.txt
You definitely should check out the international forumlink-external as well.

Problemslink


Rate this page:

Contributors to this page: Roboron3042 , Frank , IgorEliezer and system .
Page last modified on Saturday February 5, 2022 23:01:56 GMT-0000 by Roboron3042.

Online Users

13 online users

Newest Forum Posts

No records to display