[CMake] Question about variables, cache, and scope

Robert Dailey rcdailey at gmail.com
Mon Oct 10 12:11:27 EDT 2011


I have a function that I define in my top-most CMakeLists.txt file (on
Windows using CMake version 2.8.6) called define_project() that calls
add_executable, sets up compile defintions, etc etc.

For each time define_project() is called *anywhere* in the directory
hierarchy, I need to increment a global "project_count" variable to keep
track of how many projects were created and print that at the very end of
the root CMakeLists.txt file.

So far my attempts at this have been unsuccessful. I tried creating a cache
variable in the root script:

set( project_count 0 CACHE INTERNAL "" )

Then inside of my function, I do this:

function( define_project ... )
   math( EXPR count "${project_count}+1" )
   set( project_count ${count} )
endfunction()

However, 'project_count' is always 0 each time that the function is
executed.

How can I make this work?

---------
Robert Dailey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111010/b8e2e719/attachment.htm>


More information about the CMake mailing list