Compiling with CMake (OpenXcom)

From UFOpaedia
Revision as of 15:10, 14 May 2015 by Myk002 (talk | contribs)
Jump to navigation Jump to search

Before building

In addition to the OpenXcom dependencies, you will need CMake version 2.8.0 or later.

CMake can be used to build OpenXcom with differents tools. So far only the Makefile and Visual Studio have been tried. Other Generators (Xcode/Code blocks, ...) might work, but if you choose to use them, we currently have no way to make sure that they work. If broken, patches are welcome to make them work.

Note : Once a project has been generated, you don't need to regenerate it after updating the source. CMake will automatically check for modifications and regenerate the project for you.

Source dir/build dir: CMake allows you to separate the source directory (where the source resides) from the build directory (where the project is generated). This allows you to always have a clean source directory (no clutter left from builds). The source and build directories can be the same, but it's generally recommended to separate them. The standard name for the build directory is "build", which you must create yourself under the top level OpenXcom directory (where the README.md file is).


Generate a build project

Using CMake GUI tool

  • Launch the CMake configuration tools. First specify the path to the OpenXcom source tree.
  • Then specify where the OpenXcom project should be generated (e.g. the "build" directory that you created).
  • Click on configure. The first time, CMake will ask you which kind of build tool you wish to use.
  • Now CMake will analyze your system and once finished, you will be presented with a list of options. If all is fine for you, then click on generate.

Using CMake interactive command line tools

ccmake is a command line tool which allows you to configure the build interactively. You can launch it with:

 cd "openxcom build dir" &&
 ccmake -G 'Generator name' "path to openxcom source tree"

Generator name, is the name of the build system you wish to use. You can see possible values with:

 cmake help

If omitted, cmake will default to 'Unix Makefile'. Note that this needed only the first time you generate the project.

As with the GUI, tweak the options as needed and then configure the project before generating it.


Using CMake command line tools

 cd "openxcom build dir" &&
 cmake -G 'Generator name' -DOPTION_NAME=OPTION_VALUE "path to openxcom source tree"

You can check options value with:

 cmake -L

To change the value of an option:

 cmake -DOPTION_NAME=OPTION_VALUE "path to openxcom source tree"

Once the project is generated, you can use it as you would have done without using CMake.


End-to-end example

This will get you up and running from scratch to a fully functional installation. This example is written with Linux users in mind, but can be adapted easily for Windows or OSX. It assumes that you do not have OpenXcom installed in system directories (e.g. /usr/share/openxcom). If you do have a system-level OpenXcom installed, copy the /usr/share/openxcom/data directory to your OpenXcom source checkout directory (see below) and uninstall OpenXcom from your system. Otherwise, it will interact in unfriendly ways with the nightly build you are creating and running here.

Note that for the first line to work, you have to have set up your ssh key in github here: https://github.com/settings/ssh If you don't have a github account, and just want to compile the code, use "git clone https://github.com/SupSuper/OpenXcom.git openxcom" instead of the "git clone git@" command below.

git clone git@github.com:SupSuper/OpenXcom.git openxcom
{copy XCOM1 assets into openxcom/bin/data}
mkdir openxcom/build
cd openxcom/build
cmake ..
ccmake ..
{set CMAKE_BUILD_TYPE to Release (or Debug if you want useful stack traces, but that will slow the game /way/ down)}
{set CMAKE_INSTALL_PREFIX to /home/yourusername/bin/OpenXcom (or whatever)}
{configure, generate, and exit}
make -j3
make install

Then create an executable shell script in your $HOME/bin directory (ensure it is in your PATH) named openxcom with the contents:

#!/bin/sh
"$HOME/bin/OpenXcom/bin/openxcom" -data "$HOME/bin/OpenXcom/share/openxcom/data"

now just run

openxcom

to play : )