[Cmake] Setting variables breaks the cache for SUBDIRS?

Zachary Pincus zpincus at stanford.edu
Tue, 13 Apr 2004 21:06:37 -0700


Hello,

I've run into a strange problem with the cache and SUBDIRS.

Here's the setup: I have a variable that I want to add to from various 
different CMakeLists in subdirectories, called from a SUBDIRS() 
command.

This works fine:

--------------
Top CMakeList
--------------
SUBDIRS(foo bar)

--------------
Foo CMakeList
--------------
SET(VAR "${VAR} foo" CACHE INTERNAL "add foo")

--------------
Bar CMakeList
--------------
SET(VAR "${VAR} bar" CACHE INTERNAL "add bar")


Now, as you would expect, after this all runs, the cache contains VAR=" 
foo bar"

However, if we change the top level CMakeList to look like this:
--------------
Top CMakeList
--------------
SET(VAR "top" CACHE INTERNAL "add top")
SUBDIRS(foo bar)

then instead of VAR="top foo bar" as you would expect, we just get "top 
bar"

It looks to me like *if* there is no variable set in the top-level 
CMakeList, the CMakeLists called from the SUBDIRS command can load 
cached variables. However, if such a variable has already been set in 
the top-level CMakeList, this prevents the subdir-CMakeLists from 
actively reading from the cache each time. When "child" CMakeList sets 
the cached variable thinking it is appending to it, it actually 
overwrites the variable because the CMakeList never read in the latest 
version (cached by a "sibling" CMakeList) because the version of the 
variable inherited from the parent "shadows" this.

SO: Is there a way to force a CMakeList to refresh the cache? Is this 
behavior a bug?

Zach Pincus

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