[Cmake] strange behavior

Ken Martin ken.martin@kitware.com
Fri, 2 May 2003 11:56:56 -0400


The foreach loop is being process for each subdirectory as well.
Normally this isn't a problem because all the commands in the foreach
loop are also inherited. But... there was a bug in CMake 1.6.5 where the
STRING command is not inherited. And that is causing your problem. I
know this is fixed in CVS CMake and it should be fixed for CMake 1.6.7
when we release that patch.  If you want to know what commands are
inherited (i.e. run for subdirs as well) you can look at the header
files for the command in the source distribution. I believe almost all
commands are inherited except for ADD_EXECUTABLE ADD_LIBRARY
ADD_CUSTOM_COMMAND ADD_CUSTOM_TARGET INSTALL_FILES INSTALL_PROGRAM
INSTALL_TARGET and maybe one or two others.

Thanks
Ken



> -----Original Message-----
> From: cmake-admin@public.kitware.com [mailto:cmake-
> admin@public.kitware.com] On Behalf Of Stefan Schmidt
> Sent: Friday, May 02, 2003 10:45 AM
> To: cmake@public.kitware.com
> Subject: [Cmake] strange behavior
> 
> Hello,
> I have a strange problem with cmake (1.6.5) that I don't fully
understand:
> 
> I've some CMake code like this (simplified here), that sets some cache
> entries
> in a loop:
> ---
> SET (ALLPACKAGES
> AuxPkgs/TestData
> StdPkgs/ImagePkg
> AuxPkgs/Package3
> )
> 
> FOREACH(PKG ${ALLPACKAGES})
>    STRING(REGEX REPLACE "/" "_" PKGNAME ${PKG})
>      SET ("${PKGNAME}_DIR" ${CMAKE_BINARY_DIR}/${PKG} CACHE PATH
"Location
> of
> package ${PKG}" FORCE)
> ENDFOREACH(PKG)
> 
> SUBDIRS(TestSubDir)
> ---
> 
> Additionally to the intended AuxPkgs_TestData_DIR entries, a _DIR
entry is
> created with the same value as the last correct one.
> 
> This isn't the case when there are no SUBDIRS! Appearently, it has
> something
> to do with the way CMake processes the subdirectories and rereads (?)
the
> parent's CMakeList.
> I get around this if I use a (obviously superfluous)
IF(PKGNAME)...ENDIF
> around the cache setting.
> 
> I think this might either be a bug or the underlying mechanism how
CMake
> traverses the SUBDIRs has to be better documented.
> 
> 
> Kind regards,
> Stefan
> _______________________________________________
> Cmake mailing list
> Cmake@public.kitware.com
> http://public.kitware.com/mailman/listinfo/cmake