[Cmake] variables set in SUBDIRS() available to top-level CMakeList?

Zachary Pincus zpincus at stanford.edu
Fri, 9 Apr 2004 12:29:45 -0700


Hello,

If a CMakeLists file called via SUBDIRS(...) sets some variables, are 
these available to commands in the top-level file?

For example, I have a simple project which builds a library and an 
executable.

Top Level CMakeLists:
PROJECT(foo)
SUBDIRS(./lib)
...

Lib CMakeLists:
INCLUDE_DIRECTORIES(./headers)

So, will commands in the top level cmakelists subsequent to the 
subdirs() call be able to see the INCLUDE_DIRECTORIES set in the 
lower-level cmakelist? If so, will the relative path be properly 
translated, or would I have to be more careful in setting the address 
as relative to the upper-level project root? (Is there a way to get the 
path to the current directory, relative to the project root, from 
cmake?)

I ask this because doing things this way seems more robust than the 
method here:
http://cmake.org/HTML/Examples.html
where one sets the INCLUDE_DIRECTORIES for the headers in the "hello" 
directory NOT in the "hello" CMakeLists file, but in a CMakeLists 
outside of the "hello" directory. It seems like it would be nicer to 
set every variable relevant to a given directory in that directory's 
CMakeLists file, so that changes to a directory structure necessitate 
editing only one CMakeLists file.

Thanks,

Zach Pincus

Department of Biochemistry and Program in Biomedical Informatics
Stanford University School of Medicine