[CMake] building tests

Paul Harris harris.pc at gmail.com
Wed Jul 7 22:40:00 EDT 2010


On 7 July 2010 23:05, Michael Wild <themiwi at gmail.com> wrote:

>
> On 7. Jul, 2010, at 16:01 , Paul Harris wrote:
>
> > Hi all,
> >
> > I have looked and can't find the answer, so I turn to the list.
> >
> > I have a CMakeLists.txt and a subdirectory called utils, which also has
> its
> > own CMakeLists.txt
> >
> > In the parent CML.txt, I have something like:
> >
> > ENABLE_TESTING()
> > add_subdirectory(utils)
> >
> > In my utils CML.txt, I have
> >
> > ADD_EXECUTABLE(unit_1 units/unit_1.cpp)
> > ADD_TEST( unit_1 ${EXECUTABLE_OUTPUT_PATH}/unit_1 )
> >
>
> Simplify this to
>
> ADD_TEST(unit_1 unit_1)
>
> CMake will figure out by itself that unit_1 is a target and invoke the
> executable correctly (your code would break for multi-configuration IDE
> generators).
>
>
This does not work for me.  If I do not have the EXECUTABLE_OUTPUT_PATH in
add_test, I get a message like this when i run "make test" (shortened for
brevity):

  1/  1 Testing unit_string_numeric_utils     Could not find executable
unit_string_numeric_utils
Looked in the following places:
unit_string_numeric_utils
unit_string_numeric_utils
Release/unit_string_numeric_utils
Release/unit_string_numeric_utils




> As for the dependencies, I agree that it would be nice if the "test" target
> depended on the executables. But what is wrong with "make all test" (apart
> from the fact that it possibly compiles more than you actually need to run
> the test)? You could also wrap


I want to only build the tests, because for today's job, rebuilding my unit
tests takes 2 seconds, which I'll do a dozen times as I add functionality.
linking the libraries that would be affected by my changes would take 60
seconds or more.


> the add_executable call in a custom function which creates a custom target
> (say test_exes) and makes it depend on all the executables:
>
> function(add_test_executable name)
>  if(NOT TARGET ${name})
>    add_custom_target(test_exes)
>   endif()
>   add_executable(${name} ${ARGN})
>
add_test(${name} ${EXECUTABLE_OUTPUT_PATH}/${name})

>   add_dependencies(test_exes ${name})
> endfunction()
>
>
This works well for me, brilliant!    except I added the add_test() line
(above)



> Then you can do "make test_exes test".
>
>
This does not work for me, as I run it like so:
make -j8 test_exes test   (yes I have 8 CPUs)
and that runs the 'test' before / in parallel with test_exes.

I have tried to resolve that with my next email to Marcel...

Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100708/30b5c598/attachment.htm>


More information about the CMake mailing list