[Cmake] ADD_CUSTOM_COMMAND and PRE_BUILD

Brad King brad.king at kitware.com
Mon, 19 Apr 2004 09:53:44 -0400


Benjamin Rutt wrote:
> I'm using cmake 1.8.3.  I read that ADD_CUSTOM_COMMAND can be used in
> the following way, quoted from 'cmake --help ADD_CUSTOM_COMMAND':
> 
>        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 which
>        of the following is specified:
> 
>          PRE_BUILD - run before all other dependencies
>          PRE_LINK - run after other dependencies
>          POST_BUILD - run after the target has been built
> 
> So I'd like to use the PRE_BUILD to get my custom command to run
> before any of the dependencies for the named target are built.
> Here's my sample project:
> 
>     ::::::::::::::
>     CMakeLists.txt
>     ::::::::::::::
>     PROJECT(dummyproj)
> 
>     ADD_LIBRARY(dummylib SHARED foo.cpp)
> 
>     ADD_CUSTOM_COMMAND(
>       TARGET dummylib
>       PRE_BUILD
>       COMMAND cp
>       ARGS -v /etc/hosts ${dummyproj_BINARY_DIR})
> 
>     ::::::::::::::
>     foo.cpp
>     ::::::::::::::
>     class Foo
>     {
>         int a;
>         int b;
>     };
> 
> So I'd like the 'cp' command to execute before any dependencies of
> dummylib are built.  Yet the output shows that the 'cp' command is
> happening after foo.o and libdummylib.so are built.  I'd like the 'cp'
> command to happen before both of them are built.  What am I doing
> wrong?
> 
>     $ cmake ../dummyproj 
>     -- Check for working C compiler: gcc
>     -- Check for working C compiler: gcc -- works
>     -- Check for working CXX compiler: g++
>     -- Check for working CXX compiler: g++ -- works
>     -- Configuring done
>     -- Generating done
>     $ make
>     Building dependencies. cmake.depends...
>     cmake.depends is up-to-date
>     Building object file foo.o...
>     Building shared library libdummylib.so...
>     `/etc/hosts' -> `/home/rutt/dev/dummyproj/build/hosts'

Please send me the Makefile that is generated before the build occurs.

Thanks,
-Brad