Compiling TrenchBroom for Windows

This is a comprehensive guide which shows you how to download, install and use the right software on Windows to compile TrenchBroom from source.

Table of Contents

Background

Sometimes if you want to experience the latest version of an open source software package, you have to compile it yourself. I've found this to be the case with TrenchBroom which can be sometimes many months between releases. Recently I've started compiling it myself because of some nasty GUI text scaling bugs present in the (as of this article) latest 2021.1 binary release which affects the way I have things set up on my PC.

I'm not a software developer by any means, and writing this article is a more than anything a guide for myself for when I very occasionally need to come back and compile TrenchBroom from source. I hope it can also benefit the odd person out there looking to do the same thing.

Preface

The following tutorial requires the installation of lots of different pieces of software. In instances where lots of software installation is required and used once or at best sparingly, to keep your machine clean I recommend installation within a virtual machine. I use VirtualBox and set up a Windows virtual guest for this. There's plenty of VirtualBox tutorials on the web to guide you through this.

Think of this guide as a much more in depth version of the Windows build guide from the TrenchBroom Github build page.

If you're using Windows 11, the majority of the software you'll need can be obtained by using winget in the Windows Terminal. You'll be able to follow the commands below to install just about everything. Otherwise, follow the download links also provided to manually download and install.

Getting everything installed

Visual Studio

Download and install Visual Studio Community 2022. You can install and run Visual Studio Community without having a Microsoft account, but after 30 days it will prompt you to log in using one. This is up to you as to how you want to navigate this initially, but I just used one of my Microsoft accounts.

In Windows Terminal, enter the following:

winget install -e Microsoft.VisualStudio.2022.Community

Search for and open the Visual Studio Installer on the Start menu.

Once the installer begins, select "Modify" and on the next page be sure to check the "Desktop Development With C++" workload and check "MSVC v142 - VS 2019 C++ x64/x86" under "Installation details".

To download manually go to https://visualstudio.microsoft.com/vs/community/ and follow the download link for the online installer.

CMake

In Windows Terminal, enter the following:

winget install -e Kitware.CMake

To download manually go to https://cmake.org/download/ to download and run the latest 64-bit .msi installer for Windows.

Pandoc

In Windows Terminal, enter the following:

winget install -e JohnMacFarlane.Pandoc

To download manually go to https://pandoc.org/installing.html to download and run the latest 64-bit .msi installer for Windows.

Git

In Windows Terminal, enter the following:

winget install -e Git.Git

To download manually go to https://gitforwindows.org/ to download and run the latest 64-bit .exe installer for Windows.

Qt

Register for a Qt account at https://login.qt.io/register, then download the open source version at https://www.qt.io/download. You'll need to follow the "Go Open Source" link. Once downloaded, run through the installer and when you get to the "Select Components" screen, be sure to check Qt 5.15.2 with MSVC 2019 64-bit.

Download TrenchBroom source from GitHub

Open Windows Terminal and run the following command to download the TrenchBroom source files from the GitHub repository:

git clone --recursive https://github.com/TrenchBroom/TrenchBroom.git

Compiling everything

CMake

Open Windows Terminal and run the following commands:

mkdir .\TrenchBroom\build

cd .\TrenchBroom\build
cmake .. -G "Visual Studio 17 2022" -T v142 -A x64 -DCMAKE_PREFIX_PATH="C:\Qt\5.15.2\msvc2019_64"

Visual Studio

Open Windows Terminal and run the following command:

& 'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\msbuild.exe' .\TrenchBroom.sln /property:Configuration=Release /property:Platform=x64

Alternatively, if you prefer to use the Visual Studio GUI to compile, open Visual Studio, browse and open the TrenchBroom solution file at C:\Users\<user>\TrenchBroom\build\TrenchBroom.sln
 
Make sure you change the configuration from "Debug" to "Release" in the menu drop down, and then select "Build" -> "Build Solution".

Lastly, you'll find TrenchBroom compiled and ready to use in C:\Users\<user>\TrenchBroom\build\app\Release\.

Success! Copy the contents of the Release directory to a preferred location on your PC and run TrenchBroom by launching TrenchBroom.exe.