# CMake update, then: Built-in flow control command "add\_custom\_target" cannot be overridden.

**URL:** <https://discourse.cmake.org/t/cmake-update-then-built-in-flow-control-command-add-custom-target-cannot-be-overridden/3576>\
**Category:** Code\
**Created:** [June 16, 2021, 12:16pm UTC](https://discourse.cmake.org/t/cmake-update-then-built-in-flow-control-command-add-custom-target-cannot-be-overridden/3576 "2021-06-16T12:16:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![KUGA2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kuga2/32/4968_2.png) [@KUGA2](https://discourse.cmake.org/u/KUGA2)\
**Post date:** [June 16, 2021, 12:16pm UTC](https://discourse.cmake.org/t/cmake-update-then-built-in-flow-control-command-add-custom-target-cannot-be-overridden/3576/1 "2021-06-16T12:16:21Z")

</div>

Today I updated from 3.10 to 3.20. Then I get a lot of errors:

```auto
Built-in flow control command "install" cannot be overridden.
Built-in flow control command "get_target_property" cannot be overridden.
Built-in flow control command "add_custom_target" cannot be overridden.

```

I am overwriting these to test my own CMake functions that call these functions. This way I can check if it is called with the expected parameters.

Why are they now considered flow control commands?  
How can I make CMake accept those overwrites? Or is there another way to do what I want?

PS: I could not find this change in Changelog or Policies page.

---

<div class="post-metadata">

**Author:** ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)\
**Post date:** [June 16, 2021, 12:41pm UTC](https://discourse.cmake.org/t/cmake-update-then-built-in-flow-control-command-add-custom-target-cannot-be-overridden/3576/2 "2021-06-16T12:41:34Z")

</div>

It kinda looks like unintended consequence of [https://gitlab.kitware.com/cmake/cmake/-/merge\_requests/5409](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5409)

---

<div class="post-metadata">

**Author:** ![KUGA2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kuga2/32/4968_2.png) [@KUGA2](https://discourse.cmake.org/u/KUGA2)\
**Post date:** [June 16, 2021, 12:54pm UTC](https://discourse.cmake.org/t/cmake-update-then-built-in-flow-control-command-add-custom-target-cannot-be-overridden/3576/3 "2021-06-16T12:54:42Z")

</div>

Guess we need @brad.king or @kyle.edwards to confirm this.

Note that I overwrite more then the mentioned ones:

```auto
function(add_custom_command)
endfunction()
function(add_dependencies)
endfunction()

```

This works, for example.

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [June 16, 2021, 2:04pm UTC](https://discourse.cmake.org/t/cmake-update-then-built-in-flow-control-command-add-custom-target-cannot-be-overridden/3576/4 "2021-06-16T14:04:59Z")

</div>

Indeed, this was not supposed to happen. It was only supposed to protect a handful of commands, namely:

- `break`
- `continue`
- `foreach`
- `function`
- `if`
- `macro`
- `return`
- `while`

I will take a look.

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [June 16, 2021, 2:44pm UTC](https://discourse.cmake.org/t/cmake-update-then-built-in-flow-control-command-add-custom-target-cannot-be-overridden/3576/5 "2021-06-16T14:44:19Z")

</div>

I’ve opened [https://gitlab.kitware.com/cmake/cmake/-/merge\_requests/6232](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6232) to deal with this. You will once again be able to override `add_custom_target` and other project commands.

Note that you still won’t be able to override `function`, `if`, etc.
