Difference between revisions of "How to build VCMI (Linux)"

From VCMI Project Wiki
Jump to: navigation, search
(Configure debug/run applications)
(Manual Installation)
(35 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
= Compiling VCMI =
 
= Compiling VCMI =
There is a guide for compiling and running VCMI located in the SVN trunk root directory: [https://vcmi.svn.sourceforge.net/svnroot/vcmi/trunk/README.linux README.linux]
+
* Current baseline requirement for building is Ubuntu 14.04
 +
* Supported C++ compilers for UNIX-like systems are GCC 4.8+ and Clang 3.4+
  
= Setting up a development environment using Eclipse CDT =
+
Older distributions and compilers might work, but they aren't tested by [https://travis-ci.org/vcmi/vcmi/ Travis CI]
In order to do that you should followed the guide above first.
 
  
== Installing Eclipse ==
+
= Installing dependencies =
If you have installed Eclipse already, then you can skip this section.
 
  
<ol>
+
== Prerequisites ==
<li>Eclipse offers a wide range of supported programming languages. The classic package only supports Java. It can be extended to support languages like C++, PHP, JavaScript, ActionScript,... via the "Install new software..."-dialog within Eclipse. Therefore you have one programming environment this means one program which provides many languages. That's the way described here. As a starting point download Eclipse Classic first. It can be obtained from here [http://www.eclipse.org/downloads/ Eclipse downloads].</li>
 
<li>Unpack the downloaded package.
 
<pre>tar xzf eclipse.tar.gz</pre></li>
 
<li>Move it to the /opt directory which is used for additional mostly not-UNIX-like programs in matters of the directory structure.
 
<pre>sudo mv eclipse /opt</pre></li>
 
<li>Adjust file access rights.
 
<pre>cd /opt
 
sudo chown -R root:root eclipse
 
sudo chmod -R +r eclipse
 
sudo chmod +x `sudo find eclipse -type d`</pre></li>
 
<li>Make eclipse more accessible.<pre>sudo touch /usr/bin/eclipse
 
sudo chmod 755 /usr/bin/eclipse
 
sudoedit /usr/bin/eclipse</pre>Enter these few lines in the editor, save the file and close the editor.<pre>#!/bin/sh
 
export ECLIPSE_HOME="/opt/eclipse"
 
$ECLIPSE_HOME/eclipse $* </pre></li>
 
<li>If you're using GNOME as the window manager then you may do the following steps. It's default on Fedora. That way you can start eclipse via the actvities window or the programs tab.<pre>sudoedit /usr/share/applications/eclipse.desktop</pre>
 
Enter the following lines in the editor:
 
<pre>[Desktop Entry]
 
Encoding=UTF-8
 
Name=Eclipse
 
Comment=Eclipse IDE
 
Exec=eclipse
 
Icon=/opt/eclipse/icon.xpm
 
Terminal=false
 
Type=Application
 
Categories=GNOME;Application;Development;
 
StartupNotify=true </pre></li>
 
<li>Clean eclipse.<pre>/opt/eclipse/eclipse -clean</pre></li>
 
<li>Start eclipse. Adjust workspace directory to sth. like: ~/Eclipse</li>
 
<li>Go to: Help -> Install new software...</li>
 
<li>Click on Add... and enter the Location <i>http://download.eclipse.org/releases/indigo</i> and Name <i>Indigo</i>. Make sure that you adjust the Location and Name to the used eclipse version.</li>
 
<li>Type in <i>Work with</i> the name of the recently added repository. Then select the package Programming Languages -> C/C++ Development Tools and install it. This will install Eclipse CDT.</li>
 
</ol>
 
  
== Setup a VCMI project ==
+
To compile, the following packages (and their development counterparts) are needed to build:
 +
* CMake 2.8.12 or newer
 +
* SDL2 with devel packages: mixer, image, ttf
 +
* zlib and zlib-devel
 +
* Optional of launcher: Qt 5, widget and network modules
 +
* FFmpeg libraries: libavformat and libswscale. Their name could be libavformat-devel and libswscale-devel, or ffmpeg-libs-devel or similar names.
 +
* Boost C++ libraries v1.48+: program-options, filesystem, system, thread, locale
  
=== Create project ===
+
== Manual Installation ==
# File -> New Project... -> C/C++ -> C++ Project -> Next
 
# Type in a project name e.g. vcmi_animRewrite for the branch animRewrite, vcmi_trunk for the trunk, vcmi_0_88 for the tag 0.88
 
# Choose Makefile project -> Empty project -> Toolchain -> Linux GCC -> Finish
 
# Right click on project -> Properties. This will open the project properties where you can configure the sources folder, include paths,...
 
  
Add the bolded include paths as you can see them in the picture.
+
For older OS versions the latest prerequisite packages may not be readily available via the system installer. Some brief instructions for manual install are given below (tested on Ubuntu 14.04, update version numbers as desired).
  
[[File:Eclipse_Include_Path.jpg|350px]]
+
* CMake (see also https://askubuntu.com/questions/355565/how-do-i-install-the-latest-version-of-cmake-from-the-command-line/865294)
 +
<pre>
 +
wget https://cmake.org/files/v3.11/cmake-3.11.0.tar.gz
 +
tar xfz cmake-3.11.0.tar.gz
 +
cd cmake-3.11.0
 +
./bootstrap
 +
make -j2
 +
sudo checkinstall --pkgname cmake --pkgversion 3.11.0 -y
 +
</pre>
 +
Note: Will only be visible in new terminals. Test with cmake --version.
  
You have to click on Link Folder... and then Link to folder in the filesystem. Select the /src folder and the /build folder of one SVN project. If you link the /build folder then you can execute make targets.
+
* Boost (see also https://ubuntuforums.org/showthread.php?t=1180792)
 +
<pre>
 +
wget https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
 +
tar xfz boost_1_66_0.tar.gz
 +
cd boost_1_66_0
 +
./boostrap.sh --with-library=program-options,filesystem,system,thread,locale
 +
./b2
 +
sudo ./b2 install
 +
</pre>
 +
Note: Boost 1.66.0 produces a bug in asio.hpp when used with old gcc versions (see https://svn.boost.org/trac10/ticket/13368).
  
[[File:Eclipse_SourcePaths.jpg|350px]]
+
* GCC (for Ubuntu - compile from source is lengthy)
 +
<pre>
 +
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
 +
sudo apt-get update
 +
sudo apt-get install gcc-7 g++-7
 +
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7
 +
</pre>
 +
Note: Test with gcc --version (and g++ --version).
  
Add the bolded symbols as you can see them in the picture. This one is missing add this as well: __GXX_EXPERIMENTAL_CXX0X__
+
* Clang (for Ubuntu 14.04 - for later versions first line is not needed, and 'trusty' should be replaced with version name)
That symbols are for the Eclipse CDT parser only.  
+
<pre>
 +
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
 +
sudo add-apt-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main"
 +
sudo apt-get update
 +
sudo apt-get install clang-6.0
 +
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-6.0 60 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-6.0
 +
</pre>
 +
Note: Test with clang --version (and clang++ --version).
  
[[File:Eclipse_Symbols.jpg|350px]]
+
== On Debian-based systems (e.g. Ubuntu) ==
  
You'll recognize that there are some errors in some source files. That's because the Eclipse parser can't understand every C++ language feature especially c++11. This doesn't mean that they are real errors. BOOST_FOREACH errors are fixed with the appropriate macro stated above in the picture. The parser has problems with std::make_pair perhaps this will be fixed in a later release of CDT as this error message appears often. We recommend to leave error, warning reporting turned on as you can directly see what is likely to be a problem for the GCC compiler.
+
<pre>
 +
sudo apt-get install cmake g++ libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev zlib1g-dev libavformat-dev libswscale-dev libboost-dev libboost-filesystem-dev libboost-system-dev libboost-thread-dev libboost-program-options-dev libboost-locale-dev qtbase5-dev
 +
</pre>
  
=== Configure external program configure ===
+
Alternatively if you have VCMI installed from repository or PPA you can use:
 +
<pre>
 +
sudo apt-get build-dep vcmi
 +
</pre>
  
# Go to Run -> External Tools -> External Tools Configuration...
+
== On RPM-based distributions (e.g. Fedora) ==
# Add new launch configuration(Program) -> Choose the configure script as the location via the Browser Workspace Button
 
# Working directory is the /build folder
 
# Arguments may the following : <code class="inline">--datadir=/usr/local/share/games --bindir=/usr/local/games --libdir=/usr/local/lib64/games.</code> The /vcmi folder at the end of datadir and libdir is not missing. It will be added automatically by the configure script.
 
# Save configuration with Apply and Close.
 
  
That way you don't need to run the ./configure script via the terminal. It can be executed within eclipse.
+
<pre>
 +
sudo yum install cmake gcc-c++ SDL2-devel SDL2_image-devel SDL2_ttf-devel SDL2_mixer-devel boost boost-devel boost-filesystem boost-system boost-thread boost-program-options boost-locale zlib-devel ffmpeg-devel ffmpeg-libs qt5-qtbase-devel
 +
</pre>
  
=== Configure debug/run applications ===
+
== On Arch-based distributions ==
 +
On Arch-based distributions, there is a development package available for VCMI on the AUR.
  
Go to Run -> Debug/Run configurations...
+
It can be found at: https://aur.archlinux.org/packages/vcmi-git/
-> Add new launch configuration(C++ application)
 
-> Choose vcmiclient via Search project...
 
-> Make sure that Use Workspace Settings is enabled
 
-> VCMI won't start/debug if you don't set a specific environment variable due to shared libraries loading. Go to tab Environment -> New... Name = LD_LIBRARY_PATH Value = e.g. /usr/local/lib64/games/vcmi(where your shared libraries are located)
 
  
Then go to Project -> Properties -> C/C++ Build -> Builder settings -> Change build location to sth. like project/build(where your makefiles are located)
+
Information about building packages from the Arch User Repository (AUR) can be found at the Arch wiki.
 +
 
 +
= Getting the sources =
 +
 
 +
VCMI is still in development. We recommend the following initial directory structure:
 +
<pre>
 +
.
 +
├── vcmi -> contains sources and is under git control
 +
└── build -> contains build output, makefiles, object files,...
 +
</pre>
 +
 
 +
You can get latest sources with:
 +
<pre>
 +
git clone -b develop --depth 1 --recursive https://github.com/vcmi/vcmi.git
 +
</pre>
 +
 
 +
= Compilation =
 +
 
 +
== Configuring Makefiles ==
 +
<pre>
 +
mkdir build && cd build
 +
cmake ../vcmi
 +
 
 +
# Additional options that you may want to use:
 +
## To enable debugging:
 +
cmake ../vcmi -DCMAKE_BUILD_TYPE=Debug
 +
</pre>
 +
'''Notice''':
 +
The ../vcmi/ is not a typo, it will place makefile scripts into the build dir as the build dir is your working dir when calling CMake.
 +
 
 +
== Trigger build ==
 +
<pre>
 +
cmake --build . -- -j2
 +
# -j2 = compile with 2 threads, you can specify any value
 +
</pre>
 +
That will generate vcmiclient, vcmiserver, vcmilauncher as well as 4 .so libraries in '''build/bin/''' directory.
 +
 
 +
= Package building =
 +
 
 +
== RPM package ==
 +
 
 +
The first step is to prepare a RPM build environment. On Fedora systems you can follow this guide: http://fedoraproject.org/wiki/How_to_create_an_RPM_package#SPEC_file_overview
 +
 
 +
1. Download the file rpm/vcmi.spec from any tagged VCMI release for which you wish to build a RPM package via the SVN Browser trac at this URL for example(which is for VCMI 0.9): http://sourceforge.net/apps/trac/vcmi/browser/tags/0.9/rpm/vcmi.spec
 +
 
 +
2. Copy the file to ~/rpmbuild/SPECS
 +
 
 +
3. Follow instructions in the vcmi.spec. You have to export the corresponding SVN tag, compress it to a g-zipped archive and copy it to ~/rpmbuild/SOURCES. Instructions are written as comments and you can copy/paste commands into terminal.
 +
 
 +
4. Go to ~/rpmbuild/SPECS and open terminal in this folder and type: <pre>rpmbuild -ba vcmi.spec (this will build rpm and source rpm)</pre>
 +
 
 +
5. Generated RPM is in folder ~/rpmbuild/RPMS
 +
 
 +
If you want to package the generated RPM above for different processor architectures and operating systems you can use the tool mock. Moreover, it is necessary to install mock-rpmfusion_free due to the packages ffmpeg-devel and ffmpeg-libs which aren't available in the standard RPM repositories(at least for Fedora). Go to ~/rpmbuild/SRPMS in terminal and type:
 +
<pre>mock -r fedora-17-i386-rpmfusion_free path_to_source_RPM
 +
mock -r fedora-17-x86_64-rpmfusion_free path_to_source_RPM</pre>
 +
 
 +
Available root environments and their names are listed in /etc/mock.
 +
== Debian/Ubuntu ==
 +
1. Install debhelper and devscripts packages
 +
 
 +
2. Run dpkg-buildpackage command from vcmi source directory
 +
<pre>
 +
sudo apt-get install debhelper devscripts
 +
cd /path/to/source
 +
dpkg-buildpackage
 +
</pre>
 +
To generate packages for different architectures see "-a" flag of dpkg-buildpackage command
 +
 
 +
== Documentation ==
 +
 
 +
To compile using Doxygen, the UseDoxygen CMake module must be installed. It can be fetched from: http://tobias.rautenkranz.ch/cmake/doxygen/
 +
 
 +
Once UseDoxygen is installed, run:
 +
<pre>
 +
cmake .
 +
make doc
 +
</pre>
 +
 
 +
The built documentation will be available from ./doc

Revision as of 04:51, 7 April 2018

Compiling VCMI

  • Current baseline requirement for building is Ubuntu 14.04
  • Supported C++ compilers for UNIX-like systems are GCC 4.8+ and Clang 3.4+

Older distributions and compilers might work, but they aren't tested by Travis CI

Installing dependencies

Prerequisites

To compile, the following packages (and their development counterparts) are needed to build:

  • CMake 2.8.12 or newer
  • SDL2 with devel packages: mixer, image, ttf
  • zlib and zlib-devel
  • Optional of launcher: Qt 5, widget and network modules
  • FFmpeg libraries: libavformat and libswscale. Their name could be libavformat-devel and libswscale-devel, or ffmpeg-libs-devel or similar names.
  • Boost C++ libraries v1.48+: program-options, filesystem, system, thread, locale

Manual Installation

For older OS versions the latest prerequisite packages may not be readily available via the system installer. Some brief instructions for manual install are given below (tested on Ubuntu 14.04, update version numbers as desired).

wget https://cmake.org/files/v3.11/cmake-3.11.0.tar.gz
tar xfz cmake-3.11.0.tar.gz
cd cmake-3.11.0
./bootstrap
make -j2
sudo checkinstall --pkgname cmake --pkgversion 3.11.0 -y

Note: Will only be visible in new terminals. Test with cmake --version.

wget https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
tar xfz boost_1_66_0.tar.gz
cd boost_1_66_0
./boostrap.sh --with-library=program-options,filesystem,system,thread,locale
./b2
sudo ./b2 install

Note: Boost 1.66.0 produces a bug in asio.hpp when used with old gcc versions (see https://svn.boost.org/trac10/ticket/13368).

  • GCC (for Ubuntu - compile from source is lengthy)
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-7 g++-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7

Note: Test with gcc --version (and g++ --version).

  • Clang (for Ubuntu 14.04 - for later versions first line is not needed, and 'trusty' should be replaced with version name)
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo add-apt-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main"
sudo apt-get update
sudo apt-get install clang-6.0
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-6.0 60 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-6.0

Note: Test with clang --version (and clang++ --version).

On Debian-based systems (e.g. Ubuntu)

sudo apt-get install cmake g++ libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-mixer-dev zlib1g-dev libavformat-dev libswscale-dev libboost-dev libboost-filesystem-dev libboost-system-dev libboost-thread-dev libboost-program-options-dev libboost-locale-dev qtbase5-dev

Alternatively if you have VCMI installed from repository or PPA you can use:

sudo apt-get build-dep vcmi

On RPM-based distributions (e.g. Fedora)

sudo yum install cmake gcc-c++ SDL2-devel SDL2_image-devel SDL2_ttf-devel SDL2_mixer-devel boost boost-devel boost-filesystem boost-system boost-thread boost-program-options boost-locale zlib-devel ffmpeg-devel ffmpeg-libs qt5-qtbase-devel

On Arch-based distributions

On Arch-based distributions, there is a development package available for VCMI on the AUR.

It can be found at: https://aur.archlinux.org/packages/vcmi-git/

Information about building packages from the Arch User Repository (AUR) can be found at the Arch wiki.

Getting the sources

VCMI is still in development. We recommend the following initial directory structure:

.
├── vcmi -> contains sources and is under git control
└── build -> contains build output, makefiles, object files,...

You can get latest sources with:

git clone -b develop --depth 1 --recursive https://github.com/vcmi/vcmi.git

Compilation

Configuring Makefiles

mkdir build && cd build
cmake ../vcmi

# Additional options that you may want to use:
## To enable debugging:
cmake ../vcmi -DCMAKE_BUILD_TYPE=Debug

Notice: The ../vcmi/ is not a typo, it will place makefile scripts into the build dir as the build dir is your working dir when calling CMake.

Trigger build

cmake --build . -- -j2
# -j2 = compile with 2 threads, you can specify any value

That will generate vcmiclient, vcmiserver, vcmilauncher as well as 4 .so libraries in build/bin/ directory.

Package building

RPM package

The first step is to prepare a RPM build environment. On Fedora systems you can follow this guide: http://fedoraproject.org/wiki/How_to_create_an_RPM_package#SPEC_file_overview

1. Download the file rpm/vcmi.spec from any tagged VCMI release for which you wish to build a RPM package via the SVN Browser trac at this URL for example(which is for VCMI 0.9): http://sourceforge.net/apps/trac/vcmi/browser/tags/0.9/rpm/vcmi.spec

2. Copy the file to ~/rpmbuild/SPECS

3. Follow instructions in the vcmi.spec. You have to export the corresponding SVN tag, compress it to a g-zipped archive and copy it to ~/rpmbuild/SOURCES. Instructions are written as comments and you can copy/paste commands into terminal.

4. Go to ~/rpmbuild/SPECS and open terminal in this folder and type:
rpmbuild -ba vcmi.spec (this will build rpm and source rpm)

5. Generated RPM is in folder ~/rpmbuild/RPMS

If you want to package the generated RPM above for different processor architectures and operating systems you can use the tool mock. Moreover, it is necessary to install mock-rpmfusion_free due to the packages ffmpeg-devel and ffmpeg-libs which aren't available in the standard RPM repositories(at least for Fedora). Go to ~/rpmbuild/SRPMS in terminal and type:

mock -r fedora-17-i386-rpmfusion_free path_to_source_RPM
mock -r fedora-17-x86_64-rpmfusion_free path_to_source_RPM

Available root environments and their names are listed in /etc/mock.

Debian/Ubuntu

1. Install debhelper and devscripts packages

2. Run dpkg-buildpackage command from vcmi source directory

sudo apt-get install debhelper devscripts
cd /path/to/source
dpkg-buildpackage

To generate packages for different architectures see "-a" flag of dpkg-buildpackage command

Documentation

To compile using Doxygen, the UseDoxygen CMake module must be installed. It can be fetched from: http://tobias.rautenkranz.ch/cmake/doxygen/

Once UseDoxygen is installed, run:

cmake .
make doc

The built documentation will be available from ./doc