[CMake] Question about variables, cache, and scope

Robert Dailey rcdailey at gmail.com
Thu Oct 13 13:27:31 EDT 2011


>
> 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


Unfortunately this isn't a valid test case.

You need to add each call to define_project() into a CMakeLists.txt script
in a subdirectory, and then call add_subdirectory() from the root script. It
won't work in that case in my tests.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111013/0ee4e03a/attachment.htm>


More information about the CMake mailing list