...

/

Basic Directives and Commands

Basic Directives and Commands

Let's learn about version, list of languages, and metadata in CMake.

A project is a directory with a CMakeLists.txt file that contains a few commands that configure the language processor:

Press + to interact
cmake_minimum_required(VERSION 3.25.1)
project(Hello)
add_executable(Hello hello.cpp)

Let’s review some relevant CMake commands.

Specifying the minimum CMake version – cmake_minimum_required()

This isn't strictly a project-specific command, as it should be used with scripts as well, but it is so important that we repeat it here. As you know, cmake_minimum_required() checks whether the system has the right CMake version, but implicitly, it also calls another command, cmake_policy(VERSION), which will tell CMake what the right policies are to use for this project.

What are these policies?

Over the last 20 years of CMake's development, there have been many changes to how commands behave as CMake and the languages it supports have evolved. To keep the syntax clean and simple, CMake's team decided to introduce policies to reflect these changes. Whenever a backward-incompatible change was introduced, it came with a policy that enabled the new behavior. ... ...