[CMake] Generating test executables with make test

Adolfo Rodríguez dofo79 at gmail.com
Fri Feb 6 03:58:44 EST 2009


Greetings,

I'll stir the pot a little bit more in this subject, since I may not have
explained myself clearly last time, and I haven't been able to solve it by
my own means. I apologize for the extra noise ;)
So, restating: I want the "test" target (and not "all", nor any other
target) to build my test executables. According to the CMake documentation,
this is possible through something like

add_test(fooTest ${CMAKE_CTEST_COMMAND}
        --build-and-test
        "${CMAKE_CURRENT_SOURCE_DIR}/test"
        "${CMAKE_CURRENT_BINARY_DIR}/test"
        --build-two-config
        --build-generator ${CMAKE_GENERATOR}
        --build-makeprogram ${CMAKE_BUILD_TOOL}
        --build-project myProj
        --test-command fooTest)

where ${CMAKE_CURRENT_SOURCE_DIR}/test points to a standalone CMake project.
Being standalone, I have to perform lengthy initializations (or maybe import
the tested project?) that I'd like to avoid. If someone out there knows any
alternatives to this scenario, I'd be grateful to read them.

Cheers, and thanks in advance,

Adolfo Rodríguez Tsouroukdissian.


On Fri, Jan 30, 2009 at 10:31 AM, Adolfo Rodríguez <dofo79 at gmail.com> wrote:

> Hi all,
>
> I have a project with a suit of test executables that I create with CMake
> by means of add_executable(fooTest ${foo_DEPENDENCIES}), and then register
> in CTest with add_test(fooTest fooTest), and everything works just fine.
> As a next step, I wanted to exclude the building of the tests from the all
> target and associate them to the test target. Naively, I tried to
> EXCLUDE_FROM_ALL the test executables, and add_dependency(fooTest test), but
> I realized that this is not possible, since test (and install, clean, etc.)
> are not primary targets, and are only exist in the generated Makefiles.
> After reading various threads in this list, Section 10.5 of Mastering CMake
> (Using CTest to Drive Complex Tasks), and a couple of examples from the
> CMake source code, I tried something like:
>
> add_test(fooTest ${CMAKE_CTEST_COMMAND}
>         --build-and-test
>         "${CMAKE_CURRENT_SOURCE_DIR}/test"
>         "${CMAKE_CURRENT_BINARY_DIR}/test"
>         --build-two-config
>         --build-generator ${CMAKE_GENERATOR}
>         --build-makeprogram ${CMAKE_BUILD_TOOL}
>         --build-project common
>         --test-command fooTest)
>
> where the CMakeLists.txt file located in ${CMAKE_CURRENT_SOURCE_DIR}/test creates
> the test executable. Correct me if I'm wrong, but this CMakeLists.txt file
> needs to be a standalone CMake project that needs to "bring into scope" all
> the required external dependencies, and set up the necessary variables,
> which were all defined with the previous setup (using add_test(fooTest
> fooTest)). Since I'm working on a somewhat big project, performing this
> setup is quite inconvenient. Am I doing something wrong here? am I missing
> something? or must I pay the price of setting up a project for each test
> executable?
>
> Thanks in advance,
>
> Adolfo Rodríguez Tsouroukdissian
>
> P.S., I would like to express my support for the feature request reported
> in http://public.kitware.com/Bug/view.php?id=8438 although I know that
> asking for this is easier said than done.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090206/0d28a595/attachment.htm>


More information about the CMake mailing list