<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
This works:<br>set( project_count 0 CACHE INTERNAL &quot;&quot;)<br>function( define_project )<br>    math( EXPR count &quot;${project_count}+1&quot; )<br>    set( project_count ${count} CACHE INTERNAL &quot;&quot;)<br>endfunction()<br>
define_project()<br>message(${project_count})<br>define_project()<br>message(${project_count})<br>define_project()<br>message(${project_count})<br>It prints out<br>1</blockquote><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
2<br>3</blockquote><div><br></div><div>Unfortunately this isn&#39;t a valid test case.</div><div><br></div><div>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&#39;t work in that case in my tests. </div>