Building VCMI for macOS
Requirements
- C++ toolchain, either of:
- Xcode Command Line Tools (aka CLT):
sudo xcode-select --install - Xcode IDE: https://developer.apple.com/xcode/
- (not tested) other C++ compilers, e.g. gcc/clang from Homebrew
- Xcode Command Line Tools (aka CLT):
- CMake:
brew install --cask cmakeor get from https://cmake.org/download/ - Optional:
- Ninja:
brew install ninjaor get it from https://github.com/ninja-build/ninja/releases - CCache to speed up recompilation:
brew install ccache
- Ninja:
Obtaining source code
Clone https://github.com/vcmi/vcmi with submodules. Example for command line:
Obtaining dependencies
There're 2 ways to get dependencies automatically.
Conan package manager (recommended)
We use this to produce builds on CI.
Please find detailed instructions here. Note that the link points to the state of the current 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 on an Intel Mac:
macos-intel - if you're on an Apple Silicon Mac:
macos-arm
Homebrew
- Install Homebrew
- Install dependencies:
brew install boost minizip sdl2 sdl2_image sdl2_mixer sdl2_ttf tbb- you can also use minizip-ng instead of minizip
- If you want to watch in-game videos, also install FFmpeg:
brew install ffmpeg(you can also use an earlier FFmpeg version) - Install Qt dependency in either of the ways (note that you can skip this if you're not going to build Launcher and Map editor):
brew install qt@5for Qt 5 orbrew install qtfor Qt 6- using Qt Online Installer
Preparing build environment
This applies only to Xcode-based toolchain. If xcrun -f clang prints errors, then use either of the following ways:
- select an Xcode instance from Xcode application - Preferences - Locations - Command Line Tools
- use
xcode-selectutility to set Xcode or Xcode Command Line Tools path, example:sudo xcode-select -s /Library/Developer/CommandLineTools - set
DEVELOPER_DIRenvironment variable pointing to Xcode or Xcode Command Line Tools path, example:export DEVELOPER_DIR=/Applications/Xcode.app
Configuring project for building
Note that if you wish to use Qt Creator or CLion IDE, you should skip this step and configure respective variables inside the IDE. Or you could create a CMake preset to avoid manual configuration.
The following walkthrough lists only the bare minimum of required CMake options.
- In Terminal
cdto the source code directory - Start assembling CMake invocation: type
cmake -S . -B BUILD_DIRwhere BUILD_DIR can be any path, don't press Return - Decide which CMake generator you want to use:
- Xcode IDE (if you have installed it): pass
-G Xcode - Ninja (if you have installed it): pass
-G Ninja - Makefiles: no extra option needed or pass
-G 'Unix Makefiles'
- Xcode IDE (if you have installed it): pass
- If you picked Makefiles or Ninja, pick desired build type - either of
Debug/RelWithDebInfo/Release/MinSizeRel- and pass it inCMAKE_BUILD_TYPEoption, example:-D CMAKE_BUILD_TYPE=Debug. If you use don't pass this option,RelWithDebInfowill be used. - Next step depends on the dependency manager you have picked:
- Conan: pass
--toolchain conan-generated/conan_toolchain.cmake(or viaCMAKE_TOOLCHAIN_FILEvariable) where conan-generated must be replaced with your directory choice - Homebrew: if you installed Qt 5 or from the Online Installer, you need to pass
-D "CMAKE_PREFIX_PATH="variable. See below what you can insert after=(but before the closing quote), multiple values must be separated with;(semicolon):- if you installed Qt 5 from Homebrew, insert
$(brew --prefix qt@5) - if you installed Qt from Online Installer, insert your path to Qt directory, example:
/Users/kambala/dev/Qt-libs/5.15.2/Clang64
- if you installed Qt 5 from Homebrew, insert
- Conan: pass
- Now press Return
Building project
You must also install game files to be able to run the built version, see Installation on macOS.
From Xcode IDE
Open VCMI.xcodeproj from the build directory, select vcmiclient scheme and hit Run (Cmd+R). To build Launcher, select vcmilauncher scheme instead.
From command line
cmake --build <path to build directory>
- If using Makefiles generator, you'd want to utilize all your CPU cores by appending
-- -j$(sysctl -n hw.ncpu)to the above - If using Xcode generator, you can also choose which configuration to build by appending
--config <configuration name>to the above, example:--config Debug
Running VCMI
You can run binaries from your IDE or directly from the bin directory:
- BUILD_DIR/bin/vcmilauncher
- BUILD_DIR/bin/vcmiclient
- BUILD_DIR/bin/vcmiserver
- BUILD_DIR/bin/vcmimapeditor