[CMake] add_dependency on a custom target

David Cole david.cole at kitware.com
Wed Sep 15 11:40:09 EDT 2010


On Wed, Sep 15, 2010 at 11:15 AM, Nick Davidson <Nick at toby-churchill.com>wrote:

> Whoops, forgot to reply on list, sorry!
>
> > From: cmake-bounces at cmake.org
> > [mailto:cmake-bounces at cmake.org] On Behalf Of Andreas Pakulat
> > Sent: 15 September 2010 13:03
> > To: cmake at cmake.org
> > Subject: Re: [CMake] add_dependency on a custom target
> >
> > On 15.09.10 12:34:43, Nick Davidson wrote:
> > > Dear List,
> > >
> > > I'm using a file glob to extract a list of xml files to pass to a
> > > custom target to generate a pot file with getttext, most of
> > the heavy
> > > lifting is handled by a Macro.
> > >
> > > include(FindMsgfmt)
> > > macro (MakePot BIN_NAME CPP_SOURCES XML_SOURCES)
> > >      set(CPP_SRCS ${CPP_SOURCES})
> > >      set(XML_SRCS ${XML_SOURCES})
> > >      set(POT_FILE ${BIN_NAME}.pot)
> > >      if (XGETTEXT_FOUND)
> > >          message(STATUS "Adding Target Potfile: ${POT_FILE}")
> > >          if (XML_SRCS)
> > >              add_custom_target(${POT_FILE} ALL
> > >              COMMAND ${XGETTEXT_EXECUTABLE} --language=C++
> > --force-po
> > > -kN_ -kNN_:1,2 -o  ${POT_FILE} ${CPP_SRCS}
> > >              COMMAND ${XGETTEXT_EXECUTABLE} --language=Glade
> > > --force-po -j -o  ${POT_FILE} ${XML_SRCS} )
> > >          else (XML_SRCS)
> > add_custom_target(${POT_FILE} ALL
> > >              COMMAND ${XGETTEXT_EXECUTABLE} --language=C++
> > --force-po
> > > -kN_ -kNN_:1,2 -o  ${POT_FILE} ${CPP_SRCS})
> > >          endif(XML_SRCS)
> > >          add_dependencies(${POT_FILE} ${XML_SOURCES} ${CPP_SRCS})
> > >      else (XGETTEXT_FOUND)
> > >          message(STATUS "Cannot find xgettext")
> > >      endif(XGETTEXT_FOUND)
> > > endmacro (MakePot POT_NAME)
> > >
> > > The only problem is, if the list of xml files changes (e.g. a
> > > deletion) the cmake cache doesn't get regenerated and thus the xml
> > > files are not reglobbed and so the custom command fails.
> > >
> > > Any suggestions?
> >
> > Don't use a glob (list the files individually) or remember to touch
> > the cmakelists.txt file after adding new files. I don't think there's
> > a way to have cmake re-run when calling just make within
> > cmakelists.txt.
>
> Ok, but why doesn't adding the files as dependencies work?
> The glob is stored in the cache - fine, there isn't a way for Cmake to
> automatically figure out what files it should check to see if anything
> has changed. Having added those files as dependencies of the target that
> uses the glob manually then surely it's just a list of files?
>
>
> Is there a fundamental difference between a list variable made from
> a globbed set of files and a list made from a manually specified set?
>

There's no indication that a set of files retrieved by glob has changed when
a file is added or removed from a directory. So if the set changes, neither
make nor cmake know that anything is out of date... and nothing re-runs.

The mod time of the file containing the list changes when the manually
specified list changes. Therefore CMake can be re-run by make.



>
> >
> > Andreas
> >
> > --
>
> Nickd
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100915/e93c6c2d/attachment.htm>


More information about the CMake mailing list