[CMake] global variable vs cache variable

t m cmake at majchrowski.co.uk
Tue Nov 22 08:14:36 EST 2011


> Use the cache only if the values need to be persistent. Otherwise I
> recommend using a GLOBAL property. See set_property() and get_property().
>
> Michael

Thank you Michael. Looks good. So let me summarize. The workflow
should looks like follow:

1. Top Level  CMakeLists.txt:
add_subdirectory( foo )

2. Level 2 foo/CMakeLists.txt
set_property ( GLOBAL P_A PROPERTY "some value")

3. Level 1 CMakeLists.txt
get_property ( VAR_A GLOBAL PROPERY P_A)
message (STATUS "VAR_A=${VAR_A})

is that's right?


More information about the CMake mailing list