[CMake] add_custom_command depends on output from add_custom_target
Michael Hertling
mhertling at online.de
Mon Nov 1 20:28:08 EDT 2010
On 11/01/2010 10:47 PM, SK wrote:
> I know add_custom_target does not produce output as far as CMake is
> concerned. My situation is as follows:
>
> A traditional make process that I cannot modify produces a target on
> which I must do some post-processing.
>
> I use add_custom_target to force the makefile to always run. I use
> add_custom_command for my post-processing steps.
>
> How do I setup a dependency for the post-processing steps? I don't
> want to run these steps unless the external make actually updated its
> target.
Possibly, you can use ADD_CUSTOM_COMMAND(TARGET ... POST_BUILD ...):
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(POSTPROCESSING NONE)
ADD_CUSTOM_TARGET(t ALL
${CMAKE_COMMAND} -E echo "Building target t"
VERBATIM)
ADD_CUSTOM_COMMAND(TARGET t POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Post-processing target t"
VERBATIM)
So, the custom command always runs after the custom target's one.
> The add_custom_command cannot use the name of the add_custom_target as
> a DEPENDS. I tried this and it assumes that the add_custom_target name
> is just a file and cannot find it.
IMO, this is strange. Indeed, the following doesn't work:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(CUSTOMDEPENDS NONE)
ADD_CUSTOM_TARGET(t
${CMAKE_COMMAND} -E echo "Building target t"
VERBATIM)
ADD_CUSTOM_COMMAND(OUTPUT stamp
COMMAND ${CMAKE_COMMAND} -E touch stamp
DEPENDS t
VERBATIM)
ADD_CUSTOM_TARGET(main ALL
${CMAKE_COMMAND} -E echo "Building target main"
DEPENDS stamp
VERBATIM)
When running make, it correctly builds target t, but subsequently, it
bails out saying "No rule to make target `t', needed by `stamp'." From
the documentation of ADD_CUSTOM_COMMAND(), it's not clear why there is
a restriction of that kind w.r.t. custom targets. Perhaps, someone can
give us a hint if this is intended behaviour or should be considered as
erroneous.
Regards,
Michael
More information about the CMake
mailing list