Compile GZDoom on Linux

From ZDoom Wiki
Jump to navigation Jump to search

Open a terminal and copy and paste the whole code box for each step.

Notes

Starting with commit c219811a5:

cd ~/gzdoom_build/gzdoom &&
git show c219811a542e0d6aae38b920ae9e257c5c2286c1

consider GZDoom as licensed under the GPL, therefore; the following is unnecessary but will be keep in this tutorial for the users who still need to use GZDoom 2.x or older versions: #Download FMOD, liboutput_sdl.so, the FMOD library file, the environment variable LD_LIBRARY_PATH and the CMake variables NO_FMOD, FMOD_LIBRARY and FMOD_INCLUDE_DIR.

The minimum requirement for GZDoom 2.2 and later is OpenGL 2.0, so if you get the following error:

Unsupported OpenGL version.

At least OpenGL 2.0 is required to run GZDoom.

you will have to use #GZDoom 1.8.6 instead. Keep in mind that this version is several years old and no longer maintained. It will also have problems with more recent actively maintained mods.

Install dependencies

GZDoom needs certain tools and development files in order to compile:

  • Required
    • gcc 4.8 or later
    • make
    • cmake 2.8.7 or later
    • SDL 2.0.2 or later
    • libGL and libGLU (SDL or libSDL pull in libGLU) or any other GL implementation provider.
    • ZMusic
  • Recommended
    • GTK3 or GTK2
    • git (needed in order to download the source and compile in commit meta data)
    • nasm 0.98.39 or later (x86-32 only)
  • Optional
    • zlib (GZDoom has a copy of it and will be statically compiled in if not found)
    • libbzip2 (possibly static)
    • libjpeg (possibly static)
    • libgme or game-music-emu (possibly static)
    • SDL 1.2.8 or later 1.2.x versions (for GZDoom 1.x)
    • libglew (for GZDoom 1.x)
    • FMOD Ex 4.36.x or later or FMOD Studio (for GZDoom 1.x and 2.x)
  • Runtime
    • gxmessage (optional - needed to show the crash log in a window)
    • kdialog (optional - for KDE users)
    • fluidsynth (optional - for MIDI playback)

In addition to or instead of FMOD, OpenAL can be used for sound in which case the following are required:

Install the following as root/superuser:

Debian/Ubuntu

sudo apt-get install g++ make cmake libsdl2-dev git zlib1g-dev \
libbz2-dev libjpeg-dev libfluidsynth-dev libgme-dev libopenal-dev \
libmpg123-dev libsndfile1-dev libgtk-3-dev timidity nasm \
libgl1-mesa-dev tar libsdl1.2-dev libglew-dev libvpx-dev

Fedora

dnf install gcc-c++ make cmake SDL2-devel git zlib-devel bzip2-devel \
libjpeg-turbo-devel fluidsynth-devel game-music-emu-devel openal-soft-devel \
libmpg123-devel libsndfile-devel gtk3-devel timidity++ nasm \
mesa-libGL-devel tar SDL-devel glew-devel libvpx-devel

openSUSE

zypper si -d gzdoom

Mageia

a='' && [ "$(uname -m)" = x86_64 ] && a=64
urpmi gcc-c++ make cmake lib${a}sdl2.0-devel git lib${a}zlib-devel \
lib${a}bzip2-devel lib${a}jpeg-devel lib${a}fluidsynth-devel \
lib${a}gme-devel lib${a}openal-devel lib${a}mpg123-devel lib${a}sndfile-devel \
lib${a}gtk+3.0-devel lib${a}cairo-devel TiMidity++ nasm \
lib${a}mesagl1-devel tar lib${a}SDL-devel lib${a}glew-devel lib${a}vpx-devel

Arch Linux

pacman -S --needed gcc make cmake sdl2 git zlib bzip2 libjpeg-turbo \
fluidsynth libgme openal mpg123 libsndfile gtk3 timidity++ nasm \
mesa glu tar sdl glew libvpx

Gentoo

emerge -avn sys-devel/gcc sys-devel/make dev-util/cmake media-libs/libsdl2 \
dev-vcs/git sys-libs/zlib app-arch/bzip2 media-libs/libjpeg-turbo media-sound/fluidsynth \
media-libs/game-music-emu media-libs/openal media-sound/mpg123 media-libs/libsndfile \
x11-libs/gtk+ media-sound/timidity++ dev-lang/nasm media-libs/mesa \
media-libs/glu app-arch/tar media-libs/libsdl media-libs/glew media-libs/libvpx

Update (29.12.2016): Jacendi overlay has an ebuild for gzdoom

emerge -n layman
layman -a jacendi-overlay
emerge -av gzdoom

PCLinuxOS

a='' && [ "$(uname -m)" = x86_64 ] && a=64
apt-get install gcc-c++ make cmake lib${a}sdl2.0-devel git zlib1-devel \
lib${a}bzip2-devel lib${a}jpeg62-devel lib${a}fluidsynth1-devel lib${a}openal-devel \
lib${a}mpg123-devel lib${a}sndfile-devel lib${a}gtk+3.0-devel TiMidity++ nasm \
lib${a}mesagl1-devel tar lib${a}SDL-devel lib${a}glew-devel lib${a}vpx-devel

Solus

sudo eopkg install g++ make cmake binutils glibc-devel pkg-config sdl2-devel \
git zlib-devel bzip2-devel libjpeg-turbo-devel fluidsynth-devel openal-soft-devel \
mpg123-devel libsndfile-devel libgtk-3-devel nasm mesalib-devel \
libglu-devel tar sdl1-devel glew-devel libvpx

Do the following sections as normal user.

Compile ZMusic

Create zmusic_build directory:

mkdir -pv ~/zmusic_build

Download the ZMusic source and create build directory:

cd ~/zmusic_build &&
git clone https://github.com/ZDoom/ZMusic.git zmusic &&
mkdir -pv zmusic/build

To compile ZMusic:

cd ~/zmusic_build/zmusic/build &&
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr &&
make

When you wish to update ZMusic, copy and paste the following:

cd ~/zmusic_build/zmusic &&
git pull

and compile.

To install ZMusic:

cd ~/zmusic_build/zmusic/build &&
sudo make install

To uninstall ZMusic:

cd ~/zmusic_build/zmusic/build &&
while IFS= read -r file || [ -n "$file" ]; do
sudo rm -v -- "$file"
done < install_manifest.txt

Create gzdoom_build directory

mkdir -pv ~/gzdoom_build

Download and prepare the source

Download the GZDoom source and create an out of tree build directory:

cd ~/gzdoom_build &&
git clone https://github.com/ZDoom/gzdoom.git &&
mkdir -pv gzdoom/build

and run the following commands:

cd gzdoom
git config --local --add remote.origin.fetch +refs/tags/*:refs/tags/*
git pull

Download FMOD

For GZDoom 2.x or older versions.

Download FMOD and extract files to gzdoom directory:

cd ~/gzdoom_build &&
wget -nc http://zdoom.org/files/fmod/fmodapi44464linux.tar.gz &&
tar -xvzf fmodapi44464linux.tar.gz -C gzdoom

Starting with commit 3ddc3d8fe, now you can compile GZDoom with OpenAL sound support and optinally disable/enable FMOD sound support. If you want to disable FMOD sound support, run:

cd ~/gzdoom_build/gzdoom/build &&
cmake .. -DNO_FMOD=ON

and compile.

If afterwards you want to enable FMOD sound support, run:

cd ~/gzdoom_build/gzdoom/build &&
cmake .. -DNO_FMOD=OFF

Compiling

To compile GZDoom:

a='' && [ "$(uname -m)" = x86_64 ] && a=64
c="$(lscpu -p | grep -v '#' | sort -u -t , -k 2,4 | wc -l)" ; [ "$c" -eq 0 ] && c=1
cd ~/gzdoom_build/gzdoom/build &&
rm -f output_sdl/liboutput_sdl.so &&
if [ -d ../fmodapi44464linux ]; then
f="-DFMOD_LIBRARY=../fmodapi44464linux/api/lib/libfmodex${a}-4.44.64.so \
-DFMOD_INCLUDE_DIR=../fmodapi44464linux/api/inc"; else
f='-UFMOD_LIBRARY -UFMOD_INCLUDE_DIR'; fi &&
cmake .. -DCMAKE_BUILD_TYPE=Release $f &&
make -j$c

A development version of GZDoom will be compiled if you do not do #Latest stable version or #GZDoom 1.8.6.

Assuming all goes well, a gzdoom binary should be produced. To start GZDoom, the following command should work:

./gzdoom

If GZDoom complains you do not have any IWADs set up, make sure that you have your IWAD files placed in the same directory as GZDoom, in ~/.config/gzdoom/, $DOOMWADDIR, or /usr/local/share/. Alternatively, you can edit ~/.config/gzdoom/gzdoom.ini or ~/.config/gzdoom/zdoom.ini to set the path for your IWADs.

Latest stable version

Show the latest stable version:

cd ~/gzdoom_build/gzdoom &&
git tag -l | grep -v 9999 | grep -E '^g[0-9]+([.][0-9]+)*$' |
sed 's/^g//' | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 |
tail -n 1 | sed 's/^/g/'

If you want to compile the latest stable version, run:

cd ~/gzdoom_build/gzdoom &&
Tag="$(git tag -l | grep -v 9999 | grep -E '^g[0-9]+([.][0-9]+)*$' |
sed 's/^g//' | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 |
tail -n 1 | sed 's/^/g/')" &&
git checkout --detach refs/tags/$Tag

and compile.

After compiling, backing up and optionally installing the latest stable version, run:

cd ~/gzdoom_build/gzdoom &&
git checkout master

GZDoom 1.8.6

If your graphics card does not support OpenGL 2.0 or higher, you may want to compile GZDoom 1.8.6. The minimum requirement is OpenGL 1.3.

First, you need to install gcc 5.x or lower:

sudo apt-get install gcc-5 g++-5

Inside the build directory, run cmake with these arguments -DCMAKE_C_COMPILER=/path/to/compiler/gcc -DCMAKE_CXX_COMPILER=/path/to/compiler/g++, for example:

cd ~/gzdoom_build/gzdoom/build &&
cmake .. -DCMAKE_C_COMPILER=/usr/bin/gcc-5 \
-DCMAKE_CXX_COMPILER=/usr/bin/g++-5

Now checkout GZDoom 1.8.6:

cd ~/gzdoom_build/gzdoom &&
git checkout --detach refs/tags/g1.8.6

and compile. Please note that GZDoom 1.8.6 is old and unsupported. If you run into problems you are on your own.

Backup

If you want to backup GZDoom, do the following:

Create and name a directory with the corresponding GZDoom version/revision, build type and copy gzdoom, gzdoom.pk3, lights.pk3, brightmaps.pk3, game_support.pk3 and game_widescreen_gfx.pk3 to it. If you compiled GZDoom 2.x or older versions with FMOD sound support, copy liboutput_sdl.so to the destination directory.

cd ~/gzdoom_build/gzdoom/build &&
if [ -f CMakeCache.txt ]; then
k="$(sed -n 's/.*CMAKE_BUILD_TYPE:STRING=\(.*\)/\1/p' CMakeCache.txt)"; else k=''; fi &&
if [ -n "$k" ]; then b="-BuildType$k"; else b=''; fi &&
BACKUPGZDOOM="../../$(sed -n 's/.*#define GIT_DESCRIPTION "\(.*\)".*/\1/p' ../src/gitinfo.h)$b" &&
mkdir -pv "$BACKUPGZDOOM" &&
o=output_sdl/liboutput_sdl.so && if [ -f "$o" ]; then l="$o"; else l=''; fi &&
if [ game_support.pk3 -nt zd_extra.pk3 ]; then p=game_support.pk3; else p=zd_extra.pk3; fi &&
cp -v gzdoom gzdoom.pk3 lights.pk3 brightmaps.pk3 game_widescreen_gfx.pk3 $p $l \
"$BACKUPGZDOOM"/

Files are located at:

/home/<your username>/gzdoom_build/<your newly created directory>

Updating

When you wish to update GZDoom, copy and paste the following:

cd ~/gzdoom_build/gzdoom &&
git pull

When the update finish, go to #Compiling.

Installation

  • gzdoom = Stable version
  • gzdoom-alpha = Development version

Commands beginning with "sudo" will require temporary superuser privileges.

If you want to install GZDoom, do the following:

Create /usr/games/gzdoom and /usr/games/gzdoom-alpha directories:

sudo mkdir -pv /usr/games/gzdoom /usr/games/gzdoom-alpha

Copy gzdoom, gzdoom.pk3, lights.pk3, brightmaps.pk3, game_support.pk3, game_widescreen_gfx.pk3 and the soundfonts and fm_banks directories to /usr/games/gzdoom/ or /usr/games/gzdoom-alpha/. If you compiled GZDoom 2.x or older versions with FMOD sound support, copy liboutput_sdl.so and the FMOD library file to the destination directory.

a='' && [ "$(uname -m)" = x86_64 ] && a=64
cd ~/gzdoom_build/gzdoom/build &&
h="$(sed -n 's/.*#define GIT_HASH "\(.*\)".*/\1/p' ../src/gitinfo.h)" &&
if [ -z "$(git describe --exact-match --tags $h 2>/dev/null)" ]; then
d=-alpha; else d=''; fi &&
o=output_sdl/liboutput_sdl.so && if [ -f "$o" ]; then l="$o \
../fmodapi44464linux/api/lib/libfmodex${a}-4.44.64.so"; else l=''; fi &&
if [ game_support.pk3 -nt zd_extra.pk3 ]; then p=game_support.pk3; else p=zd_extra.pk3; fi &&
sudo cp -rv gzdoom gzdoom.pk3 lights.pk3 brightmaps.pk3 game_widescreen_gfx.pk3 $p soundfonts fm_banks $l \
/usr/games/gzdoom$d/

Create launch script:

cd ~/gzdoom_build/gzdoom/build &&
h="$(sed -n 's/.*#define GIT_HASH "\(.*\)".*/\1/p' ../src/gitinfo.h)" &&
if [ -z "$(git describe --exact-match --tags $h 2>/dev/null)" ]; then
d=-alpha; else d=''; fi &&
printf %s "\
#! /bin/sh
# The following command is for GZDoom 2.x or older versions
export LD_LIBRARY_PATH=/usr/games/gzdoom$d
exec /usr/games/gzdoom$d/gzdoom \"\$@\"
" > gzdoom$d.sh &&
chmod 755 gzdoom$d.sh &&
sudo mv -v gzdoom$d.sh /usr/bin/gzdoom$d

Now from a terminal you should be able to run gzdoom or gzdoom-alpha from any user account.

Uninstallation

Remove /usr/games/gzdoom directory and all its files:

sudo rm -rfv /usr/games/gzdoom

Remove gzdoom script:

sudo rm -fv /usr/bin/gzdoom

Remove /usr/games/gzdoom-alpha directory and all its files:

sudo rm -rfv /usr/games/gzdoom-alpha

Remove gzdoom-alpha script:

sudo rm -fv /usr/bin/gzdoom-alpha

Developing

This page has helped you compile GZDoom, but perhaps you are interested in debugging the code or submitting code changes or fixes for inclusion. This section is intended for more advanced users who may be unfamiliar to CMake or debugging on Linux systems.

Debugging

Prerequisite:

Maybe you have found a way to make GZDoom crash, and are interested in debugging it. First, you need to compile a debug build of GZDoom. Inside the build directory, invoke CMake to set up for compiling, but this time, the build type is set to Debug:

cd ~/gzdoom_build/gzdoom/build
cmake .. -DCMAKE_BUILD_TYPE=Debug

Optionally, you may want to use some of the #Build options.

After CMake is done, run make or to speed up compilation, run make -j<number>, a recommended value for the -j option is the number of physical cores:

make

To run GZDoom under a debugger such as gdb, use the following command:

gdb gzdoom

Now gdb should have you in its own command prompt:

(gdb)

You probably want to log the output, so lets output to a file gzdoomdebug.log:

(gdb) set logging on gzdoomdebug.log

Now start GZDoom by typing in run, and pressing enter:

(gdb) run

Or put any command line parameters to gzdoom after run:

(gdb) run <command line parameters>

If GZDoom crashes, gdb may be able to tell you the source file and line number it crashed in. Typing in the command backtrace or bt will produce information telling the last function calls, showing how execution got to the point where it crashed:

(gdb) backtrace

All output will be copied into the gzdoomdebug.log, which can then be scrutinized later, or perhaps posted to the Bugs forum for other developers to look at.

To exit gdb's command prompt, type quit, q or press Ctrl-D:

(gdb) quit

If you want to free up space, run make clean to remove the files generated by the compilation.

Build options

CMake options
Options Description Example
NO_GTK=ON Disable GTK+ dialogs. cmake .. -DNO_GTK=ON
NO_FMOD=ON Disable FMOD sound support. cmake .. -DNO_FMOD=ON
NO_OPENAL=ON Disable OpenAL sound support. cmake .. -DNO_OPENAL=ON
FMOD_LIBRARY Set path for FMOD library file. cmake .. -DFMOD_LIBRARY=/path/to/libfmodex(64)-x.y.z.so
FMOD_INCLUDE_DIR Set path for FMOD include directory. cmake .. -DFMOD_INCLUDE_DIR=/path/to/include/dir
CMAKE_C_COMPILER Set path for C compiler. cmake .. -DCMAKE_C_COMPILER=/path/to/compiler/gcc
CMAKE_CXX_COMPILER Set path for C++ compiler. cmake .. -DCMAKE_CXX_COMPILER=/path/to/compiler/g++
CMake build types
Types Description Example
Debug Debug information, -O1 optimization. cmake .. -DCMAKE_BUILD_TYPE=Debug
Release No debug information, -O3 optimization. cmake .. -DCMAKE_BUILD_TYPE=Release
RelWithDebInfo Debug information, -O2 optimization. Useful for finding optimization bugs that only show up in Release. cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
MinSizeRel Similar to Release but with less optimizations in order to save space. cmake .. -DCMAKE_BUILD_TYPE=MinSizeRel

How to increase Zandronum/GZDoom OpenGL FPS

Commands beginning with "sudo" will require temporary superuser privileges.

Run Zandronum/GZDoom, start a new game, open console and type vid_fps 1, see how many FPS are displayed and exit Zandronum/GZDoom.

If you do not use Intel graphics, go to #Disable Vertical Synchronization for Zandronum/GZDoom.

Enable SandyBridge's New Acceleration

Prerequisite:

Debian/Ubuntu

  • xserver-xorg-video-intel >= 2.19

Fedora

  • xorg-x11-drv-intel >= 2.19

openSUSE

  • xf86-video-intel >= 2.19

Mageia

  • x11-driver-video-intel >= 2.19

Arch Linux

  • xf86-video-intel >= 2.19

Gentoo

  • x11-drivers/xf86-video-intel >= 2.19

PCLinuxOS

  • x11-driver-video-intel >= 2.19

Solus

  • xorg-driver-video-intel >= 2.19

If your Intel driver version is 2.21.14-1 / 2.21.15-2 or higher:

grep 'SNA compiled:' /var/log/Xorg.0.log

go to #Disable Vertical Synchronization for Zandronum/GZDoom.

Intel SNA is useful on all Intel graphics, not just SandyBridge.

Create /etc/X11/xorg.conf.d directory:

sudo mkdir -pv /etc/X11/xorg.conf.d

Create 99-intel.conf file:

cat <<'EOF' > 99-intel.conf
Section "Device"
    Identifier "Intel Graphics"
    Driver "intel"
    Option "AccelMethod" "sna"
EndSection
EOF

Move 99-intel.conf to /etc/X11/xorg.conf.d/:

sudo mv -v 99-intel.conf /etc/X11/xorg.conf.d/

and logout and login.

Disable Vertical Synchronization for Zandronum/GZDoom

Do the following step if you are using a GZDoom version prior to commit 4eb32a50e. The following step works for the open-source graphics drivers.

Create ~/.drirc file:

cat <<'EOF' > ~/.drirc
<driconf>
    <device screen="0" driver="dri2">
        <application name="zandronum" executable="zandronum">
            <option name="vblank_mode" value="0"/>
        </application>
        <application name="gzdoom" executable="gzdoom">
            <option name="vblank_mode" value="0"/>
        </application>
    </device>
</driconf>
EOF

Run Zandronum/GZDoom, start a new game, open console and type vid_fps 1, see how many FPS are displayed, you should get more FPS than before.

Reverting changes

Remove ~/.drirc file:

rm -fv ~/.drirc

Remove 99-intel.conf file:

sudo rm -fv /etc/X11/xorg.conf.d/99-intel.conf

and logout and login.

External links