<br><br><div class="gmail_quote">On 7 July 2010 23:38, Marcel Loose <span dir="ltr">&lt;<a href="mailto:loose@astron.nl">loose@astron.nl</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><div></div><div class="h5">On Wed, 2010-07-07 at 17:05 +0200, Michael Wild wrote:<br>
&gt; On 7. Jul, 2010, at 16:01 , Paul Harris wrote:<br>
&gt;<br>
&gt; &gt; Hi all,<br>
&gt; &gt;<br>
&gt; &gt; I have looked and can&#39;t find the answer, so I turn to the list.<br>
&gt; &gt;<br>
&gt; &gt; I have a CMakeLists.txt and a subdirectory called utils, which also<br>
has its<br>
&gt; &gt; own CMakeLists.txt<br>
&gt; &gt;<br>
&gt; &gt; In the parent CML.txt, I have something like:<br>
&gt; &gt;<br>
&gt; &gt; ENABLE_TESTING()<br>
&gt; &gt; add_subdirectory(utils)<br>
&gt; &gt;<br>
&gt; &gt; In my utils CML.txt, I have<br>
&gt; &gt;<br>
&gt; &gt; ADD_EXECUTABLE(unit_1 units/unit_1.cpp)<br>
&gt; &gt; ADD_TEST( unit_1 ${EXECUTABLE_OUTPUT_PATH}/unit_1 )<br>
&gt; &gt;<br>
&gt;<br>
&gt; Simplify this to<br>
&gt;<br>
&gt; ADD_TEST(unit_1 unit_1)<br>
&gt;<br>
&gt; CMake will figure out by itself that unit_1 is a target and invoke the<br>
executable correctly (your code would break for multi-configuration IDE<br>
generators).<br>
&gt;<br>
&gt; As for the dependencies, I agree that it would be nice if the &quot;test&quot;<br>
target depended on the executables. But what is wrong with &quot;make all<br>
test&quot; (apart from the fact that it possibly compiles more than you<br>
actually need to run the test)? You could also wrap the add_executable<br>
call in a custom function which creates a custom target (say test_exes)<br>
and makes it depend on all the executables:<br>
&gt;<br>
&gt; function(add_test_executable name)<br>
&gt;   if(NOT TARGET ${name})<br>
&gt;     add_custom_target(test_exes)<br>
&gt;    endif()<br>
&gt;    add_executable(${name} ${ARGN})<br>
&gt;    add_dependencies(test_exes ${name})<br>
&gt; endfunction()<br>
&gt;<br>
&gt; Then you can do &quot;make test_exes test&quot;.<br>
&gt;<br>
&gt; HTH<br>
&gt;<br>
&gt; Michael<br>
<br>
</div></div>You can further reduce the number of targets that get (re)build by going<br>
into the directory &#39;${CMAKE_BINARY_DIR}/utils&#39; and invoke &#39;make&#39; there.<br>
<br>
You could also define a &#39;check&#39; target that will build and run all your<br>
test programs. See <a href="http://www.cmake.org/Wiki/CMakeEmulateMakeCheck" target="_blank">http://www.cmake.org/Wiki/CMakeEmulateMakeCheck</a><br>
<br>
Best regards,<br>
<font color="#888888">Marcel Loose.<br>
<br>
</font></blockquote></div><br>Thanks Marcel, I combined the solution in the wiki with what was discussed in my last email, and I ended up with<br><div> </div>set (CMAKE_TEST_COMMAND &quot;ctest&quot;)<br><br>function (add_unit_test name)<br>

   if(NOT TARGET ${name})<br>      add_custom_target (check COMMAND ${CMAKE_TEST_COMMAND})<br>   endif()<br>   add_executable(${name} ${ARGN})<br>   # or ADD_EXECUTABLE(${name} ${ARGN} EXCLUDE_FROM_ALL)<br>   #    if you want it to be skipped when building &#39;all&#39;<br>

   add_test(${name} ${EXECUTABLE_OUTPUT_PATH}/${name})<br>   add_dependencies(check ${name})<br>endfunction()<br><br><br><br>however, I have discovered (with message()) that ${CMAKE_TEST_COMMAND} is *empty* - its something I had to set(), which is not mentioned in the wiki page you mentioned.  It IS kind-of-mentioned in &quot;Cmake Scripting of CTest&quot; but not explicitly enough to catch the eye.<br>

<br>
I&#39;ve edited the wiki page, please check that my edits make sense.<br><br>Thanks<br>Paul<br>