[CMake] Running custom command before executing test

Mohit Aron mohit.aron at gmail.com
Wed Nov 4 13:38:32 EST 2009


Hello,

I'm trying to figure out how to run a custom command before a test is
executed by ctest. Looking at the manual, searching on Google etc have
been futile so far. So I'm posting on this list for help.

Assume I have two test sources that lie at:

/home/user/workspace/path1/test/test1.cc
/home/user/workspace/path2/test/test2.cc

When these tests are run, I'd like to execute a custom command just before
running the test - the command depends on the path of the test. For example,
before running test1, I'd like to execute:

mkdir -p /home/user/workspace/testoutput/path1/test

The idea is to instruct the test to place its temporary files in that
directory. I can pass the path of the above output directory as an
argument to the test (in add_test()). However, I don't know how to
execute the custom mkdir command above. That is, how to modify
CMakeLists.txt so that it automatically generates the custom command
when one runs 'make test'.

I can run the custom command from within the test, but that's really
suboptimal as it has to be repeated for all the tests.

I'd appreciate help on how to do this.


- Mohit


More information about the CMake mailing list