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

From VCMI Project Wiki
Jump to: navigation, search
(Prerequisites)
Line 1: Line 1:
 
= Prerequisites =
 
= Prerequisites =
 
* HoMM 3 (can be bought at [http://www.gog.com/en/gamecard/heroes_of_might_and_magic_3_complete_edition/ gog.com])
 
* HoMM 3 (can be bought at [http://www.gog.com/en/gamecard/heroes_of_might_and_magic_3_complete_edition/ gog.com])
 +
 +
* Git or git GUI, for example, SourceTree [http://www.sourcetreeapp.com/download download]
 
   
 
   
 
* CMake [https://cmake.org/download/ download]
 
* CMake [https://cmake.org/download/ download]
* Git or git GUI, for example, SourceTree [http://www.sourcetreeapp.com/download download]
+
* Qt5 [http://download.qt.io/official_releases/online_installers/qt-unified-windows-x86-online.exe download]  
 
* Qt5 bundle [http://download.qt.io/official_releases/online_installers/qt-unified-windows-x86-online.exe download]  
 
  
* Libraries pack ([http://1drv.ms/1mSeRtX download]), which contains
+
* Libraries pack ([http://1drv.ms/1mSeRtX download])
** [http://www.ffmpeg.org/download.html FFmpeg]
 
** SDL libraries
 
*** [http://www.libsdl.org/ SDL2]
 
*** [https://www.libsdl.org/projects/SDL_image/ SDL2_image]
 
*** [https://www.libsdl.org/projects/SDL_mixer/ SDL2_mixer]
 
*** [https://www.libsdl.org/projects/SDL_ttf/ SDL2_ttf]
 
** [http://zlib.net/ ZLib]
 
  
 
If you want to use Visual Studio compiler
 
If you want to use Visual Studio compiler
 
* Microsoft Visual Studio 2015([http://www.visualstudio.com/downloads/download-visual-studio-vs download])
 
* Microsoft Visual Studio 2015([http://www.visualstudio.com/downloads/download-visual-studio-vs download])
* Boost bundle [http://sourceforge.net/projects/boost/files/boost-binaries/1.56.0/boost_1_56_0-msvc-12.0-32.exe/download download]
+
* Boost MSVC bundle [http://sourceforge.net/projects/boost/files/boost-binaries/1.56.0/boost_1_56_0-msvc-12.0-32.exe/download download]
  
 
If you want to use MinGW compiler
 
If you want to use MinGW compiler
* Boost libraries [http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.7z/download download] (<=1.55, Boost 1.56 has error and incompatible)
+
* Boost libraries source code [http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.7z/download download] (<=1.55, Boost 1.56 has error and incompatible)
  
 
== Create initial directory ==
 
== Create initial directory ==

Revision as of 16:54, 4 September 2016

Prerequisites

  • Git or git GUI, for example, SourceTree download

If you want to use Visual Studio compiler

If you want to use MinGW compiler

  • Boost libraries source code download (<=1.55, Boost 1.56 has error and incompatible)

Create initial directory

Create a directory for VCMI development, eg. C:\VCMI We will call this directory as [VCMIBUILD_DIR]

It is recommended to avoid non-ascii characters in the path to your VCMI development folder. 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)

Preparing place

Clone VCMI

Install Boost bundle (only for MSVC)

  • Run installer
  • Select [VCMIBUILD_DIR]/boost as destination folder
  • Install

Install Qt bundle

  • Run installer
  • Select latest Qt for mingw and mingw 4.8.2 from tools
  • Select [VCMIBUILD_DIR]/qt as destination folder
  • Install
  • Add [VCMIBUILD_DIR]/Qt/Tools/mingw482_32/bin to PATH system variable.

Unpack libraries

  • Download libraries pack and unpack it in [VCMIBUILD_DIR]/depends folder

So, you should get

  • [VCMIBUILD_DIR]
    • depends
      • bin
      • include
      • lib
      • share

Compiling (MinGW)

Create toolchain file

Create [VCMIBUILD_DIR]/toolchain.txt

SET(CMAKE_SYSTEM_NAME Windows)
SET(VCMIBUILD_DIR [ENTER YOUR VCMIBUILD_DIR PATH])

SET(CMAKE_C_COMPILER   ${VCMIBUILD_DIR}/Qt/Tools/mingw482_32/bin/gcc.exe)
SET(CMAKE_CXX_COMPILER ${VCMIBUILD_DIR}/Qt/Tools/mingw482_32/bin/g++.exe)

SET(ENV{BOOST_ROOT} ${VCMIBUILD_DIR}/boost)

SET(CMAKE_FIND_ROOT_PATH  ${VCMIBUILD_DIR}/depends)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_FIND_ROOT_PATH})
list(APPEND CMAKE_PREFIX_PATH ${VCMIBUILD_DIR}/Qt/5.3/mingw482_32)

SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)

Compile boost

  • Unpack boost archive
  • Execute
bootstrap.bat mingw
b2 toolset=gcc --without-python --stage
  • copy stage/lib to [VCMIBUILD_DIR]/boost/lib
  • copy boost dir to [VCMIBUILD_DIR]/boost/boost

So, you should get

  • [VCMIBUILD_DIR]
    • boost
      • boost
      • lib

Compile VCMI

  • Open CMake-gui
  • Select [VCMIBUILD_DIR]/vcmi/source as source directory
  • Select [VCMIBUILD_DIR]/vcmi/binary as binary directory
  • click "Configure"
  • Select "MinGW makefiles" in combobox
  • Select "Specify toolchain file for crosscompiling"
  • Select toolchain file
  • Set variables:
    • CMAKE_INSTALL_PREFIX = [VCMIBUILD_DIR]/vcmi/result
    • ENABLE_PCH = OFF (because of cc1plus.exe crash)
  • click Configure
  • click Generate
  • go to [VCMIBUILD_DIR]/vcmi/binary directory
  • execute mingw32-make
  • execute mingw32-make install
  • Grab VCMI in [VCMIBUILD_DIR]/vcmi/result folder!

Compiling (MSVC)

Create toolchain file

Create [VCMIBUILD_DIR]/toolchain.txt

SET(CMAKE_SYSTEM_NAME Windows)
SET(VCMIBUILD_DIR [ENTER YOUR VCMIBUILD_DIR PATH])

SET(CMAKE_C_COMPILER   cl)
SET(CMAKE_CXX_COMPILER cl)
set(CMAKE_RC_COMPILER rc)


SET(ENV{BOOST_ROOT} ${VCMIBUILD_DIR}/boost)
SET(ENV{BOOST_LIBRARYDIR} ${VCMIBUILD_DIR}/boost/lib32-msvc-12.0)

SET(CMAKE_FIND_ROOT_PATH  ${VCMIBUILD_DIR}/depends)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_FIND_ROOT_PATH})
list(APPEND CMAKE_PREFIX_PATH ${VCMIBUILD_DIR}/Qt/5.3/msvc2013)

SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)

Compile VCMI

  • Open CMake-gui


  • Select [VCMIBUILD_DIR]/vcmi/source as source directory
  • Select [VCMIBUILD_DIR]/vcmi/binary as binary directory
  • click "Configure"
  • Select "Visual Studio 12 2013" in combobox
  • Select "Specify toolchain file for crosscompiling"
  • Select toolchain file
  • Set variables:
    • CMAKE_INSTALL_PREFIX = [VCMIBUILD_DIR]/vcmi/result
  • click Configure
  • click Generate
  • go to [VCMIBUILD_DIR]/vcmi/binary directory


  • open VCMI.sln in visual studio
  • select "Release" build type in combobox
  • right click on BUILD_ALL project - build project
  • right click on INSTALL project - build project
  • Grab VCMI in [VCMIBUILD_DIR]/vcmi/result folder!

Appendix A. Libraries compilation

How to compile ZLib yourself

  • Unpack archive to temp folder, for example, [VCMIBUILD_DIR]/zlib/src
  • Open CMake-gui
  • Select [VCMIBUILD_DIR]/zlib/src as source directory
  • Select [VCMIBUILD_DIR]/zlib/bin as binary directory
  • click "Configure"
  • Select "MinGW makefiles" in combobox
  • Select "Specify toolchain file for crosscompiling"
  • Select toolchain file
  • Set variables:
    • INSTALL_BIN_DIR = [VCMIBUILD_DIR]/depends/bin
    • INSTALL_INC_DIR = [VCMIBUILD_DIR]/depends/include
    • INSTALL_LIB_DIR = [VCMIBUILD_DIR]/depends/lib
    • INSTALL_MAN_DIR = [VCMIBUILD_DIR]/depends/share/man
    • INSTALL_PKGCONFIG_DIR = [VCMIBUILD_DIR]/depends/share/pkgconfig
  • click Configure
  • click Generate
  • go to [VCMIBUILD_DIR]/zlib/bin directory
  • execute mingw32-make
  • execute mingw32-make install

Compile FFmpeg (MinGW)

  • Download FFmpeg source tarball(link) and unpack it to temp folder, for example, [VCMIBUILD_DIR]/ffmpeg/source
  • Download Msys2 (link) and install it
  • Open Msys2
  • execute pacman -Syu and close Msys2
  • run autorebase.bat and start Msys2
  • execute pacman -S make pkg-config yasm
  • Go to /c/[VCMIBUILD_DIR]/ffmpeg/source folder
  • Execute
./configure --disable-doc --target-os=mingw32 --enable-shared --prefix=/c/[VCMIBUILD_DIR]/depends
make 
make install

Compile FFmpeg (MSVC)

  • Download Msys2 32-bit (download link) and install it to [VCMIBUILD_DIR]/msys
  • Download FFmpeg source tarball (download link) and unpack it to temp folder, for example, [VCMIBUILD_DIR]/ffmpeg/source
  • Open Visual Studio console ( C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts\VS2013 x86 Native Tools Command Prompt.lnk )
  • Open [VCMIBUILD_DIR]/msys/msys2_shell.bat
  • execute
pacman -S yasm
  • Go to /c/[VCMIBUILD_DIR]/ffmpeg/source folder
./configure --toolchain=msvc --target-os=win32 --enable-shared --prefix=/c/[VCMIBUILD_DIR]/depends
make 
make install