[CMake] custom target not working on windows

David Cole david.cole at kitware.com
Fri Jul 31 11:14:39 EDT 2009


On Fri, Jul 31, 2009 at 11:01 AM, Tyler Roscoe <tyler at cryptio.net> wrote:

> On Fri, Jul 31, 2009 at 08:42:10AM -0400, Marc Schafer wrote:
> > add_custom_target ( generated_messages ALL
> >   COMMAND
> >   ${ANT_EXECUTABLE} -f
> ${PROJECT_SOURCE_DIR}/java/MessageGenerator/build.xml
> > run
> >   COMMAND
> >   ${CMAKE_COMMAND} -E copy_if_different ${DICTIONARY_DIR}/c/messages.h
> > ${PROJECT_BINARY_DIR}/include/messages.h
> > )
> >
> > This works fine on Linux and Mac with the make generator but does not
> work
> > on Windows XP with the Visual studio 2008 generator.  From the build log
> > file, I can see that a batch file is getting generated with two commands:
> > one to run ant and the other to do the copy.  When the batch file is run,
> > the ant command works fine, but the copy never seems to happen.  My
> library
> > fails to build because it can't find messages.h even though it does exist
> in
> > ${DICTIONARY_DIR}/c/messages.h
>
> I have run into this. Here's a note from our (internal) wiki:
>
> "If invoking a DOS batch file you must precede the command with the call
> keyword. Also, it must not have quotes surrounding the call and the
> command."
>
> Your ant "executable" is probably a batch file. For reasons I don't
> remember, VS gets confused and likes to exit immediately after running a
> batch file as a custom build step.



This is not a VS specific problem, but rather how Windows batch files behave
in general.

If an executable or batch file returns an error exit status, but the "call"
keyword is not used in the calling batch file, then the calling batch file
exits without executing the remainder of the script. Using the call keyword
prevents that behavior and makes it work like you'd expect.


HTH,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090731/24b8c44e/attachment-0001.htm>


More information about the CMake mailing list