The Dark Mod - Compilation Guide

This guide should provide you with enough information to compile The Dark Mod's game code from source.
It applies to version 2.06 or later version of TDM. If you want to compile older version, see the history of this wiki page.
Brief compilation instructions are also included in COMPILING.txt file in the source code package.

The sources are available through "snapshots", i.e. whenever the Dark Mod team is releasing a new update (e.g. TDM 2.06) the corresponding sources are released as well.

Get the sources

Be warned though that (unless you're a team member and working on the SVN asset base) these sources might be incompatible with your local darkmod installation. The team cannot and will not support you in case you're running into troubles trying to get it to run.

Download the sources and unpack them next to your darkmod/ directory, such that the directory structure looks like this:

You'll find a TheDarkMod.sln solution file (in MSVC 2013 format) in the source code folder, which you can double-click to open in Visual Studio. The solution is designed to put the compiled binaries into the ../darkmod folder nearby, that's why we recommend using the directory layout shown above. (You can change the output paths in the property sheets, in case you know how to do that).

Once the solution is opened, select the Configuration in the topmost toolbar (either "release" or "debug", depending on what you want to do) and Platform (either Win32 or x64). Then hit "Build Solution" (Ctrl-Shift-B or F7). The compilation usually takes a minute or two, watch the output window at the bottom of Visual Studio. After completion you'll find the compiled binary in your darkmod/ folder. It would be either TheDarkMod.exe or TheDarkModx64.exe, depending on the target platform you chose.

The code uses DirectInput, which is automatically installed with VS2013 as a part of Windows SDK.
Normally, you don't have to do anything about it.
But if you have trouble with DirectInput, you can download the deprecated "Microsoft DirectX SDK" here.
In such case you will have to manually add paths to DirectX SDK to the property sheets.

Debugging the Engine/Game

To debug your custom built code, you need to attach Visual Studio's debugger to the TheDarkMod.exe process. There are two ways to accomplish that:

Go to menu "Debug" > "Attach to Process..." and select the TheDarkMod.exe process from the list in that dialog popping up.

The debugger will now attach to TDM and you can now place breakpoints or intercept game crashes.

Troubleshooting

My breakpoints don't work (they are hollow circles instead of full ones)

Make sure you're attached to the correct TheDarkMod.exe binary. If you're attaching to an older version (e.g. from an outdated compilation process) or one you haven't built in Studio yourself, VC++ won't be able to load the symbols from the .pdb files. Make sure that the configuration type (release or debug build) is matching as well.

I cannot inspect all the variables / The instruction pointer is skipping code

You are probably running a release build, which comes with some optimisations. When debugging a release build, you'll notice that your instruction pointer (the yellow arrow) is sometimes skipping statements, which have most likely been optimised out of the binary during compilation/linking. You'll also have troubles when trying to inspect temporary variables or inlined functions. Use a debug build if this prevents you from figuring out things during debugging.

Debugging works well, but the game plays too slowly

You are running debug build, which is much slower than release. There are several ways to make life easier. First, you can get to the place where problem happens in release build and save your game there, then run debug build and load the game to do debugging. Second, you can try the "Debug with inlines" configuration, which is faster than full debug build, but is still very convenient to debug. If this is not fast enough for you, you can also debug the release build directly, but be aware that breakpoints and watches do not always work due to optimizations. Note that even release build is slower with debugger than without it because of debug heap. You can disable it by setting environment variable _NO_DEBUG_HEAP=1. If you do it properly, then your release build should run with full speed.

Linux

You need GCC 5 or newer to build TDM on Linux.
Anything older than GCC 4.7 surely won't work.
Just as the original Doom 3, TDM is built using Scons build system.

Being in the source code root directory (darkmod_src/), you can build TDM with a command like this:

scons BUILD="release" TARGET_ARCH="x64" -j6 ..

If you omit some parameters, Scons will either use the previously defined values or the default ones.

Note: by default the deploy-ready executables are put into the current directory (which is source code root directory).
They are stripped of debug information, so you won't be able to debug them.
If you need debug information, make sure to specify ".." argument: then debuggable executables will be put into ../darkmod.

Ubuntu 16.04

The simplest approach is to do a native build, i.e. produce 64-bit binaries on 64-bit OS, or 32-bit binaries on 32-bit OS.
Starting from a clean Ubuntu installation, here is the list of packages you need to install:

The 64-bit and 32-bit versions can be built independently on a single 64-bit Linux.

Other distros

Even if you have Linux distro different from Ubuntu, the instructions above will most likely help you.
If you have still have problems with your build, please report to forums.

I have a bugfix for the team

In case you figured out a problem in the TDM game code and you maybe even have a fix available, please drop by at our forums to tell the coding staff. Your fix might be incorporated in the main development branch.

Working in SVN

If you work directly with SVN, make sure that svnversion command works properly in OS console:

To check that it works, build TDM yourself, run it, and then open TDM console. You should see the correct SVN revision number in the lower-right corner.

Dead text below

The remaining part of the article is most likely outdated and does not apply to version 2.06 (and later).
It would be probably better to simply delete it. Feel free to expand and do history digging if you like.

Linux

For Linux you'll need gcc and scons, plus a few packages depending on your distribution. There is a README.linux file contained in the source package you downloaded, check it out for some details.

For OS X you'll need gcc and scons, as with Linux. gcc should be included in your xcode installation, scons can be downloaded from the scons project website. The third-party libraries like boost, devil and libcurl are already included in the TDM source package, so it should compile out of the box. If you ever need to build one of them from scratch, see the subsections below.

The sconscripts are prepared for both Intel and PPC target architectures, the MACOSX_TARGET_ARCH argument will control which architecture you're compiling for.

Compiling for Intel architecture

To start compiling, enter the following command in the folder you extracted the TDM sources to:

scons BUILD="release" BUILD_GAMEPAK="1" MACOSX_TARGET_ARCH="i386"

Compiling for PPC architecture

To start compiling, enter the following command in the folder you extracted the TDM sources to:

scons BUILD="release" BUILD_GAMEPAK="1" MACOSX_TARGET_ARCH="ppc"

Compiling a universal binary

I've been using the following script to generate a universal binary. This script assumes that there are two separate TDM source folders, one in darkmod_src.i386 and one in darkmod_src.ppc.
Note: they are actual copies of the same TDM source package, I just used that as convenience such that I don't have to recompile the whole source tree after minor changes.

The filesize of the newly created libcurl.a should be around the sum of the single ppc and i386 libs, you can double-check that. Copy the libcurl.a into your darkmod_src/macosx/libcurl/ and you're done with this step.

Building Boost static libs in Mac OS X

Download the boost 1.45 sources and extract them to your hard drive. Create a jam user config file to use the g++ 4.0 compiler instead of the default gcc 4.2 in Leopard: create a new file in your boost root folder and name it user-config-darwin.jam:

The "stage" option only works in filesystem and system (not in thread, as of boost 1.45). You'll find the filesystem and system libs in the ./stage folder of your boost root, the libboost_thread.a will be located in the bin.v2 folder after compilation.