# Depending upon a POST\_BUILD of an ExternalProject

**URL:** https://discourse.cmake.org/t/depending-upon-a-post-build-of-an-externalproject/8507
**Category:** Code
**Tags:** gen:ninja
**Created:** [July 13, 2023, 9:51am UTC](https://discourse.cmake.org/t/depending-upon-a-post-build-of-an-externalproject/8507 "2023-07-13T09:51:41Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jmqwerk](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/a5b964/32.png) [@jmqwerk](https://discourse.cmake.org/u/jmqwerk)
#### Post date: [July 13, 2023, 9:51am UTC](https://discourse.cmake.org/t/depending-upon-a-post-build-of-an-externalproject/8507/1 "2023-07-13T09:51:41Z")

</div>

Having an issue… I add an external project which is a cmake project which creates an output, then as post build creates additional files, from the main project it then adds targets that depend on these post build files, this seems to work when manually running this as a one-off but is prone to a timing/load issue whereby it can fail because the post build in the external project can run after the project itself has finished. I have browsed the documentation and cannot see any way of linking to the POST\_BUILD of an external project, or the generated files, using the DEPENDS argument on a add\_custom\_target() call - is there any way to do that, perhaps something I’ve missed or overlooked?

---

<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: [July 18, 2023, 12:01am UTC](https://discourse.cmake.org/t/depending-upon-a-post-build-of-an-externalproject/8507/2 "2023-07-18T00:01:52Z")

</div>

Not really AFAIK. `ExternalProject` works best when everything in the project is also an `ExternalProject`. For mixing other project builds into your own, `FetchContent` may be a better way to go.

Cc: @craig.scott

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [July 18, 2023, 12:36am UTC](https://discourse.cmake.org/t/depending-upon-a-post-build-of-an-externalproject/8507/3 "2023-07-18T00:36:03Z")

</div>

How/where are you adding the `POST_BUILD` commands? I suspect you’re adding those in a way that isn’t supported, but without seeing the details, I can’t comment further.

---

<div class="post-metadata">

### Author: ![jmqwerk](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/a5b964/32.png) [@jmqwerk](https://discourse.cmake.org/u/jmqwerk)
#### Post date: [July 20, 2023, 6:36am UTC](https://discourse.cmake.org/t/depending-upon-a-post-build-of-an-externalproject/8507/4 "2023-07-20T06:36:55Z")

</div>

`POST_BUILD` is being added by the underlying code here: [https://github.com/zephyrproject-rtos/zephyr/blob/main/CMakeLists.txt#L1888](https://github.com/zephyrproject-rtos/zephyr/blob/main/CMakeLists.txt#L1888)  
This is added from the other project by using ExternalProject\_Add here: [https://github.com/zephyrproject-rtos/zephyr/blob/main/share/sysbuild/cmake/modules/sysbuild\_extensions.cmake#L241](https://github.com/zephyrproject-rtos/zephyr/blob/main/share/sysbuild/cmake/modules/sysbuild_extensions.cmake#L241)  
Can `FetchContent` be used without external e.g. web content? The files generated in this case are conversions of elf to hex, bin, etc.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [March 23, 2024, 7:23am UTC](https://discourse.cmake.org/t/depending-upon-a-post-build-of-an-externalproject/8507/5 "2024-03-23T07:23:13Z")

</div>

@jmqwerk Both of the links in your last comment are no longer pointing at the same lines. If you’re still interested in this discussion, could you please update that comment to point the links at specific tags or commits? If you can’t edit that comment, please add a new one with the updated details instead.

---

<div class="post-metadata">

### Author: ![jmqwerk](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/a5b964/32.png) [@jmqwerk](https://discourse.cmake.org/u/jmqwerk)
#### Post date: [March 25, 2024, 7:14am UTC](https://discourse.cmake.org/t/depending-upon-a-post-build-of-an-externalproject/8507/6 "2024-03-25T07:14:53Z")

</div>

Issue was worked around in a different way
