<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Developer – Manual builds</title><link>/docs/getting-started/building/manual-build/</link><description>Recent content in Manual builds on Developer</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/getting-started/building/manual-build/index.xml" rel="self" type="application/rss+xml"/><item><title>Docs: Building KDE software with CMake</title><link>/docs/getting-started/building/manual-build/cmake-build/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/docs/getting-started/building/manual-build/cmake-build/</guid><description>
&lt;p&gt;While users on older Linux distributions might have to resort to &lt;a href="/docs/getting-started/building/kde-builder/kde-builder-setup/" &gt;kde-builder&lt;/a&gt; or containers to be able to build KDE software, users of more up-to-date distributions might not need to use them.&lt;/p&gt;
&lt;p&gt;The process of building KDE software with kde-builder or containers involves builds from the master branch, which includes unreleased code changes. These changes might rely on unreleased changes from other dependencies, so you end up needing to build those dependencies as well. This is often the case with very fast-paced software such as KDE’s &lt;a href="https://apps.kde.org/itinerary/" &gt;Itinerary&lt;/a&gt; and &lt;a href="https://apps.kde.org/neochat/" &gt;Neochat&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;kde-builder uniquely also makes it easy to run a whole Plasma Desktop session.&lt;/p&gt;
&lt;p&gt;If the software you want to contribute to is an application that does not have bleeding edge build dependencies, it is perfectly possible (and faster and easier) to build it manually by running CMake commands on a sufficiently up-to-date Linux distribution, like the latest &lt;a href="https://fedoraproject.org/spins/kde/" &gt;Fedora&lt;/a&gt;, &lt;a href="https://get.opensuse.org/tumbleweed/" &gt;openSUSE Tumbleweed&lt;/a&gt;, or &lt;a href="https://archlinux.org/" &gt;Arch Linux&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If the software you want to contribute to does in fact have bleeding edge dependencies and you do not care about the dependencies themselves, it is also possible to build it manually with CMake by using a distribution that provides KDE software built from the master, like &lt;a href="https://en.opensuse.org/SDB:Argon_and_Krypton" &gt;openSUSE Krypton&lt;/a&gt;, &lt;a href="https://neon.kde.org/download" &gt;KDE neon Unstable Edition, or KDE neon Developer Edition&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This tutorial teaches you the basics of building a KDE project using standalone CMake the right way, how to deal with targets and tests, and the traditional way you &lt;em&gt;will&lt;/em&gt; find in the wild.&lt;/p&gt;
&lt;p&gt;This knowledge is also helpful to Windows users using &lt;a href="https://community.kde.org/Craft" &gt;Craft&lt;/a&gt; who are designing a new application using KDE libraries and haven’t yet created their own Craft blueprints.&lt;/p&gt;
&lt;h2 id="summary"&gt;Summary of commands to build a KDE project manually&lt;/h2&gt;
&lt;p&gt;This summary is provided in case you are already somewhat familiar with CMake or you just want to skip the explanation and check the right commands to quickly start compiling a KDE project.&lt;/p&gt;
&lt;p&gt;On Linux, do:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ --install-prefix ~/.local
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --parallel
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --install build/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;On Windows, do:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --parallel
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --install build/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you get stuck while running the first command, be sure to look at our &lt;a href="/docs/getting-started/building/help/dependencies/" &gt;guide about installing build dependencies for a CMake project&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you get stuck while running the second command, it’s most likely a code issue that is in need of fixing.&lt;/p&gt;
&lt;p&gt;To run tests, do:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ -D &lt;span class="nv"&gt;BUILD_TESTING&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ON
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --target test&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To uninstall the project, do:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --target uninstall&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Keep reading this page if you want to know more about what’s happening under the hood or if you would like to understand the build instructions you might see being provided by KDE projects and others.&lt;/p&gt;
&lt;h2 id="three-steps"&gt;The three compilation steps&lt;/h2&gt;
&lt;p&gt;The compilation process of C++ software with CMake is made of three steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Configuration&lt;/li&gt;
&lt;li&gt;Build&lt;/li&gt;
&lt;li&gt;Installation&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The terms “compilation” and “build” are typically used interchangeably, but from here on “build” will refer to the second compilation step.&lt;/p&gt;
&lt;p&gt;These steps are done in CMake by running the following commands from the root directory of the software project:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ --install-prefix /place/to/install
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --parallel
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --install build/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="build-system-generator"&gt;CMake is a build system generator&lt;/h2&gt;
&lt;p&gt;CMake itself is not really a build system. It doesn’t compile things by itself: it calls other software to compile the project for you, and that software is the build system.&lt;/p&gt;
&lt;p&gt;On Linux, the most common build systems are Make and Ninja. On Windows, the main build system is the MSVC compiler toolset.&lt;/p&gt;
&lt;p&gt;During the configuration step, CMake uses the source files of the project to &lt;em&gt;generate&lt;/em&gt; the necessary files to build the project with a &lt;em&gt;build system&lt;/em&gt; inside a &lt;em&gt;build directory&lt;/em&gt;, otherwise known as &lt;em&gt;binary directory&lt;/em&gt;. Hence, CMake is a &lt;em&gt;build system generator&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;CMake can then build the project by calling &lt;code&gt;make&lt;/code&gt; or &lt;code&gt;ninja&lt;/code&gt; (on Linux) or &lt;code&gt;msbuild&lt;/code&gt; (on Windows) on the generated files:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For &lt;code&gt;make&lt;/code&gt;, the generated file is a &lt;code&gt;Makefile&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;For &lt;code&gt;ninja&lt;/code&gt;, the generated file is a &lt;code&gt;ninja.build&lt;/code&gt; file&lt;/li&gt;
&lt;li&gt;For &lt;code&gt;msbuild&lt;/code&gt;, the generated file is a Visual Studio project file with extension &lt;code&gt;.vcxproj&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Lastly, during the installation step, CMake copies the files built by the build system to the place where it needs to be.&lt;/p&gt;
&lt;h2 id="compiling-on-windows"&gt;Compiling on Windows&lt;/h2&gt;
&lt;p&gt;At this point in time, this guide does not go in-depth about manually compiling projects on Windows.&lt;/p&gt;
&lt;p&gt;The easiest way to compile KDE software on Windows is with Craft, whether you use the provided &lt;code&gt;craft&lt;/code&gt; tool or build a project manually.&lt;/p&gt;
&lt;p&gt;All the instructions on this guide should work by default on a Linux terminal. To follow this guide’s instructions, you will need to set up Craft and run all of the commands using Craft’s provided terminal shell, CraftRoot.&lt;/p&gt;
&lt;h2 id="configuration"&gt;The configuration step&lt;/h2&gt;
&lt;p&gt;The first command prepares the project by trying to find its build dependencies:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can read more about it in the &lt;a href="/docs/getting-started/building/help/dependencies/" &gt;guide about installing build dependencies for a CMake project&lt;/a&gt;.&lt;/p&gt;
&lt;div class="d-flex align-items-center notecard notecard--info" role="alert"&gt;
&lt;span&gt;
&lt;p class="h4 mt-0"&gt;Note for Windows users&lt;/p&gt;Windows users using &lt;a href="https://community.kde.org/Craft" &gt;Craft&lt;/a&gt; can install missing build dependencies with the &lt;code&gt;craft&lt;/code&gt; tool. For example: &lt;code&gt;craft kxmlgui&lt;/code&gt;.
&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;In reality, what CMake is actually running is:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -S . -B build/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;-S&lt;/code&gt; flag specifies where to look for the project’s source code, and the &lt;code&gt;-B&lt;/code&gt; flag specifies the build directory, so the place where to configure and build the project. The build/ directory is automatically created for you if it doesn’t exist.&lt;/p&gt;
&lt;p&gt;This allows you to run the &lt;code&gt;cmake&lt;/code&gt; command from anywhere, as long as you specify the source code directory and where to build it.&lt;/p&gt;
&lt;p&gt;If either flag is omitted, the flag will point to the current directory.&lt;/p&gt;
&lt;p&gt;If both the source code and build directory are omitted, CMake will default to searching for the source code in the current directory or any other place where you point it to, and will put the generated files in the current directory, for example:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Configure the project using the source code&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# in the above directory, then put the&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# generated files in the current directory&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake ..&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="out-of-tree"&gt;Out-of-tree builds&lt;/h3&gt;
&lt;p&gt;There are four common ways to compile a project:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;from the source code folder, putting the generated files in the source code folder&lt;/li&gt;
&lt;li&gt;from a build folder, putting the generated files in the build folder&lt;/li&gt;
&lt;li&gt;from the source code folder, putting the generated files in a build folder&lt;/li&gt;
&lt;li&gt;from outside the source code folder, putting the generated files in a build folder&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The first causes the source code folder to become full with generated and build files together with the source code, making git output dirty. This method is always undesirable and should be avoided:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# From the root of the project source code&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -S . -B .
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Or simply&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake .&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The second is very common and can be found in the wild:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# From the root of the project source code&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;mkdir build/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; build/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake ..&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It is called an out-of-tree build because the generated files are not in the same place as the source code. The build/ directory is still present in the project itself, but it’s typically added to the .gitignore file of a project so as to keep git output clean.&lt;/p&gt;
&lt;p&gt;The third is also an out-of-tree build. It is an optimization on top of the second method and should be preferred:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# From the root of the project source code&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Instead of creating the build/ directory yourself, you can just tell CMake to create it for you with the &lt;code&gt;-B&lt;/code&gt; flag.&lt;/p&gt;
&lt;p&gt;This method is the cleanest and most convenient to use in KDE projects and tutorials.&lt;/p&gt;
&lt;p&gt;The fourth way, which is very commonly done by IDEs (a notable example being &lt;a href="https://doc.qt.io/qtcreator/" &gt;QtCreator&lt;/a&gt;), looks more like this:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# From a directory *above* the source code&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -S projectdir/ -B build/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It is also an out-of-tree build, and in this case the build directory is not even inside the project root folder. It requires doing extra navigation steps, but it is convenient, for example, if you want to have multiple, different build folders in the same place, as is the case with &lt;a href="#multi-config" &gt;multi-configuration builds&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id="generators"&gt;Defining a generator&lt;/h3&gt;
&lt;p&gt;A &lt;em&gt;generator&lt;/em&gt; in the context of CMake is the name given to a build system variant or specialization.&lt;/p&gt;
&lt;p&gt;By running CMake with the &lt;code&gt;-G&lt;/code&gt; flag without passing any parameter to it, CMake will show what generators are available on your system:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -G&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You’ll see something like this:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-man" data-lang="man"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;CMake Error: No generator specified for -G
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Generators
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Green Hills MULTI = Generates Green Hills MULTI files
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; (experimental, work-in-progress).
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;* Unix Makefiles = Generates standard UNIX makefiles.
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Ninja = Generates build.ninja files.
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Ninja Multi-Config = Generates build-&amp;lt;Config&amp;gt;.ninja files.
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Watcom WMake = Generates Watcom WMake makefiles.
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; CodeBlocks - Ninja = Generates CodeBlocks project files
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; (deprecated).
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; CodeBlocks - Unix Makefiles = Generates CodeBlocks project files
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; (deprecated).
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; CodeLite - Ninja = Generates CodeLite project files
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; (deprecated).
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; CodeLite - Unix Makefiles = Generates CodeLite project files
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; (deprecated).
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; (deprecated).
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; (deprecated).
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Kate - Ninja = Generates Kate project files (deprecated).
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Kate - Ninja Multi-Config = Generates Kate project files (deprecated).
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Kate - Unix Makefiles = Generates Kate project files (deprecated).
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Sublime Text 2 - Ninja = Generates Sublime Text 2 project files
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; (deprecated).
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Sublime Text 2 - Unix Makefiles
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; = Generates Sublime Text 2 project files
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; (deprecated).&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The default generator is marked with an asterisk *.&lt;/p&gt;
&lt;p&gt;As you can see, even though Make is a single build system, CMake provides many specialized generators with the name “Unix Makefiles”. Same thing with Ninja.&lt;/p&gt;
&lt;p&gt;Generally, on Linux, the only generators you will ever care about as a KDE developer are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Unix Makefiles&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Ninja&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Ninja - Multi-Config&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Kate - Ninja&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Kate - Ninja Multi-Config&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On Windows, the only generators you will ever care about are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the &lt;code&gt;Visual Studio&lt;/code&gt; generators&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Mingw Makefiles&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Qt projects (and consequently also KDE projects) tend to build slightly faster with the Ninja build system on Linux and tend to produce more reliable builds with Visual Studio generators on Windows.&lt;/p&gt;
&lt;p&gt;Ninja and Visual Studio are also able to do &lt;a href="#multi-config" &gt;multi-configuration builds&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The Kate-derived generators are essentially the same as the Make and Ninja generators, except they create &lt;code&gt;kateproject&lt;/code&gt; files that can be opened with KDE’s main text editor &lt;a href="https://kate-editor.org" &gt;Kate&lt;/a&gt; with the &lt;a href="https://docs.kde.org/stable5/en/kate/kate/kate-application-plugin-build.html" &gt;build plugin&lt;/a&gt; already set up for the current project.&lt;/p&gt;
&lt;p&gt;To set a generator for the project you are attempting to build, use the &lt;code&gt;-G&lt;/code&gt; flag:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ -G &lt;span class="s2"&gt;&amp;#34;Ninja - Multi-Config&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="install-prefix"&gt;Defining the install prefix&lt;/h3&gt;
&lt;p&gt;The install prefix is the root (top-most) folder inside of which the software will be installed.&lt;/p&gt;
&lt;p&gt;Traditionally, the way one would set the install prefix would be by using a &lt;a href="#config-variables" &gt;configuration option&lt;/a&gt; called &lt;code&gt;CMAKE_INSTALL_PREFIX&lt;/code&gt; during the configuration step.&lt;/p&gt;
&lt;p&gt;Since CMake 3.21, this variable can be replaced with the more convenient &lt;code&gt;--install-prefix&lt;/code&gt; flag.&lt;/p&gt;
&lt;p&gt;So where traditionally you'd run:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ -DCMAKE_INSTALL_PREFIX&lt;span class="o"&gt;=&lt;/span&gt;/usr&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can now run:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ --install-prefix /usr&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note that &lt;code&gt;--install-prefix&lt;/code&gt; requires an absolute path, so only options like the following are valid:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;/usr&lt;/code&gt; (already an absolute path)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;~/.local&lt;/code&gt; (expands to &lt;code&gt;/home/youruser/.local&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$PWD/test-prefix&lt;/code&gt; (expands to &lt;code&gt;/home/youruser/currentdir/test-prefix&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The flag (or configuration option) needs to be set during the configuration step, even though the project is only installed during the install step. See &lt;a href="#install" &gt;install step&lt;/a&gt; for details.&lt;/p&gt;
&lt;h3 id="config-variables"&gt;Defining configuration options&lt;/h3&gt;
&lt;p&gt;You can give instructions to override what CMake does by passing variables to the &lt;code&gt;-D&lt;/code&gt; flag followed by &lt;code&gt;=somevalue&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;A common variable seen in KDE projects is used to enable tests:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ -D &lt;span class="nv"&gt;BUILD_TESTING&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ON&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Not all KDE projects might use this variable, but they most likely have an equivalent that is specific to tests.&lt;/p&gt;
&lt;p&gt;You can inspect the boolean configuration options available for a given project by running &lt;code&gt;ccmake&lt;/code&gt; on the build directory after having configured the project:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ccmake build/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can have a space between the &lt;code&gt;-D&lt;/code&gt; flag and the variable, an equal sign, or no space at all:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ -D&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;BUILD_TESTING&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ON &lt;span class="c1"&gt;# Valid&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ -DBUILD_TESTING&lt;span class="o"&gt;=&lt;/span&gt;ON &lt;span class="c1"&gt;# Valid&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And you can use ON/OFF, YES/NO or TRUE/FALSE as values for boolean variables like the above:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ -D &lt;span class="nv"&gt;BUILD_TESTING&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;YES &lt;span class="c1"&gt;# Valid&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ -D &lt;span class="nv"&gt;BUILD_TESTING&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;TRUE &lt;span class="c1"&gt;# Valid&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;KDE has mostly standardized on the ON/OFF pair of values.&lt;/p&gt;
&lt;p&gt;There are two commonly used CMake variables that are found in the wild but have better replacements:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html" &gt;CMAKE_BUILD_TYPE&lt;/a&gt; → &lt;code&gt;--config&lt;/code&gt; flag for the build and install steps&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html" &gt;CMAKE_INSTALL_PREFIX&lt;/a&gt; → &lt;code&gt;--install-prefix&lt;/code&gt; for the configuration step&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;See the sections on &lt;a href="#multi-config" &gt;multi-configuration&lt;/a&gt;, the &lt;a href="#configuration" &gt;configuration step&lt;/a&gt;, and the &lt;a href="#install" &gt;install step&lt;/a&gt;, respectively.&lt;/p&gt;
&lt;h2 id="build"&gt;The build step&lt;/h2&gt;
&lt;p&gt;It doesn’t matter which method you used to generate the necessary files to build the project, you can point to the build directory with the second command:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This step effectively calls the relevant build system &lt;em&gt;for&lt;/em&gt; you. It is virtually the same as running the following with &lt;code&gt;make&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; build
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;make&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;or &lt;code&gt;ninja&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; build
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ninja&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It can be improved by parallelizing the build process, spreading out multiple source code files to your computer’s CPU cores and speeding up build times:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --parallel&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Assuming your machine has 4 CPU cores, this is virtually the same as:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --parallel&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Or&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ -j4
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Or&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; build
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;make -j
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Or&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; build
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ninja&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It is not uncommon to encounter build instructions in the wild that look like the following:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;mkdir build
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; build
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake ..
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;make&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;They can (and should) be replaced with CMake-only instructions, as they better outline the CMake steps needed, require less typing overall, and are agnostic to the build system used:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Another traditional practice that can be observed in the wild and is often necessary is to delete the build directory to rebuild the project in full. This results in a longer build time, but can be used to resolve build cache issues.&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;rm -rf build
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;mkdir build
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; build
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake ..
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Or the somewhat better version&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;rm -rf build
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is no longer necessary, as CMake provides a flag to rebuild the project from scratch:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --clean-first&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="install"&gt;The install step&lt;/h2&gt;
&lt;p&gt;This step installs the contents of the build directory into a certain &lt;em&gt;install prefix&lt;/em&gt;, which was previously set during the &lt;a href="#install-prefix" &gt;configuration step&lt;/a&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ --install-prefix /place/to/install
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --install build/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;On Linux, for example, if the prefix is set to &lt;code&gt;/usr&lt;/code&gt; and the project's executable &lt;code&gt;myprogram&lt;/code&gt; should be installed to &lt;code&gt;bin/&lt;/code&gt;, the executable will be installed to &lt;code&gt;/usr/bin/myprogram&lt;/code&gt;. Similarly, if the prefix is set to &lt;code&gt;~/.local&lt;/code&gt;, the executable will be installed to &lt;code&gt;~/.local/bin/myprogram&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The place where you want a project to be installed &lt;em&gt;for users&lt;/em&gt; is typically &lt;code&gt;/usr&lt;/code&gt; on Linux and &lt;code&gt;c:/Program Files/${PROJECT_NAME}&lt;/code&gt; for Windows. Replace &lt;code&gt;${PROJECT_NAME}&lt;/code&gt; with the name of your project folder.&lt;/p&gt;
&lt;p&gt;For &lt;em&gt;local&lt;/em&gt; builds on Linux however it is a better idea to install the project to &lt;code&gt;~/.local&lt;/code&gt;, as it has the equivalent paths to &lt;code&gt;/usr&lt;/code&gt;, but in userspace.&lt;/p&gt;
&lt;p&gt;The reason the install prefix needs to be set during the configuration step instead of the install step is that sometimes projects may prepare the project such that during the configuration step that need to know the install prefix beforehand. See &lt;a href="#changing-prefix" &gt;Changing the install prefix&lt;/a&gt; for details.&lt;/p&gt;
&lt;h3 id="install-location"&gt;Where the files are installed for KDE projects&lt;/h3&gt;
&lt;p&gt;KDE projects need to install multiple files:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;executables in prefix/bin (BINDIR)&lt;/li&gt;
&lt;li&gt;libraries in prefix/lib or prefix/lib64 (LIBDIR)&lt;/li&gt;
&lt;li&gt;public API header files in prefix/include (INCLUDEDIR)&lt;/li&gt;
&lt;li&gt;QML modules in prefix/${LIBDIR}/qml or prefix/${LIBDIR}/qt6/qml (QMLDIR)&lt;/li&gt;
&lt;li&gt;desktop files in prefix/share/applications (APPDIR)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On Linux with &lt;code&gt;/usr&lt;/code&gt; and &lt;code&gt;~/.local&lt;/code&gt;, these usually translate to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;/usr/bin&lt;/code&gt; and &lt;code&gt;~/.local/bin&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/usr/lib&lt;/code&gt; or &lt;code&gt;/usr/lib64&lt;/code&gt; and &lt;code&gt;~/.local/lib&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/usr/include&lt;/code&gt; and &lt;code&gt;~/.local/include&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/usr/${LIBDIR}/qml&lt;/code&gt; or &lt;code&gt;/usr/${LIBDIR}/qt6/qml&lt;/code&gt; and &lt;code&gt;~/.local/qml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/usr/share/applications&lt;/code&gt; and &lt;code&gt;~/.local/share/applications&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On Windows, they translate instead to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;c:/Program Files/${PROJECT_NAME}/bin&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;c:/Program Files/${PROJECT_NAME}/lib&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;c:/Program Files/${PROJECT_NAME}/include&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;c:/Program Files/${PROJECT_NAME}/lib/qml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;c:/Program Files/${PROJECT_NAME}/bin/data/applications&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are using &lt;a href="https://community.kde.org/Craft" &gt;Craft&lt;/a&gt;‘s terminal shell, CraftRoot, the default prefix is altered to be &lt;code&gt;c:/CraftRoot&lt;/code&gt; instead of &lt;code&gt;c:/Program Files/${PROJECT_NAME}&lt;/code&gt; for convenience.&lt;/p&gt;
&lt;p&gt;All of these paths and more are standardized in KDE software that uses the &lt;a href="https://api.kde.org/ecm/kde-module/KDEInstallDirs6.html" &gt;KDEInstallDirs module of extra-cmake-modules&lt;/a&gt;. To make it easier to understand the linked documentation for KDEInstallDirs, consider:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;EXECROOTDIR&lt;/code&gt; the same as the prefix, so &lt;code&gt;/usr&lt;/code&gt; or &lt;code&gt;c:/Program Files/$PROJECT_NAME&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DATAROOTDIR&lt;/code&gt; the same as &lt;code&gt;/usr/share&lt;/code&gt; on Linux or &lt;code&gt;c:/Program Files/${PROJECT_NAME}/bin/data&lt;/code&gt; on Windows&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="changing-prefix"&gt;Changing the install prefix&lt;/h3&gt;
&lt;p&gt;After a project is &lt;a href="#configuration" &gt;configured&lt;/a&gt; and the &lt;a href="#install-prefix" &gt;install prefix has been set&lt;/a&gt;, the developer may want to change the install prefix, for example to create a separate build directory to compare the results with certain code changes applied.&lt;/p&gt;
&lt;p&gt;There are two ways to do so:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;--prefix&lt;/code&gt; flag of the install step&lt;/li&gt;
&lt;li&gt;By rebuilding the build directory&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;code&gt;--prefix&lt;/code&gt; flag is used like so:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ --install-prefix ~/.local
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --install build/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Some time passes, now I want to install to somewhere else!&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --install build/ --prefix test-prefix&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Instead of the project being installed to &lt;code&gt;~/.local&lt;/code&gt;, it will be installed to &lt;code&gt;test-prefix&lt;/code&gt; in the current directory where the command is run.&lt;/p&gt;
&lt;p&gt;The flag effectively overrides the value of the install prefix and is convenient in many cases since it doesn't require rebuilding the project, but it won't work for projects that prepare their files using the install prefix during the configuration step.&lt;/p&gt;
&lt;p&gt;Be careful not to confuse the &lt;code&gt;--prefix&lt;/code&gt; flag of the install step with the &lt;code&gt;--install-prefix&lt;/code&gt; flag of the configuration step.&lt;/p&gt;
&lt;div class="d-flex align-items-center notecard notecard--warning" role="alert"&gt;
&lt;span&gt;
&lt;p class="h4 mt-0"&gt;When not to use --prefix&lt;/p&gt;&lt;details&gt;
&lt;summary&gt;Click here to read more&lt;/summary&gt;&lt;/br&gt;
&lt;p&gt;Using a practical example, if a project has an input file &lt;code&gt;org.kde.myapp.desktop.in&lt;/code&gt; with the following line:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-ini" data-lang="ini"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;Exec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;@CMAKE_INSTALL_PREFIX/bin/myapp@&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If the project is configured to point to &lt;code&gt;/usr&lt;/code&gt;, the file &lt;code&gt;org.kde.myapp.desktop&lt;/code&gt; will be seen in the build directory with the following line:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-ini" data-lang="ini"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="na"&gt;Exec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;/usr/bin/myapp&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Because this is done during the configuration step, even if you use the &lt;code&gt;--prefix&lt;/code&gt; flag to set the install prefix to &lt;code&gt;~/.local&lt;/code&gt; during the installation step, the installed &lt;code&gt;org.kde.myapp.desktop&lt;/code&gt; file will point to &lt;code&gt;/usr/bin/myapp&lt;/code&gt; instead of &lt;code&gt;/home/youruser/.local/bin/myapp&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In some cases this may not matter for the developer, but it is worth keeping this in mind.&lt;/p&gt;
&lt;p&gt;Another specific edge case that can bite QML app developers is when the install prefix is never manually set (with either the flag or configuration option) but the &lt;code&gt;--prefix&lt;/code&gt; flag is used. See &lt;a href="https://invent.kde.org/documentation/develop-kde-org/-/issues/195" &gt;Limitations of using --prefix&lt;/a&gt; for details.&lt;/p&gt;
&lt;/details&gt;
&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;The second method is guaranteed to always work in all cases, but also requires emptying the build directory and rebuilding the project from scratch, which might not be desirable if a project has long compile times.&lt;/p&gt;
&lt;p&gt;Traditionally this is done by deleting the build directory manually and then recreating it:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;rm -rf build
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build --install-prefix &lt;span class="nv"&gt;$PWD&lt;/span&gt;/test-prefix&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;But since CMake 3.24, it is now possible to empty and reconfigure a project in one go using the &lt;code&gt;--fresh&lt;/code&gt; flag:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build --install-prefix &lt;span class="nv"&gt;$PWD&lt;/span&gt;/test-prefix --fresh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="multi-config"&gt;Multi-configuration builds&lt;/h2&gt;
&lt;p&gt;Most of the time you will likely want to have only one build directory for simplicity, in which case CMake defaults to a “Debug” configuration with all debug symbols available for the developer.&lt;/p&gt;
&lt;p&gt;There are however &lt;a href="https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#build-configurations" &gt;multiple configurations&lt;/a&gt; you can use to compile your project:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Debug&lt;/li&gt;
&lt;li&gt;RelWithDebInfo (it stands for “release with debug information”)&lt;/li&gt;
&lt;li&gt;Release&lt;/li&gt;
&lt;li&gt;MinSizeRel (it stands for “minimum size release”)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;They provide &lt;a href="https://stackoverflow.com/questions/48754619/what-are-cmake-build-type-debug-release-relwithdebinfo-and-minsizerel" &gt;varying levels of compiler optimizations&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Debug takes the longest to compile but provides all debug symbols for developers to debug crashes in their software&lt;/li&gt;
&lt;li&gt;Release takes the least time to compile but provides no debug symbols for debugging&lt;/li&gt;
&lt;li&gt;RelWithDebInfo is a mid-term between Debug and Release&lt;/li&gt;
&lt;li&gt;MinSizeRel is simply Release optimized for size rather than speed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Depending on what you are attempting to do when building the software, you may prefer one configuration over another. For example, if you are certain you are not going to deal with crashes or you’d like to test software the way it will be delivered to users, you might want to use Release; if you want to improve build times while still keeping most debug symbols available, you might want to use RelWithDebInfo.&lt;/p&gt;
&lt;p&gt;To choose a specific configuration, use the &lt;code&gt;--config&lt;/code&gt; flag during &lt;strong&gt;both&lt;/strong&gt; the build and install steps:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --parallel --config RelWithDebInfo
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --install build/ --config RelWithDebInfo&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The main advantage of using multi-configuration builds is that you can have multiple build directories each with a different configuration. A similar thing is often done by IDEs under the hood.&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build-rel/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build-rel/ --parallel --config Release
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --install build-rel/ --config Release
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build-debug/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build-debug/ --parallel --config Debug
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --install build-debug/ --config Debug&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It can be a bit impractical when doing manual compilation yourself. CMake provides a simpler way to doing multi-configuration with a single build directory, but you will need to specify a multi-configuration capable &lt;a href="#generators" &gt;generator&lt;/a&gt; (on Linux there is Ninja, on Windows there is Visual Studio):&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ -G &lt;span class="s2"&gt;&amp;#34;Ninja Multi-Config&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --parallel --config Release
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --parallel --config Debug
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --install build/ --config Release
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --install build/ --config Debug&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="targets"&gt;Building CMake targets&lt;/h2&gt;
&lt;p&gt;CMake has the concept of targets, usually executables or libraries that have their own properties, source files, and dependencies.&lt;/p&gt;
&lt;p&gt;Whenever the project’s &lt;code&gt;CMakeLists.txt&lt;/code&gt; files have a call to &lt;a href="https://cmake.org/cmake/help/latest/command/add_executable.html" &gt;add_executable()&lt;/a&gt;, &lt;a href="https://cmake.org/cmake/help/latest/command/add_library.html" &gt;add_library()&lt;/a&gt; or &lt;a href="https://cmake.org/cmake/help/latest/command/add_custom_target.html" &gt;add_custom_target()&lt;/a&gt;, a CMake target is created. The name of the target is always the first word of such calls: a call to &lt;code&gt;add_executable(projectbin)&lt;/code&gt; creates an executable target called &lt;code&gt;projectbin&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Well-structured desktop applications will usually have a single executable target, and multiple dependent smaller library targets that are linked to it. For example, a library target for settings, a target for models, a target for dialogs, having all these linked as dependencies to the main executable.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;project-bin
&lt;ul&gt;
&lt;li&gt;project-settings&lt;/li&gt;
&lt;li&gt;project-models&lt;/li&gt;
&lt;li&gt;project-dialogs&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Using that target name, it is possible to build only a specific target (and its dependencies) using CMake. To build only the &lt;code&gt;project-settings&lt;/code&gt; library, you can run the following:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --target project-settings&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This both speeds build times dramatically and restricts the scope of warnings and errors to only the source code files used by the target. It is a good way to ensure a set of source files builds properly by itself.&lt;/p&gt;
&lt;p&gt;Remember to build the whole project by the end to make sure the new changes don’t break anything!&lt;/p&gt;
&lt;p&gt;There are custom targets provided both by CMake and by KDE’s extra-cmake-modules (ECM):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;CMake’s &lt;a href="https://cmake.org/cmake/help/book/mastering-cmake/chapter/Testing%20With%20CMake%20and%20CTest.html" &gt;add_test()&lt;/a&gt; provides the &lt;code&gt;test&lt;/code&gt; target&lt;/li&gt;
&lt;li&gt;ECM’s &lt;a href="https://api.kde.org/ecm/module/ECMAddTests.html" &gt;ecm_add_tests()&lt;/a&gt; provides a new target for each C++ test file based on the filename without the file extension (.cpp)&lt;/li&gt;
&lt;li&gt;ECM’s &lt;a href="https://api.kde.org/ecm/kde-module/KDECMakeSettings.html" &gt;KDECMakeSettings&lt;/a&gt; module provides the &lt;code&gt;uninstall&lt;/code&gt; target&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are building a project locally on Linux and later would like to uninstall a project, you can do the following:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ --install-prefix ~/.local
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --parallel
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --install build/
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Later, when you no longer need the program installed&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --target uninstall&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="tests"&gt;Running test targets&lt;/h3&gt;
&lt;p&gt;As mentioned in &lt;a href="#targets" &gt;Running CMake targets&lt;/a&gt;, CMake provides an additional &lt;code&gt;test&lt;/code&gt; target by default and ECM provides one target per test source file.&lt;/p&gt;
&lt;p&gt;To run all tests for a KDE project, you can do the following:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ -D &lt;span class="nv"&gt;BUILD_TESTING&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ON
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --target test&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To run only a specific test, you can do the following:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build -D &lt;span class="nv"&gt;BUILD_TESTING&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ON
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Inspecting the CMakeLists.txt in the project&amp;#39;s tests directory,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# ecm_add_test() shows a file &amp;#34;settings-test.cpp&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake --build build/ --target settings-test&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Running test targets directly with &lt;code&gt;cmake&lt;/code&gt; can be inconvenient both because the command is very verbose and because no additional options can be passed to modify how the test should behave.&lt;/p&gt;
&lt;p&gt;Instead, you can use &lt;code&gt;ctest&lt;/code&gt; to run tests. CTest is what is actually run under the hood when you call a test target with &lt;code&gt;cmake&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;To execute all tests, run the following after configuring the project:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;cmake -B build/ -D &lt;span class="nv"&gt;BUILD_TESTING&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ON
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ctest --test-dir build/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To execute only one test, run the following:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Only run tests that have &amp;#34;app&amp;#34; in the name&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ctest --test-dir build/ -R app&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The short flag &lt;code&gt;-R&lt;/code&gt; (or long flag &lt;code&gt;--tests-regex&lt;/code&gt;) allows for any regex expression, unlike CMake's &lt;code&gt;--target&lt;/code&gt; which only accepts matching names. It opposite flag &lt;code&gt;-E&lt;/code&gt; or &lt;code&gt;--exclude-regex&lt;/code&gt; allows to only run tests not matching the regex expression:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;# Only run tests that do not have &amp;#34;window&amp;#34; in the name&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ctest --test-dir build/ -E window&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;A few common additional options you can pass to &lt;code&gt;ctest&lt;/code&gt; but cannot to &lt;code&gt;cmake&lt;/code&gt; include:&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;--verbose&lt;/code&gt;, &lt;code&gt;--extra-verbose&lt;/code&gt; and &lt;code&gt;--debug&lt;/code&gt; flags to see more details about the test or which commands are run under the hood:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ctest --test-dir build/ --verbose
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ctest --test-dir build/ --debug&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The flag &lt;code&gt;--rerun-failed&lt;/code&gt; to run only failed tests and the flag &lt;code&gt;--stop-on-failure&lt;/code&gt; to make CTest stop once a single test fails:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ctest --test-dir build/ --rerun-failed
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ctest --test-dir build/ --stop-on-failure&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The flag &lt;code&gt;--output-log&lt;/code&gt; to save the test results to a file:&lt;/p&gt;
&lt;div class="highlight"&gt;
&lt;pre tabindex="0" class="chroma" style="margin-top: 0;
padding-top: 0.4em;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;ctest --test-dir build/ --output-log test1.txt&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item></channel></rss>