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

**URL:** https://discourse.cmake.org/t/can-cmake-scripts-run-with-p-return-exit-code-other-than-zero/4964
**Category:** Usage
**Created:** [February 3, 2022, 9:05pm UTC](https://discourse.cmake.org/t/can-cmake-scripts-run-with-p-return-exit-code-other-than-zero/4964 "2022-02-03T21:05:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![KentWilliams](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/c4cdca/32.png) [@KentWilliams](https://discourse.cmake.org/u/KentWilliams)
#### Post date: [February 3, 2022, 9:05pm UTC](https://discourse.cmake.org/t/can-cmake-scripts-run-with-p-return-exit-code-other-than-zero/4964/1 "2022-02-03T21:05:06Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [February 3, 2022, 9:08pm UTC](https://discourse.cmake.org/t/can-cmake-scripts-run-with-p-return-exit-code-other-than-zero/4964/2 "2022-02-03T21:08:40Z")

</div>

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