Basic directives and commands
In Chapter 1, First Steps with CMake, we already looked at a simple project definition. Let's revisit it. It is a directory with a CMakeLists.txt
file that contains a few commands configuring the language processor:
chapter01/01-hello/CMakeLists.txt: Hello world in CMake language
cmake_minimum_required(VERSION 3.20) project(Hello) add_executable(Hello hello.cpp)
In the same chapter, in the Project files section, we learned about a few basic commands. Let's explain them in depth.
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()
will check whether the system has the right CMake version, but implicitly, it will also call another command, cmake_policy(VERSION)
, which will tell CMake what the right policies are to use for this project...