Skip to content

Building on Windows

matty0ung edited this page Jan 14, 2023 · 24 revisions

Introduction

There are potentially several options for how you build on Windows. The instructions here are intended to keep things simple for a Linux developer who is supporting Windows as a secondary build platform. If Windows is your primary build platform, and you already have compilers and other tools installed, you will probably want to get things working a slightly different way (eg without using MSYS2, and using MSVC rather than gcc).

MSYS2

In the interests of simplicity, we suggest you next download and install MSYS2. In and of itself, it isn't needed for building Brewken, but it makes installing and updating all the rest of the required tools a lot easier, including by virtue of providing a Linux-like environment, a package manager (Pacman) and a repository of over 2000 pre-built packages. It's what's used to do the GitHub server-side automated builds for Windows. The downside is that you can't mix-and-match with things installed outside the MSYS2 environment. Once you install MSYS2, you have a directory (eg C:\msys64\) which is the "root" directory of the MSYS2 environment and, inside which, you need to install all the packages you need per the instructions below.

Download and install the latest MSYS2 installer. At the end, when you run it, you will be in the Mintty command line terminal. You rest of this guide tell you how to execute commands in this terminal to install the remaining tools you need.

Update the package database and base packages

This is the short version of the instructions on the MSYS2 home page:

  • In Mintty, enter the command pacman -Syu and enter Y to the question about installing
  • Close the Mintty terminal and open a new one by selecting "MSYS2 MSYS" from the Windows Start menu
  • In the new Mintty, enter the command pacman -Su and, if prompted, enter Y to the question about installing. (Do not worry if it says there is nothing to do. Just proceed with the steps below.)

General notes on installing packages

Packages come in different architectures, which are reflected in the names - eg "x86_64" is 64-bit and "i686" is 32-bit. The instructions below assume you are installing 64-bit. However, if you want to build Windows packages you might be better off installing 32-bit as there is currently some limitation on the NSIS installer that means it does not support 64-bit packages.

Pacman has lots of options. The --needed flag we use below just stops packages being reinstalled if they're already installed. Also, if you want to, you can combine all the commands below in the obvious way to install everything in one go.

If you want to remove a package it's simple. Eg, to remove package foobar it's:

pacman -Rns foobar

Important - read this before continuing

If you look carefully in the Windows Start menu, you will see MSYS2 actually ships with several different versions of Mintty. Once you've installed all the packages below, they won't just work "out of the box" in the same terminal that you've been using to do the installs. Instead, you need to run the version of Mintty appropriate to the toolchain you want to use. So, if you've installed 64-bit MinGW versions of everything (per the instructions below) then go to the Windows Start menu and select "MSYS2 MinGW 64-bit" before you, say, try to run CMake, otherwise you will get confusing errors.

Automatic Installation

The quickest way to get everything else set-up is to install Python, Pip and Git, and run the bt setup script to install everything else.

Run the following commands from Mintty:

   # pacman -S --needed mingw-w64-x86_64-python
   ...
   # pacman -S --needed mingw-w64-x86_64-python-pip
   ...
   # pacman -S --needed git
   ...

Then, once you have checked out the code from Git, run the following command from Mintty inside the brewken directory:

   # ./bt setup all

Manual Installation

An alternative to having the bt script set everything up is to install all the dependencies manually.

Qt

Try pacman -S --needed mingw-w64-x86_64-qt5

MinGW & GCC

MinGW provides a way to use the GCC compiler and related tools on Windows. Use the following command to install from Mintty:

pacman -S --needed base-devel mingw-w64-x86_64-toolchain gcc

CMake

CMake is the build system used by Brewken (and Brewtarget). Use the following command to install from Mintty:

pacman -S --needed mingw-w64-x86_64-cmake cmake

Git

No prizes for guessing why you need this. Use the following command to install from Mintty:

pacman -S --needed git

Xerces & Xalan

We use these for processing XML, as the built-in XML support in Qt is a bit minimalist. (See comments in the code for more detail.) Use the following command to install from Mintty:

pacman -S --needed mingw-w64-x86_64-xerces-c mingw-w64-x86_64-xalan-c

Boost & dependencies

Currently used for logging stack traces, and planned to be used for supporting BeerJSON. For stack traces on Windows, we also need libbacktrace. Use the following command to install from Mintty:

pacman -S --needed mingw-w64-x86_64-boost mingw-w64-x86_64-libbacktrace

Doxygen

Used for generating code documentation from source code comments. Use the following command to install from Mintty:

pacman -S --needed doxygen

NSIS (Nullsoft Scriptable Install System)

Used for creating installable packages:

pacman -S --needed mingw-w64-x86_64-nsis