Loading...
 

Compiling Simutrans


Normally you install and run Simutrans from one of the available executables, 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 subforum 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
libSDL2  http://www.libsdl.org/link-external Necessary* *On Linux & Mac. Optional but recommended for Windows. Graphics back-end
bzip2  http://www.bzip.org/downloads.htmllink-external Optional Alternative compression. You can pick this or zstd
libzstd https://github.com/facebook/zstdlink-external Optional Alternative compression. You can pick this or bzip2
pkgconf http://pkgconf.org/link-external Optional Needed by FreeType/SDL/makeobj
libpng http://www.libpng.org/pub/png/link-external Optional Used by makeobj
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 with support for changing soundfonts. Recommended on Linux & Mac.
libSDL2_mixer http://www.libsdl.org/link-external Optional Alternative MIDI playback and sound system.


Libraries for MSYS2 / Linux / Maclink


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

  1. Download MSVC Studio Community edition.
  2. Download a git tool and clone https://github.com/Microsoft/vcpkglink-external to an arbitary directory (if you are using CMake the “build” directory is recommended).
  3. Run bootstrap-vcpkg.bat
  4. Copy install-building-libs.bat from simutrans/trunk to this folder and execute it, or install libraries the libraries you want manually:
./vcpkg/vcpkg --triplet x64-windows-static install zlib bzip2 libpng ztsd sdl2 freetype miniupnpc fluidsynth

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

If you are using other version or prefer to compile the libraries yourself, check this forum thread link-external.

Compilinglink

Go to the source code directory of simutrans (simutrans/trunk if you downloaded from svn).

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

If you want a 32 bit executable change “x64” to “Win32”
cmake.exe .. -G "Visual Studio 16 2019" -A x64.

3. Build Simutranslink

The executable will be built in build/simutrans. By default this will only compile the simutrans target. If you want to build makeobj call cmake with --target makeobj.

Linux & MinGWlink

cmake --build .

MacOSlink

MacOS users may want to add the --target install option to generate an app bundle instead.
cmake --build . --target install

MSVClink

With MSVC you need to set the build type at this step:
cmake --build . --target simutrans --config Release


Compiling with makelink


MacOSlink

  1. Open a terminal and run autoreconf -ivf
  2. Now run ./configure
  3. Type make AV_FOUNDATION=1 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 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: Prefered backend for Simutrans.
  • Simutrans GDI: Windows-only backend.
  • Simutrans Server: Server backend 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 optimised code but using revision data just like debug. This is meant for creating optimised nightly builds for servers.

Cross-Compilinglink

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

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 October 9, 2021 11:59:46 CEST by Roboron3042.

Online Users

5 online users

Newest Forum Posts

No records to display