[CMake] global variable passing up via INTERNAL cache

James Bigler bigler at cs.utah.edu
Thu Nov 29 16:37:32 EST 2007


Ha, ha.  I just had this problem.  This week in fact.

The problem is that if you initialize the list it won't work.  The  
following code worked for me.  You have to have two variables.  One  
for the building and one for the storing/using.

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

ADD_SUBDIRECTORY(subdir1)
ADD_SUBDIRECTORY(subdir2)

SET(MY_VALUE ${MY_VALUE_BUILD} CACHE INTERNAL "List of values")
# Reset the value for the next time cmake is called
SET(MY_VALUE_BUILD "" CACHE INTERNAL "List of values")

James

On Nov 29, 2007, at 2:09 PM, Tal Blum wrote:

> Hi,
>
>
>
> I defined the following macros. One us used to initialize a  
> variable while
> the other is used to add a value. It still has the problem that you  
> need to
> initialize it if you don't want the values to accumulate from one  
> run to the
> other.
>
>
>
> # A macro for passing lists between different directories
>
> # through an internal cache variable.
>
> MACRO (APPEND_INTERNAL_LIST  LIST_NAME  VALUE)
>
>
>
>    # If the list in not in the cache, create it.
>
>    IF (${LIST_NAME})
>
>       SET (${LIST_NAME} "${${LIST_NAME}};${VALUE}" CACHE INTERNAL  
> "Internal
> variable")
>
>    ELSE (${LIST_NAME})
>
>       SET (${LIST_NAME} "${VALUE}" CACHE INTERNAL "Internal variable")
>
>    ENDIF (${LIST_NAME})
>
>
>
> ENDMACRO (APPEND_INTERNAL_LIST)
>
>
>
> # A macro for passing lists between different directories
>
> # through an internal cache variable.
>
> # This function empties the variable (usually because of older runs)
>
> MACRO (INITIALIZE_INTERNAL_LIST  LIST_NAME)
>
>    SET (${LIST_NAME} "" CACHE INTERNAL "Internal variable")
>
> ENDMACRO (INITIALIZE_INTERNAL_LIST)
>
>
>
> -Tal
>
>
>



More information about the CMake mailing list