[CMake] Variable visibility through CMake directory strucutre

Alexander Neundorf a.neundorf-work at gmx.net
Wed Jul 11 08:28:38 EDT 2007


On Tuesday 10 July 2007 10:35, Iacopo Palazzi wrote:
> Hi there,
> the question I'm wondering about concerns the variable visibility during
> the CMake configuration process.
>
> Assume you have a two-level structure project:
>
> 	./
> 	./core
>
> Assume that the ./CMakeLists.txt is something like this:
>
> 	ADD_SUBDIRECTORY(core)
>
> 	FOREACH(F ${PRJ_SOURCES})
> 		MESSAGE(STATUS "File: ${F}")
> 	ENDFORACH(F ${PRJ_SOURCES})
>
> Assume that the ./core/CMakeLists.txt is like this:
>
> 	SET(PRJ_SOURCES file.cpp)
>
> The workflow wants that the ./core/CMakeLists.txt is being processed as
> first and then, the ./CMakeLists.txt.
> In the ./CMakeLists.txt I expect the ${PRJ_SOURCES} with file.cpp inside
> because the ./core/CMakeLists.txt structure, but it's empty. Seems like
> that returning from ./core/CMakeLists.txt, the ${PRJ_SOURCES} is not
> returned with the filled data.
>
> Is that a variable-visibility issue or something else unknown to me?

Variables are "inherited" to subdirectories, but not back to parent 
directories. So if you change PRJ_SOURCES in the toplevel file, this value is 
available in all subdirs, if you change it in one of the subdirs the changed 
value is current in all subdirs of that subdir, but not in the parent and 
sibling directories.

You could include() a file from core/ in your toplevel CMakeLists.txt, or you 
could use set(... CACHE FORCE), which forces a value in the cache, and the 
cache is visible everywhere.
Maybe you can also do something with SET/GET_TARGET_PROPERTIES() or 
GET/SET_DIRECTORY_PROPERTY() and define your own property for that.

Alex


More information about the CMake mailing list