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

Brad King brad.king at kitware.com
Fri Dec 9 08:28:18 EST 2016


On 12/09/2016 08:18 AM, Dan Liew wrote:
> CMake has special commands for doing `install` so I'd expect something
> analogous for managing how `clean is performed`.

CMake has full control over the generation of the install rules.
For "clean" this is only true for the Makefile generator.

>> think something like `ADDITIONAL_MAKE_CLEAN_COMMAND` or perhaps
>> `ADDITIONAL_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?

No, because ninja has its own model for a "clean" operation.

Getting custom "clean" behavior in general would require adding
a custom target that looks like a normal target to build systems
but inside is full of commands to clean.  For this I don't think
any special support is needed from CMake:

add_custom_target(myclean
  COMMAND ${whatever_command_user_wants}
  COMMAND ${CMAKE_COMMAND} --build . --target clean --config $<CONFIG>
  )

-Brad



More information about the CMake mailing list