[Cmake] ADD_CUSTOM_COMMAND etc

Andy Cedilnik andy.cedilnik at kitware.com
Tue Apr 15 07:47:56 EDT 2003


Hi Neil,

On Tue, 2003-04-15 at 00:33, Neil Killeen wrote:
> 1)  From your example
> 
> 
> >
> > PROJECT(Test)
> >
> > SET (LATEX_COMPILE latex)
> >
> > SET(DOC_ROOT ${Test_SOURCE_DIR}/Documentation)
> >
> > ADD_CUSTOM_TARGET (LaTeXDocument ALL)
> > ADD_CUSTOM_COMMAND(
> >     SOURCE    ${DOC_ROOT}/junk.tex
> >     COMMAND   ${LATEX_COMPILE}
> >     ARGS      ${DOC_ROOT}/junk.tex
> >     TARGET    LaTeXDocument
> >     OUTPUTS   ${Test_BINARY_DIR}/junk.dvi
> > )
> > ADD_CUSTOM_COMMAND(
> >     SOURCE    LaTeXDocument
> >     TARGET    LaTeXDocument
> >     DEPENDS   ${Test_BINARY_DIR}/junk.dvi
> > )
> >
> 
> 
> the amusing thing  about this, is that the output
> goes absoluetly nowhere except in the working
> directory.  The bold use of ${Test_BINARY_DIR}
> has no actual impact on where the output goes !
> Everything stays in $DOC_ROOT
> Looking at the Makefile it is clear why.
> Now since CMake knows nothing about the actual
> command in use, e.g. latex, in this case, the only
> way I can see to affect the output location is
> throught the 'ARGS'
> Now I think in this case latex has no control over
> the output.  But imagine we were in the dvipdf phase
> then one would do something like
> ARGS      ${DOC_ROOT}/junk.tex ${Test_BINARY_DIR}/junk.dvi
> being the equivalent of
> % dvipdf  $DOC_ROOT/junk.tex $Test_BINARY_DIR/junk.dvi
> so I am still left unclear what the OUTPUTS thing is all about !

The outputs is hint to CMake and not to the actual command. It is so
that other custom commands or whatever know that this custom command
will create file. In your case, the second custom command depends on
${Test_BINARY_DIR}/junk.dvi. Now CMake will look at what generates that
file, by looking at OUTPUTS.

> 2)  To copy HTML files to their destnation I used your example
> which invokes, ultimately, something like
> 
> % cmake -E copy $HERE/junk.html  $THERE/junk.html
> 
> 
> Can i wild-card this ? I have lots of html source files to be copied.
> Thus the equivalent of
> 
> % cp $HERE/*.html $THERE
> 
> I tried the obvious things with the above cmake command syntax,
> but they fail.  I get the impression I can only do one at a time
> which means I have to write a custom command for each one.


You can use foreach:

ADD_CUSTOM_TARGET(HTMLs ALL)
SET(files junk1.html junk2.html junk3.html junk4.html)
SET(results)
FOREACH(file ${files})
  SET(src ${HERE}/${file})
  SET(dst ${THERE}/${file})
  ADD_CUSTOM_COMMAND(SOURCE ${src}
    TARGET HTMLs
    COMMAND ${CMAKE_COMMAND}
    ARGS -E copy ${src} ${dst}
    OUTPUTS ${dst}
  )
  SET(results ${results} ${dst})
ENDFOREACH(file)
ADD_CUSTOM_COMMAND(SOURCE HTMLs
  TARGET HTMLs
  DEPENDS ${results}
)

Looks good?
Verify the {}().

			Andy




More information about the CMake mailing list