How is target name propogated to external projects?

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.

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 is implemented (probably more possible after a rework of the Unix Makefiles generator).