# How is target name propogated to external projects?

**URL:** <https://discourse.cmake.org/t/how-is-target-name-propogated-to-external-projects/186>\
**Category:** Code\
**Created:** [November 12, 2019, 8:33am UTC](https://discourse.cmake.org/t/how-is-target-name-propogated-to-external-projects/186 "2019-11-12T08:33:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![oscarh](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/aca169/32.png) [@oscarh](https://discourse.cmake.org/u/oscarh)\
**Post date:** [November 12, 2019, 8:33am UTC](https://discourse.cmake.org/t/how-is-target-name-propogated-to-external-projects/186/1 "2019-11-12T08:33:14Z")

</div>

I don’t see a way to specify the target to build when calling ExternalProject\_Add (Correct me if I’ve missed it). So how does the external project know what target to build when I run “cmake --build” on the top-most project?

I found running the top-most “cmake --build . --target clean” does not clean artifacts (\*.o, binary built) of the external project. Is this expected?

I’m using cmake 3.16 RC3.

---

<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:** [November 12, 2019, 1:06pm UTC](https://discourse.cmake.org/t/how-is-target-name-propogated-to-external-projects/186/2 "2019-11-12T13:06:28Z")

</div>

It look like you’ll need to make your own `BUILD_COMMAND` to use a custom target. You can probably add a custom `clean` step (that depends on the configure step or knows how to handle the build files not existing), but you’ll have to wire _that_ up to some custom target; I don’t think there’s away to make the built-in clean target depend on a custom target right now.

That said, an issue to support a specific target in `BUILD_COMMAND` automatically would probably be useful. The `clean` stuff could be wired up once [https://gitlab.kitware.com/cmake/cmake/issues/8438](https://gitlab.kitware.com/cmake/cmake/issues/8438) is implemented (probably more possible after a rework of the Unix Makefiles generator).
