[CMake] creating custom make targets

Brad King brad.king at kitware.com
Thu Feb 19 12:09:12 EST 2009


Aaron Turner wrote:
> Whoops, my bad.  Typed "add_custom_target" not "add_custom_command".
> 
> Thanks everyone, this makes sense now.

To answer the original question, the best way to generate a bunch of things
only when the users asks is to use add_custom_command to create the rules
and then associate them with a top-level target using add_custom_target:

   add_custom_command(
     OUTPUT myfile.txt
     COMMAND ... # command to generate myfile.txt here
     DEPENDS ... # file-level depends here
     )

   add_custom_target(test_standard DEPENDS myfile.txt)

When add_custom_target is not given the ALL option, it will not build unless
the user explicitly requests it with "make test_standard".  Then the custom
commands it drives will still have normal dependencies to only rebuild when
necessary.

-Brad


More information about the CMake mailing list