Hi all,<div><br></div><div>I have looked and can't find the answer, so I turn to the list.</div><div><br></div><div>I have a CMakeLists.txt and a subdirectory called utils, which also has its own CMakeLists.txt</div><div>
<br></div><div>In the parent CML.txt, I have something like:</div><div><br></div><div>ENABLE_TESTING()</div><div>add_subdirectory(utils)</div><div><br></div><div>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>When I run "make test" on the command line, it will only run the tests, it doesn't build my tests.<br>When I want to do some work and test it, I would like to do something like<br>
<br>make build_run_tests<br>and have it automatically build ALL of my unit tests, and then run ALL of my unit tests.<br><br>But there doesn't seem to be any way other than something like<br>make unit_1 unit_2 unit_3 && make test<br>
Which is very difficult to do, as the actual names of my unit tests are much longer, eg unit_string_numeric_utils<br><br>I tried doing cmake --build-and-test but that seems to demand that I also tell it what the targets are too!<br>
<br><br>I did the following hack,<br>in parent CML.txt, it now reads:<br>ENABLE_TESTING()<br>set (UNIT_TESTS)<br><div>add_subdirectory(utils)<br>add_custom_target (build_tests ALL DEPENDS ${UNIT_TESTS})<br>add_custom_target (build_run_tests ALL DEPENDS ${UNIT_TESTS} test)<br>
<br>and in utils/CML.txt it now reads:<br>ADD_EXECUTABLE(unit_1 units/unit_1.cpp)<br>ADD_TEST( unit_1 ${EXECUTABLE_OUTPUT_PATH}/unit_1 )<br>SET (UNIT_TESTS ${UNIT_TESTS} unit_1 PARENT_SCOPE)<br><br>so I am MANUALLY adding every unit test into "UNIT_TESTS" variable, and then I add a custom target to build them all.<br>
But you can see that my attempt to make build_run_tests failed, as I can't seem to build the 'test' subproject directly.<br><br>This hack is very verbose, I have to add<br></div>SET (UNIT_TESTS ${UNIT_TESTS} unit_xyz PARENT_SCOPE)<br>
for EVERY unit test I write.<br><br>WHY is it so annoying to do such a seemingly simple thing?<br><br>thanks<br>Paul<br><br></div>