Can CMake scripts run with -P return exit code other than zero?

I use CMake scripting to accomplish various build tasks - the sort of things I’d use a shell script for in Unix.

The problem is that sometimes running the script has an error, but as far as I can tell – and I’ve searched the web & CMake documentation – cmake running a script with -P always returns an exit code of zero.

This means that as far as the build program knows, that build step succeeded when in fact it died horribly.

Is there a way to get cmake to return an error when it’s running a -P script?

Using message(FATAL_ERROR "...") makes CMake return exit code 1. That also works with SEND_ERROR.