Skip to content

Compilation guide

Alex Lo edited this page Feb 17, 2016 · 54 revisions

Before we begin

You will need the following applications installed on your system:

  • CMake
  • Git
  • C and C++ compiler of your choice

Quick guide

If you are unfamiliar with CMake or Git, then skip this section.

  1. Get the source code.
  2. Get the dependencies (the libraries needed are listed under the Getting the dependencies section below)
  3. Run CMake to build the project files. Use the CMake GUI or curses GUI to get a list of all the options.
  4. Open the project files (if necessary), and compile!

Getting the source code

The source code for OpenJK, which includes Jedi Outcast and Jedi Academy, can be downloaded from the git repository:

$ git clone https://github.com/JACoders/OpenJK.git openjk

Alternatively, you can fork our project if you would like to contribute back! Either way, you must adhere to the GNU GPLv2 license, under which the original Jedi Outcast/Jedi Academy source was licensed. This means any changes to the code must be publicly available.

Getting the dependencies

The following libraries are required to build OpenJK:

  • libjpeg
  • libpng
  • zlib
  • OpenGL
  • OpenAL (Windows only)
  • SDL2

Windows

For Windows builds, all the dependencies are provided with the source code.

Linux

On Debian-based distros, the following command will download and install the required dependencies:

$ sudo apt-get install libjpeg8-dev libpng12-dev zlib1g-dev libsdl2-dev make build-essential

There will be equivalent commands on other Linux distros.

For example on openSUSE you will need:

$ sudo zypper in libjpeg8-devel libpng16-devel zlib-devel libSDL2-devel

CentOS 7 for dedicated server and MP libraries

Install the dependencies:

$ sudo yum install libjpeg-devel libpng-devel zlib-devel

Run cmake with -i to select the desired parts of OpenJK to build.

Or when cross-compiling for 32 bit:

$ sudo yum install glibc-devel.i686 libstdc++-devel.i686 libjpeg-turbo-devel.i686 libpng-devel.i686 zlib-devel.i686

Run cmake with -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32

OS X

We recommend using a package manager similar MacPorts or Homebrew to download and install the dependencies. Using Homebrew, you can use the following command:

$ brew install zlib libjpeg libpng sdl2 --universal

zlib is installed as part of libpng.

Generating project files

We use CMake as our cross-platform makefile generator. This allows us to maintain a single set of project files, and have CMake generate the Visual Studio solution, Makefile, or Xcode project files for us. CMake can be downloaded from the CMake website, or through your package manager. Instructions for installing CMake can be found here.

There are three ways to run CMake:

CMake GUI (Windows, Linux and OS X)

This method is recommended for people using Windows, or are new to CMake.

  1. Open CMake GUI
  2. In the "Where is the source code" text box, enter the path to the OpenJK source code.
  3. Copy and paste the patch into the "Where to build the binaries" text box, and add /build at the end of the path.
  4. Click the Configure button at the bottom-left of the window.
  5. Follow the on-screen instructions. If you don't know which compiler to use, then leave it as default.
  6. The window should now be filled with some settings. Edit the settings to suit your needs. We highly recommend setting CMAKE_INSTALL_PREFIX to JKA's GameData folder to make running and testing easier later on. Hovering over each setting will give a description of what it does.
  7. Press the Generate button to generate the project files.
  8. The project files will be generated in the build/ folder located in your OpenJK source folder.

CMake Curses (Linux and OS X)

This method is recommended for people new to CMake and are comfortable using the terminal. On Linux, the curses GUI for CMake might need to be installed separately. For Debian-based distros, the package can be downloaded by running:

sudo apt-get install cmake-curses-gui

To create the project files:

  1. cd to the OpenJK source folder and run mkdir build.
  2. cd build
  3. ccmake .. (note the double c in ccmake)
  4. You can optionally provide the -G <generator name> option to specify what type of project file to generate. For example: ccmake -G Ninja .. will create project files for the Ninja build system. A list of generators can be found by running cmake (single c).
  5. Configure the project (press the C key), and then edit the settings to suit your needs. We highly recommend setting CMAKE_INSTALL_PREFIX to JKA's GameData folder to make running and testing easier later on.
  6. Generate the project (press the G key).
  7. Your project files will be created in the build/ directory.
  8. Exit the GUI by pressing the E key.

If you need to change any settings, run make edit_cache, and the curses GUI will be shown again. Edit the settings, and generate the project again.

Using cmake directly

This method is recommended for build scripts such as those used in automated builds or for experienced users who are comfortable with using the terminal, and know the flags to pass to CMake. The following commands will create the build directory, and generate the project files for the default generator. You should edit it for your specific needs.

cd $HOME/openjk
mkdir build
cd !$
cmake ..

It is recommended to set the install prefix: `cmake -DCMAKE_INSTALL_PREFIX=/path/to/GameData ..

Compiling

Compiling the source code depends on the project/makefile generated. Instructions for the main build tool on each supported platform are supplied below.

Windows

  1. Open the OpenJK.sln file in the build folder.
  2. Select the build configuration to use (Debug/Release/RelWithDebInfo/MinSizeRel).
  3. Build the solution.
  4. Built files can be found in build/<project name>/<build configuration>/.

OpenJK makes use of some standard C/C++ headers which aren't available by default in older versions of Visual Studio. Please make sure you're running the latest version of Visual Studio!

Linux/OS X

Simply run make from the build folder. On multicore CPUs, you can improve the speed of compilation by passing the -j option: make -jN, Where N is the number of cores in your CPU.

This will build all the projects. Individual projects can be built by passing the project names as arguments to make:

$ make openjk_sp.i386

A list of projects can be found by running make help.

If you have set CMAKE_INSTALL_PREFIX correctly, running make install will copy all the built files into their correct places in your GameData folder, ready to run and test.

Linux and multiarch builds

If you are attempting to build 32-bit binaries under 64-bit Linux, chances are you will be able to make use of multiarch support in most modern Linux distros. If you are having problems, then we suggest creating a 32-bit chroot and building inside of the chroot. This is what we do for our automated builds!

Clone this wiki locally