2024-07-14 23:16:30 +02:00
# Building VCMI for Linux
2023-09-01 14:25:21 +02:00
2023-09-07 11:57:03 +02:00
- Current baseline requirement for building is Ubuntu 20.04
- Supported C++ compilers for UNIX-like systems are GCC 9+ and Clang 13+
2023-09-01 14:25:21 +02:00
2023-09-07 11:57:03 +02:00
Older distributions and compilers might work, but they aren't tested by Github CI (Actions)
2023-09-01 14:25:21 +02:00
2024-07-14 23:16:30 +02:00
## Installing dependencies
2023-09-01 14:25:21 +02:00
2024-07-16 20:29:20 +02:00
### Prerequisites
2023-09-01 14:25:21 +02:00
To compile, the following packages (and their development counterparts) are needed to build:
2023-09-07 11:57:03 +02:00
- CMake
2023-09-01 14:25:21 +02:00
- SDL2 with devel packages: mixer, image, ttf
- zlib and zlib-devel
2023-09-07 11:57:03 +02:00
- Boost C++ libraries v1.48+: program-options, filesystem, system, thread, locale
2023-09-01 14:25:21 +02:00
- Recommended, if you want to build launcher or map editor: Qt 5, widget and network modules
- Recommended, FFmpeg libraries, if you want to watch in-game videos: libavformat and libswscale. Their name could be libavformat-devel and libswscale-devel, or ffmpeg-libs-devel or similar names.
2023-10-08 21:18:44 +02:00
- Optional:
- if you want to build scripting modules: LuaJIT
- to speed up recompilation: Ccache
2023-09-01 14:25:21 +02:00
2024-07-14 23:16:30 +02:00
### On Debian-based systems (e.g. Ubuntu)
2023-09-01 14:25:21 +02:00
2023-09-07 11:57:03 +02:00
For Ubuntu and Debian you need to install this list of packages:
2023-09-01 14:25:21 +02:00
2024-04-20 16:38:19 +02:00
`sudo apt-get install cmake g++ clang 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 libboost-iostreams-dev qtbase5-dev libtbb-dev libluajit-5.1-dev liblzma-dev libsqlite3-dev qttools5-dev ninja-build ccache`
2023-09-01 14:25:21 +02:00
Alternatively if you have VCMI installed from repository or PPA you can use:
2023-09-07 11:57:03 +02:00
`sudo apt-get build-dep vcmi`
2023-09-01 14:25:21 +02:00
2024-07-14 23:16:30 +02:00
### On RPM-based distributions (e.g. Fedora)
2023-09-01 14:25:21 +02:00
2024-04-20 16:38:19 +02:00
`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 boost-iostreams zlib-devel ffmpeg-devel ffmpeg-libs qt5-qtbase-devel tbb-devel luajit-devel liblzma-devel libsqlite3-devel fuzzylite-devel ccache`
2023-09-07 11:57:03 +02:00
NOTE: `fuzzylite-devel` package is no longer available in recent version of Fedora, for example Fedora 38. It's not a blocker because VCMI bundles fuzzylite lib in its source code.
2023-09-01 14:25:21 +02:00
2024-07-14 23:16:30 +02:00
### On Arch-based distributions
2023-09-01 14:25:21 +02:00
On Arch-based distributions, there is a development package available for VCMI on the AUR.
2024-07-14 23:16:30 +02:00
It can be found at https://aur.archlinux.org/packages/vcmi-git/
2023-09-01 14:25:21 +02:00
Information about building packages from the Arch User Repository (AUR) can be found at the Arch wiki.
2024-07-23 00:28:45 +02:00
### On NixOS or Nix
On NixOS or any system with nix available, [it is recommended ](https://nixos.wiki/wiki/C ) to use nix-shell. Create a shell.nix file with the following content:
```nix
with import < nixpkgs > {};
stdenv.mkDerivation {
name = "build";
nativeBuildInputs = [ cmake ];
buildInputs = [
cmake clang clang-tools llvm ccache ninja
boost zlib minizip xz
SDL2 SDL2_ttf SDL2_net SDL2_image SDL2_sound SDL2_mixer SDL2_gfx
ffmpeg tbb vulkan-headers libxkbcommon
qt6.full luajit
];
}
```
And put it into build directory. Then run `nix-shell` before running any build commands.
2024-07-16 20:29:20 +02:00
## Getting the sources
2023-09-01 14:25:21 +02:00
2024-02-05 21:09:18 +02:00
We recommend the following directory structure:
2023-09-01 14:25:21 +02:00
2024-07-14 23:16:30 +02:00
```
.
├── vcmi -> contains sources and is under git control
2024-07-15 11:27:23 +02:00
└── build -> contains build output, makefiles, object files,...
2024-07-14 23:16:30 +02:00
```
2024-02-05 21:09:18 +02:00
2024-07-14 23:16:30 +02:00
You can get the latest source code with:
2023-09-01 14:25:21 +02:00
`git clone -b develop --recursive https://github.com/vcmi/vcmi.git`
2024-07-16 20:29:20 +02:00
## Compilation
2023-09-01 14:25:21 +02:00
2024-07-16 20:29:20 +02:00
### Configuring Makefiles
2023-09-01 14:25:21 +02:00
2023-09-07 11:57:03 +02:00
```sh
2024-07-15 11:27:23 +02:00
mkdir build
cd build
2024-02-05 21:09:18 +02:00
cmake -S ../vcmi
2023-09-07 11:57:03 +02:00
```
2023-09-01 14:25:21 +02:00
2024-07-14 23:16:30 +02:00
> [!NOTE]
> The `../vcmi` is not a typo, it will place Makefiles into the build dir as the build dir is your working dir when calling CMake.
2023-09-01 14:25:21 +02:00
2024-07-15 11:27:23 +02:00
See [CMake ](CMake.md ) for a list of options
2023-09-01 14:25:21 +02:00
2024-07-16 20:29:20 +02:00
### Trigger build
2023-10-08 21:18:44 +02:00
2024-07-14 23:16:30 +02:00
```
cmake --build . -j8
```
2023-09-01 14:25:21 +02:00
2024-07-14 23:16:30 +02:00
(-j8 = compile with 8 threads, you can specify any value. )
2023-09-01 14:25:21 +02:00
2024-07-14 23:16:30 +02:00
This will generate `vcmiclient` , `vcmiserver` , `vcmilauncher` as well as .so libraries in the `build/bin/` directory.
2023-09-01 14:25:21 +02:00
2024-07-17 17:09:52 +02:00
## Packaging
2023-09-01 14:25:21 +02:00
2024-07-16 20:29:20 +02:00
### RPM package
2023-09-01 14:25:21 +02:00
2023-09-07 11:57:03 +02:00
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
0. Enable RPMFusion free repo to access to ffmpeg libs:
```sh
sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
```
2024-07-14 23:16:30 +02:00
> [!NOTE]
> The stock ffmpeg from Fedora repo is no good as it lacks a lots of codecs
2023-09-07 11:57:03 +02:00
1. Perform a git clone from a tagged branch for the right Fedora version from https://github.com/rpmfusion/vcmi; for example for Fedora 38: < pre > git clone -b f38 --single-branch https://github.com/rpmfusion/vcmi.git</ pre >
2. Copy all files to ~/rpmbuild/SPECS with command: < pre > cp vcmi/* ~/rpmbuild/SPECS</ pre >
2023-09-01 14:25:21 +02:00
2023-09-07 11:57:03 +02:00
3. Fetch all sources by using spectool:
```sh
sudo dnf install rpmdevtools
spectool -g -R ~/rpmbuild/SPECS/vcmi.spec
```
2023-09-01 14:25:21 +02:00
2023-09-07 11:57:03 +02:00
4. Fetch all dependencies required to build the RPM:
2023-09-01 14:25:21 +02:00
2023-09-07 11:57:03 +02:00
```sh
sudo dnf install dnf-plugins-core
sudo dnf builddep ~/rpmbuild/SPECS/vcmi.spec
```
2023-09-01 14:25:21 +02:00
4. Go to ~/rpmbuild/SPECS and open terminal in this folder and type:
2023-09-07 11:57:03 +02:00
```sh
rpmbuild -ba ~/rpmbuild/SPECS/vcmi.spec
```
2023-09-01 14:25:21 +02:00
5. Generated RPM is in folder ~/rpmbuild/RPMS
2023-09-07 11:57:03 +02:00
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:
2023-09-01 14:25:21 +02:00
2023-09-07 11:57:03 +02:00
```sh
mock -r fedora-38-aarch64-rpmfusion_free path_to_source_RPM
mock -r fedora-38-x86_64-rpmfusion_free path_to_source_RPM
```
For other distributions that uses RPM, chances are there might be a spec file for VCMI. If there isn't, you can adapt the RPMFusion's file
2023-09-01 14:25:21 +02:00
Available root environments and their names are listed in /etc/mock.
2024-07-16 20:29:20 +02:00
### Debian/Ubuntu
2023-09-01 14:25:21 +02:00
1. Install debhelper and devscripts packages
2. Run dpkg-buildpackage command from vcmi source directory
2023-09-07 11:57:03 +02:00
```sh
2023-09-01 14:25:21 +02:00
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