[Cmake] ADD_CUSTOM_COMMAND problems

Brad King brad . king at kitware . com
Fri, 10 Oct 2003 18:07:00 -0400 (EDT)


Hi Kevin,

I'll assume you're using cmake 1.8.  Major improvements were made to
custom commands from 1.6 to 1.8.

On Fri, 10 Oct 2003, Kevin Wright wrote:
> I'm having some trouble getting ADD_CUSTOM_COMMAND to work in one part
> of my setup.  I have one section of the code where I create a
> pre-processing command which works perfectly:
>
>   ADD_CUSTOM_COMMAND(OUTPUT ${MocFile} COMMAND ${MOC_EXE}
> 	ARGS ${Header} -o ${MocFile} DEPENDS ${Header} COMMENT moc_${BaseName}.cxx)

This looks fine.  The rule is added to any project file that uses the
generated ${MocFile} source.

> Then, a few lines later, I use another ADD_CUSTOM_COMMAND to copy a dll
> into my project like so:
>
>     ADD_CUSTOM_COMMAND(OUTPUT ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/${BaseName}
> 	COMMAND ${CANMET_BINARY_DIR}/copy.exe
>  	ARGS ${DLL} ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}
>  	DEPENDS ${DLL}
> 	COMMENT ${BaseName}
>  	)
>
> (where copy.exe is just an executable that copies without complaining
> about forward slashes on windows)

You might want to look at the "cmake -E copy" option for this.  It is
provided for exactly this reason.  Run "cmake -E" for details.

> This does not even show up in the VC++ list of targets.  I've tried
> using ADD_DEPENDENCIES to tie it to the main executable building, but
> that doesn't seem to help.

ADD_DEPENDENCIES can only add dependencies among targets listed in the
main .dsw or .sln file.

> Am I making a stupid mistake?  Do I fundamentally misunderstand
> something about this?  Any help would be great.

There are no executables or libraries in your project that need the rule
to execute for the build to complete.  There is no way for cmake to tell
Visual Studio about the rule because no project file needs it.

You are looking for the ADD_CUSTOM_TARGET command.  Run

  cmake --help ADD_CUSTOM_TARGET

for help using the command.  It will create a target not associated with
an executable or library that can be used to drive the custom command you
wrote above.

-Brad