<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 "")<br>function( define_project )<br> math( EXPR count "${project_count}+1" )<br> set( project_count ${count} CACHE INTERNAL "")<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'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't work in that case in my tests. </div>