# add\_custom\_target needs intermediate target

**URL:** https://discourse.cmake.org/t/add-custom-target-needs-intermediate-target/8397
**Category:** Usage
**Created:** [June 23, 2023, 12:09pm UTC](https://discourse.cmake.org/t/add-custom-target-needs-intermediate-target/8397 "2023-06-23T12:09:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [June 23, 2023, 12:09pm UTC](https://discourse.cmake.org/t/add-custom-target-needs-intermediate-target/8397/1 "2023-06-23T12:09:22Z")

</div>

This works:

```auto
add_custom_target(foo COMMAND crunsh)
add_dependencies(foo bar)
add_custom_target(top)
add_dependencies(top foo)

```

This does not:

```auto
add_custom_target(top COMMAND crunsh)
add_dependencies(top bar)

```

With the latter, command `make top` will immediately execute `crunsh` without waiting for `bar` to be finished.

Why?

Are there alternatives to the stammering four-line solution?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [June 25, 2023, 8:14pm UTC](https://discourse.cmake.org/t/add-custom-target-needs-intermediate-target/8397/2 "2023-06-25T20:14:26Z")

</div>

Can you please provide a full example?
