CMake quality linting
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 and unused CLI options.
Uninitialized variables
Uninitialized variables can be less troublesome in CMake than other languages, but it’s better to be explicit by setting a new variable. Check for CMake uninitialized variables:
cmake -Wuninitialized -B buildor
cmake -Werror=uninitialized -B buildThis 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 "")Unused CLI options
CMake can also warn about unused command-line options, which can help catch typos or misconfigurations:
cmake -Wunused-cli -B buildor to treat them as errors:
cmake -Werror=unused-cli -B build