[CMake] Adding to RUN_TESTS target

David Cole david.cole at kitware.com
Sat Oct 27 08:59:52 EDT 2012


Just run ctest down in the sub-directory, any directory with a
"CTestTestfile.cmake" file in it, (run it with no arguments), and it
will run the tests in that directory.

With Visual Studio, you'll need to use "${CMAKE_CTEST_COMMAND} -C
${CMAKE_CFG_INTDIR}" as the custom command to get the tests to run for
the right configuration.

I would do something like this if I were going to do it:

add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/SubdirTests.log
  ${CMAKE_CTEST_COMMAND} -C ${CMAKE_CFG_INTDIR} -O
${CMAKE_BINARY_DIR}/SubdirTests.log
  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/Subdir
)

add_custom_target(SubdirTests DEPENDS ${CMAKE_BINARY_DIR}/SubdirTests.log)

Then you could build the "SubdirTests" target to run the tests.

Of course, if you need to extend the subset, you could run a script as
the "test suite" instead, and in the script, do your pre-stuff, run
the ctest tests with the same command as above, and then do your
post-stuff.


Cheers,
David



On Wed, Oct 24, 2012 at 7:23 PM, Robert Dailey <rcdailey.lists at gmail.com> wrote:
> Thanks David.
>
> I don't mind creating a custom target for this, but I'm not sure how
> to invoke CTest manually with the tests in question. What commands
> would I run?
>
> On Wed, Oct 24, 2012 at 6:15 PM, David Cole <david.cole at kitware.com> wrote:
>> The ctest command that is run by RUN_TESTS is not extensible at the moment.
>>
>> However, you can use add_custom_target to make your own test target
>> (just don't name it "test" or "RUN_TESTS"... ;-) which can do whatever
>> you want.
>>
>>
>> HTH,
>> David
>>
>>
>> On Wed, Oct 24, 2012 at 5:44 PM, Robert Dailey <rcdailey.lists at gmail.com> wrote:
>>> Can I extend RUN_TESTS to execute more tests of my choosing? RUN_TESTS
>>> will only execute tests defined in the directory of the project I
>>> opened or below. I want to add some tests to it that are created prior
>>> to that project.
>>> --
>>>
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list