CMake quality linting

CMake’s scripting language has some legacy characteristics as do other 1990s code languages. Editors such as Visual Studio Code have add-on CMake linting capabilities via CMake Tools. Deeper introspection is available via the CMake command-line options for uninitialized variables.

Uninitialized variables

Uninitialized variables can be less troublesome in CMake than other languages, but it’s almost always better to be explicit by setting a new variable. Check for CMake uninitialized variables by:

cmake --warn-uninitialized -B build

This warning option can have false positives, or at least what the developer might consider false positives. Often the warning can be stifled by doing like:

set(myopt)

or

set(myopt "")

Deprecated

The --warn-unused-var option did not work properly since CMake 3.2 and has been removed from CMake.