Serdlao
Serdlao

Reputation: 21

Add bash command to CMake test

I recently found out about CMake testing possibilities. I wrote several test-clients using it, they work ok, but to perform tests I need to:

cmake .. -> make -> then run my program in the background or other terminal -> make test (which runs all test clients/test scenarios)

Lets say I want the command: make test not only to run the tests, but also to run the executable(That is being tested) in background and kill it after tests complete. How can I pass a bash command via CMakeLists? I haven't found a straightforward way to achieve what I want yet

Upvotes: 2

Views: 1227

Answers (2)

Bill Hoffman
Bill Hoffman

Reputation: 1762

There is not a way to run a process in the background from ctest. To handle this for projects like paraview that use MPI, we write a c driver program that launches the processes and performs the test/tests. Basically each ctest test needs to be something that runs and returns a value. However, there is of course nothing keeping that test from starting and stopping as many processes as possible.

Upvotes: 2

meyumer
meyumer

Reputation: 5064

You can do so by using ADD_CUSTOM_COMMAND. (CMake ADD_CUSTOM_COMMAND docs)

Upvotes: 2

Related Questions