This is a question for folks at Stack Overflow. Literally. :-)<br><br>I&#39;m assuming you mean &quot;_add_library(${name} ${ARGN})&quot;?<br><br>The &quot;override and call original with a leading _&quot; is probably not well documented anywhere. While it&#39;s useful on occasion, we do not recommend using it if there&#39;s an alternate technique that you can use.<br>
<br>When you override a function, there is only one &quot;_&quot; original function reference saved in CMake&#39;s data structures. So... if you do it more than once, the _ version now refers to one of the ones you&#39;ve defined rather than the real &quot;orginal&quot; one. It&#39;s more like the last one.<br>
<br>So then suddenly, you&#39;ve turned one of your functions into a recursive one that calls itself over and over again... hence the crash. Nice bit of unintended stack overflow.<br><br>Moral: if you&#39;re going to do this, do it globally at the top level CMakeLists.txt file and do not allow subdirectories to have their own overrides. At this point, enforcing this is up to your project. It should probably be made more robust in CMake itself, but until then, caveat emptor.<br>
<br><br>HTH,<br>David<br><br><br>p.s. -- the following CMakeLists file demonstrates the problem using add_executable -- when you run cmake on this, when it gets to the &quot;add_executable(exe2&quot; call, it gets into the first override of add_executable, which ends up calling itself over and over again via the re-defined _add_executable that it&#39;s trying to use.....<br>
<br>cmake_minimum_required(VERSION 2.8.4)<br>project(test_function_overrides)<br><br>file(WRITE &quot;${CMAKE_CURRENT_BINARY_DIR}/<a href="http://test.cxx.in">test.cxx.in</a>&quot;<br>&quot;int main(int argc, const char* argv[])<br>
{<br>  return 0;<br>}<br>&quot;)<br><br>set(src &quot;${CMAKE_CURRENT_BINARY_DIR}/test.cxx&quot;)<br><br>configure_file(<br>  &quot;${CMAKE_CURRENT_BINARY_DIR}/<a href="http://test.cxx.in">test.cxx.in</a>&quot;<br>  &quot;${src}&quot;<br>
  )<br><br>add_executable(exe0 ${src})<br><br>function(add_executable name)<br>  message(STATUS &quot;enter add_executable override1: name=&#39;${name}&#39;&quot;)<br>  _add_executable(${name} ${ARGN})<br>  message(STATUS &quot; exit add_executable override1&quot;)<br>
endfunction()<br><br>add_executable(exe1 ${src})<br><br>function(add_executable name)<br>  message(STATUS &quot;enter add_executable override2: name=&#39;${name}&#39;&quot;)<br>  _add_executable(${name} ${ARGN})<br>  message(STATUS &quot; exit add_executable override2&quot;)<br>
endfunction()<br><br>add_executable(exe2 ${src})<br><br><br><br><br><div class="gmail_quote">On Wed, Mar 9, 2011 at 9:45 AM, Johan Björk <span dir="ltr">&lt;<a href="mailto:phb@spotify.com">phb@spotify.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi everyone,<div><br></div><div>I just ran into an infinite loop in CMake. The cause is that I used function overrides in two locations in my CMake tree.</div>
<div>Is the _function_name() syntax documented somewhere? What is the expected behavior?</div>
<div><br></div><div><br></div><div>My structure is as follows:</div><div>proj1</div><div> - CMakeLists.txt</div><div> - common_core</div><div>proj2</div><div> - CMakeLists.txt</div><div> - common_core</div>
<div><br></div><div>in proj1 CMakeLists.txt I override a function using</div><div>function(add_library name)</div><div>_add_library_name(...)</div><div>...</div><div>endfunction()</div><div>include(common_core/common.cmake)</div>

<div><br></div><div>In common.cmake, I also override the function in the same way</div><div><div>function(add_library name)</div><div>_add_library_name(...)</div><div>...</div><div>endfunction()</div>
<div><br></div><div>This causes an infinite loop in latest master. </div><div><br></div><div>Thanks</div><div>/Johan</div><div><br></div>
</div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br>