Useful Commands

Let's review the most beneficial beginner commands in CMake.

CMake offers many, many scripting commands that allow us to work with variables and the environment. Some of them are covered extensively in the "Appendix" section, for example, list(), string(), and file(). Others, such as find_...(), fit better in chapters that talk about managing dependencies. In this section, we'll briefly cover the most useful commands for scripts.

The message() command

We already know and love our trusty message() command, which prints text to standard output. However, there's a lot more to it than meets the eye. By providing a MODE argument, we can customize the style of the output, and in the case of an error, we can stop the execution of the code: message(<MODE> "text").

The recognized modes are as follows:

Get hands-on with 1400+ tech skills courses.