Search⌘ K
AI Features

Introduction

Explore the fundamentals of setting up a CMake project from initial configuration to generating a build system. Understand environment checks, project partitioning, and automation of builds and tests to improve development workflow and code quality.

We'll cover the following...

Building project

In CMake, a project contains all the source files and configurations necessary to manage the process of bringing our solutions to life. Configuration starts by performing all the checks:

  • Whether the target platform is supported.

  • Whether it has all the necessary dependencies and tools.

  • Whether the provided compiler works and supports required features.

When that's done, CMake will generate a buildsystem for the build tool of our choice and run it. Source files will be compiled and linked with each other and their dependencies to produce output artifacts.

Projects can be used internally by a group of developers to produce packages that users can install on their systems through package managers, or they can be used to provide single-executable installers. Projects can also be shared in an open-source repository so that users can use CMake to compile projects on their machines and install them directly.

Using CMake projects to their full potential will improve the developing experience and the quality of the produced code because we can automate many dull tasks, such as:

  • Running tests after the build

  • Checking code coverageCode coverage is a metric that can help us understand how much of our source is tested for a particular test suite and helps us to assess the quality of our test suite.

  • Formatting the code

  • Checking source code with lintersA tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs. and other tools a tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs.

Topics to cover

To unlock the power of CMake projects, we require to understand how to correctly configure the project as a whole and how to partition it and set up the source tree so that all files are neatly organized in the right directories.

We can then understand how to query the environment the project is built on—for example, what architecture is it? What tools are available? What features do they support? And what standard of the language is in use? Finally, we can compile a test C++ file to verify if the chosen compiler meets the standard requirements set in our project.

We're going to cover the following main topics:

  • Basic directives and commands

  • How to partition your project

  • Thinking about the project structure

  • Scoping the environment

  • Configuring the toolchain

  • Disabling in-source builds