[CMake] custom targets can't be used in different subdirectories?

Gaëtan Lehmann gaetan.lehmann at jouy.inra.fr
Wed Nov 28 12:01:53 EST 2007


Le 28 nov. 07 à 17:35, Gaëtan Lehmann a écrit :

>
> Hi,
>
> I'm currently trying to build a project organized in  
> subdirectories. In all the subdirectories, several files are  
> generated at build time (with an ADD_CUSTOM_COMMAND).
> In all the directories, a custom target depending on all the files  
> generated in the subdirectory is created with ADD_CUSTOM_TARGET, so  
> it should be easy to declare a dependancy on all those files in  
> another subdirectory.
>
> During the build, things are all right until "make" try to build a  
> file which depends on a custom target from another subdirectory.  
> Here is an example:
>
> [glehmann at marvin build]$ LC_ALL=C make BaseSwig
> [  0%] Built target VXLNumericsIdx
> make[3]: *** No rule to make target `VXLNumericsIdx', needed by  
> `ClassIndex/wrap_ITKCommonBase.i'.  Stop.
> make[2]: *** [Modules/Base/CMakeFiles/BaseSwig.dir/all] Error 2
> make[1]: *** [Modules/Base/CMakeFiles/BaseSwig.dir/rule] Error 2
> make: *** [BaseSwig] Error 2
>
> VXLNumericsIdx is defined in one subdir, and BaseSwig in another  
> on. "make" reports that the custom target "VXLNumericsIdx" is built  
> (that's true), but the line after, it say it can't find that target.
> It seems definitively strange to me!
>
> I'm using cmake cvs 2007-10-24, and have seen the same behavior  
> with cmake 2.4.5
>
> Any idea about what can be wrong?
>

I've just find my mistake, which has nothing to do with  
subdirectories, but which don't fully explain the cmake behavior though:
I was trying to add the dependency to the custom target with the  
DEPENDS option of ADD_CUSTOM_COMMAND, while I should have used  
ADD_DEPENDENCIES (this one works fine).
However, it's strange that, with the DEPENDS option, the target is  
built. IMHO, it would be less confusing if the custom target would  
not be built at all, instead of giving a quite inconsistent error  
message.

Here is a short CMakeLists.txt to reproduce that behavior:

   PROJECT(toto)
   ADD_CUSTOM_TARGET(CustomTarget)
   ADD_CUSTOM_COMMAND(
    OUTPUT output
    COMMAND touch output
    DEPENDS CustomTarget
   )
   ADD_CUSTOM_TARGET(CustomCommand DEPENDS output)


and run "make CustomCommand".


For the next ones with that problem, the right way to do things is:

   PROJECT(toto)
   ADD_CUSTOM_TARGET(CustomTarget)
   ADD_CUSTOM_COMMAND(
    OUTPUT output
    COMMAND touch output
   )
   ADD_CUSTOM_TARGET(CustomCommand DEPENDS output)
   ADD_DEPENDENCIES(CustomCommand CustomTarget)

Gaëtan


-- 
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
http://voxel.jouy.inra.fr




-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: =?ISO-8859-1?Q?Ceci_est_une_signature_=E9lectronique_PGP?=
Url : http://public.kitware.com/pipermail/cmake/attachments/20071128/95726349/PGP.pgp


More information about the CMake mailing list