Useful Commands
Let's review the most beneficial beginner commands in CMake.
We'll cover the following...
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:
-
FATAL_ERROR: This stops processing and generation. -
SEND_ERROR: This continues processing, but skips generation. -
WARNING: This continues processing. -
AUTHOR_WARNING: A CMake warning. This continues processing.
DEPRECATION: This works accordingly if either of theCMAKE_ERROR_DEPRECATEDorCMAKE_WARN_DEPRECATEDvariables are enabled.NOTICEor omitted mode (default): This prints a message tostderrto attract the user's attention.STATUS: This continues processing and is recommended for main messages for users.VERBOSE: This continues processing and should be used for more detailed information that usually isn't very necessary. ...