[CMake] Running tests as part of a build

Clinton Stimpson clinton at elemtech.com
Fri Jan 8 13:16:33 EST 2010


On Friday 08 January 2010 11:10:23 am Gavin Heavyside wrote:
> I am seriously looking at moving the build system of some existing software
> from scons to cmake.  Most things I want to accomplish seem easier in
> cmake, but there is one thing I can't work out how to do.
>
> I like to have (at least some) unit test run as part of the build, e.g.
> when I type 'make' then my program compiles, the tests compile and then the
> tests run.  This means that failing tests are equivalent to a failing
> build, and stops me 'forgetting' to run 'make test'.
>
> I can generate my tests and and have them added to the 'test' target easily
> enough, and 'make test' works fine.  Is there a straightforward way to run
> tests after they are built as part of 'make' on its own, and have a failing
> test cause a build failure?
>
> I'm using g++ on linux & mac and Google Test as my unit testing framework,
> in case it make a difference to the answer.
>

Have you looked at add_custom_command(TARGET ...) or add_custom_target(...)?
Those are how you run can run commands as part of the build, but after some 
other targets are compiled.

Clint


More information about the CMake mailing list