Difference between revisions of "How to build VCMI (Windows/Vcpkg)"

From VCMI Project Wiki
Jump to: navigation, search
(Compile VCMI from command line)
(Replaced content with "{{Template:MovedToWebpage|https://vcmi.eu/developers/Building_Windows/}}")
 
(16 intermediate revisions by 4 users not shown)
Line 1: Line 1:
= Prerequisites =
+
{{Template:MovedToWebpage|https://vcmi.eu/developers/Building_Windows/}}
* Windows Vista or newer.
 
* Microsoft Visual Studio [https://www.visualstudio.com/vs/older-downloads/ 2017] or [http://www.visualstudio.com/downloads/download-visual-studio-vs 2019]
 
* Git or git GUI, for example, SourceTree [http://www.sourcetreeapp.com/download download]
 
* CMake [https://cmake.org/download/ download]. During install after accepting license agreement make sure to check "Add CMake to the system PATH for all users".
 
* To unpack pre-build Vcpkg: [http://www.7-zip.org/download.html 7-zip]
 
* To create installer: [http://nsis.sourceforge.net/Main_Page NSIS]
 
 
 
= Choose directory =
 
 
 
Create a directory for VCMI development, eg. '''C:\VCMI'''
 
We will call this directory as '''[VCMI_DIR]'''
 
 
 
'''Warning!''' Replace '''[VCMI_DIR]''' with path you chosen in following commands of this instruction.
 
 
 
== How to choose good directory ==
 
 
 
It is recommended to avoid non-ascii characters in the path to your working folders. The folder should not be write-protected by system.
 
Good location:
 
* '''C:\VCMI'''
 
Bad locations:
 
* '''C:\Users\Michał\VCMI''' (non-ascii character)
 
* '''C:\Program Files (x86)\VCMI''' (write protection)
 
 
 
= Install dependencies =
 
 
 
You have two options: to use pre-built libraries or build your own. We strongly recommend start with using pre-built ones.
 
 
 
== Option A. Use pre-built Vcpkg ==
 
So you decide to start using Vcpkg packages pre-built by VCMI team.
 
 
 
Package guaranteed to work since they tested with every commit by [https://ci.appveyor.com/project/vcmi/vcmi AppVeyor]
 
 
 
=== Download and unpack archive ===
 
 
 
Archives are available from GitHub: https://github.com/vcmi/vcmi-deps-windows/releases
 
 
 
Only download latest version available.
 
 
 
* vcpkg-export-'''x86'''-windows-v140.7z to build for 32-bit
 
* vcpkg-export-'''x64'''-windows-v140.7z to build for 64-bit
 
 
 
Extract archive by right clicking on it and choosing "7-zip -> Extract Here".
 
 
 
=== Move dependencies to target directory  ===
 
 
 
Once extracted "vcpkg" directory will appear with "installed" and "scripts" inside it.
 
 
 
Move extracted "vcpkg" directory into your '''[VCMI_DIR]'''.
 
 
 
== Option B. Build Vcpkg on your own ==
 
Be aware that building Vcpkg might take a lot of time depend on your CPU model and 10-20GB of disk space.
 
=== Create initial directory ===
 
 
 
=== Clone vcpkg ===
 
 
 
# open SourceTree
 
# File -> Clone
 
# select '''https://github.com/microsoft/vcpkg/''' as source
 
# select '''[VCMI_DIR]/vcpkg''' as destination
 
# click '''Clone'''
 
 
 
From command line use:
 
<pre>
 
git clone https://github.com/microsoft/vcpkg.git [VCMI_DIR]/vcpkg
 
</pre>
 
 
 
=== Build vcpkg ===
 
* Run
 
<pre>
 
[VCMI_DIR]/vcpkg/bootstrap-vcpkg.bat
 
</pre>
 
 
 
=== Build dependencies ===
 
* For 32-bit build run:
 
<pre>
 
[VCMI_DIR]/vcpkg/vcpkg.exe install minizip:x86-windows sdl2:x86-windows sdl2-image:x86-windows sdl2-ttf:x86-windows sdl2-mixer:x86-windows boost:x86-windows qt5-base:x86-windows ffmpeg:x86-windows fuzzylite:x86-windows smpeg2:x86-windows
 
</pre>
 
* For 64-bit build run
 
<pre>
 
[VCMI_DIR]/vcpkg/vcpkg.exe install minizip:x64-windows sdl2:x64-windows sdl2-image:x64-windows sdl2-ttf:x64-windows sdl2-mixer:x64-windows boost:x64-windows qt5-base:x64-windows ffmpeg:x64-windows fuzzylite:x64-windows smpeg2:x64-windows
 
</pre>
 
 
 
= Build VCMI =
 
 
 
== Clone VCMI ==
 
# open SourceTree
 
# File -> Clone
 
# select '''https://github.com/vcmi/vcmi/''' as source
 
# select '''[VCMI_DIR]/source''' as destination
 
# expand Advanced Options and change Checkout Branch to "develop"
 
# tick Recursive submodules
 
# click '''Clone'''
 
 
 
or From command line use:
 
<pre>
 
git clone --recursive https://github.com/vcmi/vcmi.git [VCMI_DIR]/source
 
</pre>
 
 
 
== Generate solution for VCMI ==
 
# create '''[VCMI_DIR]/build''' folder
 
# open '''[VCMI_DIR]/build''' in command line:
 
## Run Command Prompt or Power Shell.
 
## Execute: cd [VCMI_DIR]/build
 
# execute one of following commands to generate project
 
 
 
'''Visual Studio 2017 - 32-bit build'''
 
<pre>
 
cmake [VCMI_DIR]/source -DCMAKE_TOOLCHAIN_FILE=[VCMI_DIR]/vcpkg/scripts/buildsystems/vcpkg.cmake -G "Visual Studio 15 2017"
 
</pre>
 
 
 
'''Visual Studio 2017 - 64-bit build'''
 
<pre>
 
cmake [VCMI_DIR]/source -DCMAKE_TOOLCHAIN_FILE=[VCMI_DIR]/vcpkg/scripts/buildsystems/vcpkg.cmake -G "Visual Studio 15 2017 Win64"
 
</pre>
 
 
 
'''Visual Studio 2019 - 32-bit build'''
 
<pre>
 
cmake [VCMI_DIR]/source -DCMAKE_TOOLCHAIN_FILE=[VCMI_DIR]/vcpkg/scripts/buildsystems/vcpkg.cmake -G "Visual Studio 16 2019" -A Win32
 
</pre>
 
 
 
'''Visual Studio 2019 - 64-bit build'''
 
<pre>
 
cmake [VCMI_DIR]/source -DCMAKE_TOOLCHAIN_FILE=[VCMI_DIR]/vcpkg/scripts/buildsystems/vcpkg.cmake -G "Visual Studio 16 2019" -A x64
 
</pre>
 
 
 
== Compile VCMI with Visual Studio ==
 
# open '''[VCMI_DIR]/build/VCMI.sln''' in Visual Studio
 
# select "Release" build type in combobox
 
# right click on '''BUILD_ALL''' project - build project
 
# grab VCMI in '''[VCMI_DIR]/build/bin''' folder!
 
 
 
== Compile VCMI from command line ==
 
 
 
'''For release build'''
 
<pre>
 
cmake --build [VCMI_DIR]/build --config Release
 
</pre>
 
 
 
'''For debug build'''
 
<pre>
 
cmake --build [VCMI_DIR]/build --config Debug
 
</pre>
 
Debug will be used by default even "--config" if not specified.
 
 
 
for some users who need to disable tests, this might help:
 
-DENABLE_TEST=0
 
 
 
= Create VCMI installer =
 
Make sure NSIS is installed to default directory or have registry entry so CMake can find it.
 
 
 
After you build VCMI execute following commands from '''[VCMI_DIR]/build'''.
 
=== Execute following if you built for Release: ===
 
<pre>
 
cpack
 
</pre>
 
=== If you built for Debug: ===
 
<pre>
 
cpack -C Debug
 
</pre>
 
 
 
= Troubleshooting and workarounds =
 
Vcpkg might be very unstable due to limited popularity and fact of using bleeding edge packages (such as most recent Boost). Using latest version of dependencies could also expose both problems in VCMI code or library interface changes that developers not checked yet. So if you're built Vcpkg yourself and can't get it working please try to use binary package.
 
 
 
Pre-built version we provide is always manually tested with all supported versions of MSVC for both Release and Debug builds and all known quirks are listed below.
 
 
 
=== Debug build of VCMI won't run since SDL2.dll / libbz2.dll missing ===
 
 
 
Almost all of Vcpkg debug libraries are built with "d" prefix, but for whatever reason VCMI or some libraries might expect them to be named without prefix. Workaround is to just make a copy of said library with different name.
 
 
 
Likely this can be resolved by some CMake configuration magic so if you know how please make pull request.
 
 
 
=== I got crash within library XYZ.dll ===
 
 
 
Good workaround is to use debug version of said library instead of release one or vice versa. If that's helped you can swap the library within Vcpkg package itself so you don't need to do it every time when you.
 
 
 
=== Debug build is very slow ===
 
 
 
Debug builds with MSVC are generally extremely slow since it's not just VCMI binaries are built as debug, but every single dependency too and this usually mean no optimizations at all. Debug information that available for release builds is often sufficient so just avoid full debug builds unless absolutely necessary.
 

Latest revision as of 16:07, 16 July 2024

Logo256.png    Page moved to VCMI-Homepage