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

From VCMI Project Wiki
Jump to: navigation, search
(Compiling VCMI for Windows on Linux or Mac)
 
 
Line 1: Line 1:
= Compiling VCMI for Windows on Linux or Mac =
+
= Requirements =
Some developers may want to make Windows builds without dealing with dependencies as it may be headache when you're on Windows. It's possible to setup own cross-compiler toolkit that use MinGW, but that take time and skill. Fortunately we can use Conan Package Manager that make cross compilation easy and work out of box for our engine.
+
# MinGW environment: <code>apt install mingw-w64</code>
 +
# CMake: <code>apt install cmake</code> or get from https://cmake.org/download/
 +
# (optional) Ninja: <code>apt install ninja-build</code> or get from https://github.com/ninja-build/ninja/releases
 +
# (optional) NSIS: <code>apt install nsis</code>
 +
# Unfortunately, on Ubuntu 22.04 or less we need to fetch MinGW headers from 22.10
 +
 
 +
<code>curl -O -L http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-common_10.0.0-2_all.deb && sudo dpkg -i mingw-w64-common_10.0.0-2_all.deb;</code>
 +
 
 +
<code>curl -O -L http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-x86-64-dev_10.0.0-2_all.deb && sudo dpkg -i mingw-w64-x86-64-dev_10.0.0-2_all.deb;</code> (for x86_64)
 +
 
 +
<code>curl -O -L http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-i686-dev_10.0.0-2_all.deb  && sudo dpkg -i mingw-w64-i686-dev_10.0.0-2_all.deb;</code> (for i686)
 +
 
 +
= Compiling VCMI for Windows on Linux =
 +
Some developers may want to make Windows builds without dealing with dependencies as it may be headache when you're on Windows. It's possible to setup own cross-compiler toolkit that use MinGW, but that take time and skill. Fortunately we can use Conan Package Manager that make cross compilation easy and work out of box for our engine. Conan for cross-compiling VCMI is supported only from VCMI 1.2+
 +
 
 +
 
 +
= Precompiled build from CI =
 +
In order to speed up Conan cross compilation time on CI we use precompiled Conan dependencies packages for Ubuntu 22.04 x86_64. Assuming that you already install requirements, this should be easy.
 +
 
 +
<code>curl -L "https://github.com/vcmi/vcmi-deps-windows-conan/releases/download/1.0/vcmi-deps-windows-conan-w64.tgz" | tar -C ~/.conan -xzf -</code>
 +
 
 +
== Conan package manager ==
 +
Please find detailed instructions in [https://github.com/vcmi/vcmi/tree/develop/docs/conan.md VCMI repository]. Note that the link points to the cutting-edge state in <code>develop</code> branch, for the latest release check the same document in the [https://github.com/vcmi/vcmi/tree/master/docs/conan.md master branch].
 +
 
 +
On the step where you need to replace '''PROFILE''', choose:
 +
* if you're want 64-bit: <code>mingw64-linux.jinja</code>
 +
* if you're want 32-bit: <code>mingw32-linux.jinja</code>
 +
 
 +
Note: if you wish to build 1.2 release in non-<code>Release</code> configuration, you should define <code>USE_CONAN_WITH_ALL_CONFIGS=1</code> environment variable when executing <code>conan install</code>.
 +
 
 +
== Building ==
 +
If you are on CMake 3.20+, simply use <code>cmake --preset windows-mingw-conan-linux</code> for configure and <code>cmake --build --preset windows-mingw-conan-linux --target package</code> for automatic generator of install script.
 +
If you have CMake version incapable of doing presets, you need to use this command <code>cmake <path> -DCMAKE_TOOLCHAIN_FILE=/home/rilian/Projects/vcmi/conan-generated/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW <additional cmake options></code> and then use <code>make package</code> or <code>ninja package</code> (if -G Ninja) in your generated path.
 +
 
 +
== Testing build ==
 +
After compile, you can run generated binaries by using Wine from here (assuming, you used CMake preset):
 +
<pre>
 +
out/build/windows-mingw-conan-linux/bin/vcmilauncher
 +
out/build/windows-mingw-conan-linux/bin/vcmiclient
 +
out/build/windows-mingw-conan-linux/bin/vcmiserver
 +
</pre>
 +
You need to copy H3 data as with usual VCMI installation.
 +
 
 +
= Troubleshooting =
 +
In case of troubles you can always consult our CI build scripts or contact the dev team via slack

Latest revision as of 20:45, 29 January 2023

Requirements

  1. MinGW environment: apt install mingw-w64
  2. CMake: apt install cmake or get from https://cmake.org/download/
  3. (optional) Ninja: apt install ninja-build or get from https://github.com/ninja-build/ninja/releases
  4. (optional) NSIS: apt install nsis
  5. Unfortunately, on Ubuntu 22.04 or less we need to fetch MinGW headers from 22.10

curl -O -L http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-common_10.0.0-2_all.deb && sudo dpkg -i mingw-w64-common_10.0.0-2_all.deb;

curl -O -L http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-x86-64-dev_10.0.0-2_all.deb && sudo dpkg -i mingw-w64-x86-64-dev_10.0.0-2_all.deb; (for x86_64)

curl -O -L http://mirrors.kernel.org/ubuntu/pool/universe/m/mingw-w64/mingw-w64-i686-dev_10.0.0-2_all.deb && sudo dpkg -i mingw-w64-i686-dev_10.0.0-2_all.deb; (for i686)

Compiling VCMI for Windows on Linux

Some developers may want to make Windows builds without dealing with dependencies as it may be headache when you're on Windows. It's possible to setup own cross-compiler toolkit that use MinGW, but that take time and skill. Fortunately we can use Conan Package Manager that make cross compilation easy and work out of box for our engine. Conan for cross-compiling VCMI is supported only from VCMI 1.2+


Precompiled build from CI

In order to speed up Conan cross compilation time on CI we use precompiled Conan dependencies packages for Ubuntu 22.04 x86_64. Assuming that you already install requirements, this should be easy.

curl -L "https://github.com/vcmi/vcmi-deps-windows-conan/releases/download/1.0/vcmi-deps-windows-conan-w64.tgz" | tar -C ~/.conan -xzf -

Conan package manager

Please find detailed instructions in VCMI repository. Note that the link points to the cutting-edge state in develop branch, for the latest release check the same document in the master branch.

On the step where you need to replace PROFILE, choose:

  • if you're want 64-bit: mingw64-linux.jinja
  • if you're want 32-bit: mingw32-linux.jinja

Note: if you wish to build 1.2 release in non-Release configuration, you should define USE_CONAN_WITH_ALL_CONFIGS=1 environment variable when executing conan install.

Building

If you are on CMake 3.20+, simply use cmake --preset windows-mingw-conan-linux for configure and cmake --build --preset windows-mingw-conan-linux --target package for automatic generator of install script. If you have CMake version incapable of doing presets, you need to use this command cmake <path> -DCMAKE_TOOLCHAIN_FILE=/home/rilian/Projects/vcmi/conan-generated/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW <additional cmake options> and then use make package or ninja package (if -G Ninja) in your generated path.

Testing build

After compile, you can run generated binaries by using Wine from here (assuming, you used CMake preset):

out/build/windows-mingw-conan-linux/bin/vcmilauncher
out/build/windows-mingw-conan-linux/bin/vcmiclient
out/build/windows-mingw-conan-linux/bin/vcmiserver

You need to copy H3 data as with usual VCMI installation.

Troubleshooting

In case of troubles you can always consult our CI build scripts or contact the dev team via slack