[CMake] Can I run a command every time a given target is created?

Paul Smith paul at mad-scientist.net
Wed Oct 23 15:41:35 EDT 2013


I need to be able to run a command after a target is created, every time
the target is created.  I need this to happen regardless of the command
line.

For example, for Makefile generators if someone runs "make myTarget"
directly (if myTarget is a program for example) I still need this
command to be run; similarly for MSVC requesting a particular build
target.

I have my cmake files set up now to use a target created with
add_custom_command() / add_custom_target() with ALL DEPENDS so that if
someone runs plain "make" or the default MSVC target, then the command
will always be run afterward.  But this doesn't help me when people
build these specific targets.


For example, is it possible to modify the standard build target rule to
add extra commands, in cmake?



More information about the CMake mailing list