[CMake] Adding dependencies to the `clean` target in 2016?

Dan Liew dan at su-root.co.uk
Fri Dec 9 08:18:11 EST 2016


On 5 December 2016 at 14:05, Brad King <brad.king at kitware.com> wrote:
> On 12/03/2016 06:52 AM, Dan Liew wrote:
>> There was a post about this 10 years ago [1], has anything changed since then?
>
> No.  From my response back then:
>
>>> The "clean" target is not a first class target available to
>>> CMakeLists.txt code....We do plan to make targets like install
>>> and clean first class eventually but it is not yet implemented.
>
> This never happened.  These generator-provided targets have very
> different semantics (e.g. per-directory behavior in the Makefile
> generator) and that makes it hard to define them in a way that is
> visible to client code during configuration.  It may be possible but
> will require deep design thought.

Thanks for the info. Giving developers control of the `clean` target
is something I'd like to see even if it does require quite a bit of
thought.
CMake has special commands for doing `install` so I'd expect something
analogous for managing how `clean is performed`.
These would be declared on a per directory basis and if the generator
worked a per directory basis then we would have
per directory clean targets otherwise there would just be a global clean target.

>> I realise the `clean` target won't be available for all generators but
>> for those that do, it would be really nice to able to do something
>> like this.
>>
>> add_dependencies(clean CleanKLEERuntimes)
>
> Just as `ADDITIONAL_MAKE_CLEAN_FILES` is a make-specific solution I
> think something like `ADDITIONAL_MAKE_CLEAN_COMMAND` or perhaps
> `ADDITIONAL_MAKE_CLEAN_TARGET` could be offered.  Such configuration
> could be interpreted by the makefile generator while generating the
> "make clean" target.

I suppose that would do the job. I do use Ninja as a generator a lot
too. Would Ninja support it too?

Dan.


More information about the CMake mailing list