[CMake] global variable passing up via INTERNAL cache variable

James Bigler bigler at cs.utah.edu
Tue Nov 27 17:31:25 EST 2007


I got a hint that I could do this to set values that could be read by  
the CMakeLists.txt file above:

MACRO(APPEND_VALUE VALUE)
   SET(temp_value ${MY_VALUE} ${VALUE})
   MESSAGE("temp_value = ${temp_value}")
   SET(MY_VALUE ${temp_value} CACHE INTERNAL "List of values")
ENDMACRO(APPEND_VALUE)

I would then call APPEND_VALUE in sub directories.

Life was good until I noticed that subsequent calls of cmake would  
append to the list making it grow and grow.  I could do an insert  
only if the value didn't already exist, but that would prevent me  
from having values disappear if they wouldn't have added themselves  
(i.e. removing calls to APPEND_VALUE).

I tried adding this to the top level CMakeLists.txt before any of my  
ADD_SUBDIRECTORY.  The hope was that when CMake was called it would  
clear the variable before adding stuff to it again.

SET(MY_VALUE "" CACHE INTERNAL "")

However this stopped the appending from happening.  It looks like  
every time it pops up from a directory it resets MY_VALUE to what was  
in there before decending the directory.  This behavior is different  
from when the variable wasn't explicitly created in the top level  
CMakeLists.txt file.  Is this because the variable was created at the  
top level CMake instead of down below?

Is there any way to reliably get information passed automatically  
from subdirs?  This seems like a fundamental capability, and I'm very  
frustrated trying to figure out how to make this work.

I've attached a simple project that illustates the problem.  Run with  
cmake <path to CMakeLists.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: global.zip
Type: application/zip
Size: 1199 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20071127/82d0cef8/global-0001.zip
-------------- next part --------------


Thanks,
James


More information about the CMake mailing list