[CMake] Generating test executables with make test

Adolfo Rodríguez dofo79 at gmail.com
Fri Jan 30 04:31:59 EST 2009


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/20090130/c2269caa/attachment.htm>


More information about the CMake mailing list