[CMake] Question about variables, cache, and scope
Bill Hoffman
bill.hoffman at kitware.com
Mon Oct 10 17:38:31 EDT 2011
On 10/10/2011 3:52 PM, Robert Dailey wrote:
> Yes, this works perfectly.
>
> It's a bit disappointing that cache variables are, for all intents and
> purposes, read-only in functions. The property approach is a bit more
> verbose but it functions! I think 'set' needs a new override
> specifically for cases like this. Something similar to "PARENT_SCOPE",
> but something like "CACHE_SCOPE", that forces CMake to first check for
> the existance of a cache variable with that name, and it would take
> precedence over any identically named variable in function scope.
>
> On another note, you'd think this would work too but it doesn't:
>
> set( project_count ${new_count} CACHE INTERNAL FORCE )
>
This works:
set( project_count 0 CACHE INTERNAL "")
function( define_project )
math( EXPR count "${project_count}+1" )
set( project_count ${count} CACHE INTERNAL "")
endfunction()
define_project()
message(${project_count})
define_project()
message(${project_count})
define_project()
message(${project_count})
It prints out
1
2
3
-Bill
More information about the CMake
mailing list