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:
-
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_DEPRECATED
orCMAKE_WARN_DEPRECATED
variables are enabled.NOTICE
or omitted mode (default): This prints a message tostderr
to attract the user's attention.STATUS
: This continues processing and is recommended for main messages for users.VERBOSE
...