[Cmake] Custom Command Reworked

Ken Martin ken . martin at kitware . com
Tue, 3 Jun 2003 10:55:16 -0400


I just checked in my updates to ADD_CUSTOM_COMMAND. Basically many of us
were unhappy with ADD_CUSTOM_COMMAND because it was confusing to use
etc. Based on a number of use cases we came up with a new syntax that is
better. I have tried to maintain the old functionality as well but the
changes were significant so let me know if you run into problems. I have
added a new test to cmake called CustomCommand that demonstrates a few
common examples of using a custom command. Also FYI, I tried writing the
VTK_WRAP_TCL command as a CMake macro and it worked, so the new syntax
seems pretty solid. I have included the new docs below. Currently there
is one limitation. In Visual Studio 6, PRE_BUILD and PRE_LINK rules are
treated both as PRE_LINK (a limitation of VS6 I believe) The same
limitation applies to Makefiles although I think that can be fixed.

Thanks
Ken

Ken Martin, PhD
Kitware Inc.
518 371 3971 x101
469 Clifton Corporate Pkwy
Clifton Park NY 12065



ADD_CUSTOM_COMMAND
     Add a custom build rule to the generated build system.

     There are two main signatures for ADD_CUSTOM_COMMAND The first
     signature is for adding a custom command to produce an output.

       ADD_CUSTOM_COMMAND(OUTPUT result
                          COMMAND command
                          [ARGS [args...]]
                          [MAIN_DEPENDENCY depend]
                          [DEPENDS [depends...]]
                          [COMMENT comment])

     This defines a new command that can be executed during the build
     process.  Note that MAIN_DEPENDENCY is completely optional and is
used
     as a suggestion to visual studio about where to hang the custom
     command In makefile terms this creates a new target in the
following
     form:

       OUTPUT: MAIN_DEPENDENCY DEPENDS
               COMMAND ARGS



     The second signature adds a custom command to a target such as a
     library or executable.  This is useful for performing an operation
     before or after building the target

       ADD_CUSTOM_COMMAND(TARGET target
                          PRE_BUILD | PRE_LINK | POST_BUILD
                          COMMAND command
                          [ARGS [args...]]
                          [COMMENT comment])

     This defines a new command that will be associated with building
the
     specified target.  When the command will happen is determined by
     whether you specify

     PRE_BUILD - run before all other dependencies
     PRE_LINK - run after other dependencies
     POST_BUILD - run after the target has been built