<br><br><div class="gmail_quote">On 7 July 2010 23:38, Marcel Loose <span dir="ltr"><<a href="mailto:loose@astron.nl">loose@astron.nl</a>></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>
> On 7. Jul, 2010, at 16:01 , Paul Harris wrote:<br>
><br>
> > Hi all,<br>
> ><br>
> > I have looked and can't find the answer, so I turn to the list.<br>
> ><br>
> > I have a CMakeLists.txt and a subdirectory called utils, which also<br>
has its<br>
> > own CMakeLists.txt<br>
> ><br>
> > In the parent CML.txt, I have something like:<br>
> ><br>
> > ENABLE_TESTING()<br>
> > add_subdirectory(utils)<br>
> ><br>
> > In my utils CML.txt, I have<br>
> ><br>
> > ADD_EXECUTABLE(unit_1 units/unit_1.cpp)<br>
> > ADD_TEST( unit_1 ${EXECUTABLE_OUTPUT_PATH}/unit_1 )<br>
> ><br>
><br>
> Simplify this to<br>
><br>
> ADD_TEST(unit_1 unit_1)<br>
><br>
> 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>
><br>
> As for the dependencies, I agree that it would be nice if the "test"<br>
target depended on the executables. But what is wrong with "make all<br>
test" (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>
><br>
> function(add_test_executable name)<br>
> if(NOT TARGET ${name})<br>
> add_custom_target(test_exes)<br>
> endif()<br>
> add_executable(${name} ${ARGN})<br>
> add_dependencies(test_exes ${name})<br>
> endfunction()<br>
><br>
> Then you can do "make test_exes test".<br>
><br>
> HTH<br>
><br>
> Michael<br>
<br>
</div></div>You can further reduce the number of targets that get (re)build by going<br>
into the directory '${CMAKE_BINARY_DIR}/utils' and invoke 'make' there.<br>
<br>
You could also define a 'check' 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 "ctest")<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 'all'<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 "Cmake Scripting of CTest" but not explicitly enough to catch the eye.<br>
<br>
I've edited the wiki page, please check that my edits make sense.<br><br>Thanks<br>Paul<br>