[CMake] Test organization within cmake

Damien R damienrg+list at gmail.com
Thu May 24 09:57:35 EDT 2012


Hi,

I want some help to organize tests within cmake.
Currently I have a test directory which contains some test files, eg :
test_foo.cpp
test_bar.cpp

In the CMakeLists.txt, I had:
add_executable(test_foo test_foo.cpp)
add_test(test_foo test_foo)

add_executable(test_bar test_bar.cpp)
add_test(test_bar test_bar)

test_bar and test_foo have not the same dependencies so I did:
find_package(Boost COMPONENTS thread)
add_executable(test_foo test_foo.cpp)
add_test(test_foo test_foo)
target_link_libraries(test_foo ${Boost_LIBRARIES} my-project)

find_package(Boost COMPONENTS system)
add_executable(test_bar test_bar.cpp)
add_test(test_bar test_bar)
target_link_libraries(test_bar ${Boost_LIBRARIES} my-project)

but it does not work as I expected (see bug
http://www.cmake.org/Bug/view.php?id=13244).
I realized that is not a cmake bug but my misunderstanding of cmake.

Correct me if I am wrong but I think the cmake way looks like:
test/CMakeLists.txt
add_subdirectory(foo)
add_subdirectory(bar)

test/foo/CMakeLists.txt
find_package(Boost COMPONENTS thread)
add_executable(test_foo test_foo.cpp)
add_test(test_foo test_foo)
target_link_libraries(test_foo ${Boost_LIBRARIES} my-project)

test/bar/CMakeLists.txt
find_package(Boost COMPONENTS system)
add_executable(test_bar test_bar.cpp)
add_test(test_bar test_bar)
target_link_libraries(test_bar ${Boost_LIBRARIES} my-project)

but I think this solution is a bit verbose because we need to create a
directory for each test.

So, I have 2 questions:
- how do you organize your tests within cmake? / what is the cmake way to
organize test?
- how do you handle multiple targets in the same CMakeLists.txt with
differents dependencies? / what is the cmake way to handle multiple targets
in the same CMakeLists.txt with differents dependencies?

Regards,
Damien R.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120524/24fc33a2/attachment.htm>


More information about the CMake mailing list