[CMake] emulating `make check' behaviour

William A. Hoffman billlist at nycap.rr.com
Tue Aug 15 14:26:52 EDT 2006


At 01:09 PM 8/15/2006, Scott Amort wrote:
>Hello,
>
>I am attempting to emulate the autotools `make check' behaviour in my
>CMake project.  I currently have a testing framework setup and working
>using ENABLE_TESTING() and CTest, however, it has two drawbacks (from my
>perspective, anyways ;-) ).
>
>1) Testing executables are compiled at the same time as the project
>(i.e. when `make' is executed).  I would prefer these to only compile
>when explicitly requested with `make test'.
>
>2) `make test' only executes ctest with no dependencies on the testing
>executables (i.e. if I make a change to the testing code, I need to
>rerun `make' and then `make test').
>
>I enquired about this a little while back, and it was suggested to use
>ctest with --build-and-test, however, I can't seem to find any
>documentation on what this actually does.  It appears to be independent
>of the CMake build process, however, so it is likely not the solution I
>am after.
>
>Does anyone have any suggestions on how to proceed?  My current idea is
>to create an optional subproject that is the testing executable(s) and
>link that to an ADD_CUSTOM_TARGET, however, I don't think it is possible
>to selectively compile projects with this command.  If anyone could
>offer some assistance, it would be greatly appreciated.

I still think that --build-and-test is your best bet.
Look here for examples: CMake/Source/CMakeLists.txt 

It basically, will run cmake, and run the build command at the time
the test is run.   So, the tests are not part of the larger projects
cmakelist files, and do not get built with all, or show up in IDE's to
clutter things up.   When you do make test, it will run ctest and
for each test it will run cmake on the test, and then run the make
or ide to build the test, then it will run the test.

-Bill



More information about the CMake mailing list