[CMake] How to emulate autotools "make check"?

Eric Noulard eric.noulard at gmail.com
Fri Mar 20 05:06:24 EDT 2009


2009/3/20 Marcel Loose <loose at astron.nl>:
> Hi Erk,
>
> On Thu, 2009-03-19 at 15:37 +0100, Eric Noulard wrote:
>> 2009/3/19 Marcel Loose <loose at astron.nl>:
>> > Hi Eric,
>> >
>> > I used "make test" first, but that failed the same way ctest fails.
>> > However, ctest -V at least gave me some more (useful) output.
>>
>> You are right there is no "functional" difference,
>> in one case you'll have
>> make test --> ctest --> ctest
>> and in the other
>> ctest --> ctest
>
> I still don't understand why ctest is being called twice, or (as you
> say) recursively.

Because you ask for it :-)
when calling ctest in add_test.


>> Then this executable should be built with add_executable somehow
>> add_test macro does not compile anything, that's may be were you
>> have missed something.
>>
>> add_test(testname Exename arg1 arg2 ...)
>>
> Hmm, if I add the test with add_executable() it will become part of
> target all; so it will always be built when typing 'make'. But I want it
> to become part of a target 'check', so that it's only being compiled,
> linked and run when you type 'make check'.
>
> I've played a bit with EXCLUDE_FROM_ALL. That way I could get the
> sources to compile and link

I think you find the appropriate way, add_executable with EXCLUDE_FROM_ALL.

>  but not run against target 'check'. Should I
> also use add_custom_command()? If so, then this command should have the
> same effect as typing 'make test' at the command line. Right? How do I
> accomplish that?

Did you something like:

add_executable(t_hello t_ EXCLUDE_FROM_ALL hello.cpp)

add_test(t_hello t_hello)

add_custom_target(check
                             COMMAND ${CMAKE_BUILD_TOOL} test
                             DEPENDS t_hello)

then:

the toplevel check target exists but won't be run by "make"
you have the rule to build your exe (but it is excluded from all)
the check target depends on your exe so that calling "make check"
should trigger the build of your exe.

in the end the check target should run "make test" which seems to be what
you want?


>> I think (but I may be wrong too) that you supposed may build needed executable
>> from source of the same name. This is not the case, CTest is **only**
>> executing some prebuilt executable with given agrument.
>
> If that is the case, and I'm willing to believe you, why does ctest run
> cmake (as can be seen from the output of 'ctest -V')?

Because you asked ctest to "--build-and-test"  the build part
needs/triggers cmake run :-).

I'll be off the list for a week or so, please do not drop the list address
or you won't have any answers.

-- 
Erk


More information about the CMake mailing list