[Cmake] Setting variables breaks the cache for SUBDIRS?

William A. Hoffman billlist at nycap.rr.com
Wed, 14 Apr 2004 08:33:55 -0400


Perhaps if you were to describe what you are trying to accomplish, there is
another solution.   

-Bill


At 12:06 AM 4/14/2004, Zachary Pincus wrote:
>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
>
>_______________________________________________
>Cmake mailing list
>Cmake at www.cmake.org
>http://www.cmake.org/mailman/listinfo/cmake