[CMake] Unit tests, but not CTest

Tyler Roscoe tyler at cryptio.net
Mon May 10 12:28:45 EDT 2010


Let's keep this on the list in case it helps someone else.

On Fri, May 07, 2010 at 10:27:16PM +0100, Magnus Therning wrote:
> On 07/05/10 17:24, Tyler Roscoe wrote:
> > On Fri, May 07, 2010 at 04:41:23PM +0100, Magnus Therning wrote:
> >>>        add_custom_command (TARGET ${PROJECT_NAME}
> >>>            POST_BUILD
> >>>            # Call the runner script directly. By doing it this way, all the
> >>>            # unit tests in the executable run at once. If we call CTest
> >>>            # here (like we do for the _runtest target), the script (and
> >>>            # thus the python interpreter) is invoked once for each test in
> >>>            # the executable, which is slower than calling the script once.
> >>>            COMMAND ${PYTHON_EXECUTABLE} ${${PROJECT_NAME}_TESTRUNNER} ${CMAKE_CFG_INTDIR} --gtest_print_time
> >>>        )
> >>
> >> One thing though, it seems the command is run *always* irrespective of
> >> whether the target is built or not.  That doesn't seem to square up
> >> with the text in the man page:
> > 
> > Works For Me. I only see unit test runs if the library in question is
> > recompiled or relinked. What version of CMake are you using?
> 
> 2.8
> 
> What kind of target is ${PROJECT_NAME}?
> 
> I used a target created with add_custom_target, so maybe that's the cause of it.

I think all the targets in our project which use this post-build step
are libraries or executables.

If your target is a custom_target that always runs (which, as noted in
the docs, custom_targets sometimes do) then of course the post-build
step will also always run.

hth,
tyler


More information about the CMake mailing list