[CMake] SUBDIRS PREORDER semantics with ADD_DEPENDENCIES ?

Eric BOIX eboix at ens-lyon.fr
Wed Mar 8 09:47:31 EST 2006


   Dear CMake users,

As Brad King states it in
    http://public.kitware.com/pipermail/cmake/2006-February/008339.html

B. King>  As of CMake 2.2 the PREORDER flag is not useful or needed.  The make 
B. King>  system that is generated does not recurse through the directory 
B. King>  structure.  Instead it recurses on a target-level basis and always 
B. King>  builds things in the right order.

Hence, as I understand it, one now has to use ADD_DEPENDENCIES to translate
dependencies between directories into target dependencies. But this can prove
to be fairly complicated e.g. when the target directory contains many
sub targets...

Let's consider an example. Assume we have the following file layout:
  CMakeLists.txt
  documentation.tex       [ The documentation I want to TeXify ]
  fig/ (subdirectory)
     CMakeLists.txt
     a.fig, b.fig, c.fig... [many drawings in the transfig format and on
                             which documentation.tex depends]

Now, in order to TeXify my documentation I first need to convert all
my transfig files to encapsulated postscipt (eps) files, which I achieve
in fig/CMakeLists.txt. An easy (read lazy) way of doing this is to
do an FOREACH loop on the result of a FILE( GLOB ...) and for each file
to define the target.
Here is a code snipet taken from my fig/CMakeLists.txt:
   FILE(GLOB MANUAL_FIG_GLOB "*.fig")
   FOREACH( filename ${MANUAL_FIG_GLOB} )
     GET_FILENAME_COMPONENT( filenameNoExt ${filename} NAME_WE )
     SET( filenameDest "${CMAKE_CURRENT_BINARY_DIR}/${filenameNoExt}.eps" )
     ADD_CUSTOM_COMMAND( OUTPUT    ${filenameDest}
                         COMMAND   ${FIG2DEV}
                         ARGS      -L eps ${filename} ${filenameDest}
                         DEPENDS   ${filename} )
     ADD_CUSTOM_TARGET(dummy${filename}_EPS ALL
                       DEPENDS  ${filenameDest})
   ENDFOREACH( filename )

The important thing is here that the target names (i.e. dummy${filename}_EPS)
can be numerous and are generated by cmake ! Now my main CMakeLists.txt used
to only state
    SUBDIRS( PREORDER fig)
which doesn't work anymore with cmake version 2.2.X...

If I want to have the same semantics with ADD_DEPENDENCIES the trick
will be fairly complicated since my main CMakeLists.txt will have
to contain the same FOREACH loop based on a FILE GLOB of files of a
subdirectory... Doesn't seem to be really elegant, does it ?

My question is then: is there a clean way of still considering directories as
targets (which they are not according to the documentation and the new
logic) with ADD_DEPENDENCIES ? If not, what is a nice durable equivalent ?

         Thanks in advance,
         Yours,
         Eric Boix.


More information about the CMake mailing list