How to CMake Good - 2c - Functions, Scopes, Arguments, and List Expansion
Channel: vector-of-bool
Date: 02/09/2018

This video is a bit longer than usual, but it covers a lot of important topics for CMake scripting. The scripting language can be confusing for those unfamiliar with just how simplistic it really is.

The video covers several topics, so here's some timestamps for each part:

00:12 - Arguments to commands are just a sequence of strings. Always. There is no other syntax. No keywords. No magic.
02:41 - Argument list expansion is essential to understand. This is where quoted vs unquoted variable references become important. It won't bite you if you know when to expect it. It can be your friend.
05:54 - Defining your own functions. It's not hard, and you can make powerful functionality using CMake scripts on their own! Functions are key. Know the difference between ARGN and ARGV.
09:14 - Variable scopes. This can trip people up when they aren't expecting it. Functions receive their own variable scope. include() and macro() do not. Know this, and how to manipulate your parent scope to return values to them.
11:51 - CMake output parameters and "indirection" through variable name arguments. Essential for any CMake scripting magic. Builds upon knowledge of scopes.

I purposefully omitted discussion of macro(). It's a very sharp tool that must be used with care, and is rarely needed. You can almost always get away with function() instead. Prefer it.

I've been told to increase the font size on my screen, so I've inflated VSCode to pretty large proportions. Tell me how it looks in the comments!

No errata for this one. It's a masterpiece, truly.

Documentation about set(), discussing PARENT_SCOPE: https://cmake.org/cmake/help/latest/command/set.html

Documentation about unquoted arguments (covering list expansion): https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#unquoted-argument

Documentation on variables and scopes: https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#variables

This video has no quip in its description - The Sign Painter