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

William A. Hoffman billlist at nycap.rr.com
Tue, 13 Apr 2004 08:40:18 -0400


Subdir variables and commands do not affect the parent directories.
In the hello example, it sets the directories for the whole project at
the top.   You could and should only set the include directories where
they are needed.  The only way to pass information up to a parent directory
is via CACHE variables which once set are available to the entire project.

-Bill


At 03:29 PM 4/9/2004, Zachary Pincus wrote:
>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
>
>_______________________________________________
>Cmake mailing list
>Cmake at www.cmake.org
>http://www.cmake.org/mailman/listinfo/cmake