[CMake] add_test with --build-and-run fails
Frank Stappers
f.p.m.stappers at tue.nl
Fri Sep 10 05:06:04 EDT 2010
Hello,
I try to accomplish to add a test, that compiles and runs afterward.
For the test that I want to run I have defined a project
CMakeLists.txt project in
${CMAKE_SOURCE_DIR}/test/, which looks like:
========
project(test_tgt)
cmake_minimum_required(VERSION 2.6)
include_directories(${CMAKE_SOURCE_DIR}/include1)
add_executable(test_tgt "test.cpp" )
target_link_libraries(test_tgt a_compiled_lib)
========
Within the CMakeLists.txt of ${CMAKE_SOURCE_DIR}
it is possible to compile "test_tgt", by including
========
.....
ENABLE_TESTING()
add_subdirectory(test)
========
And run "test_tgt"
Now I change the above code into:
========
.....
ENABLE_TESTING()
ADD_TEST(test_tgt ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMAKE_SOURCE_DIR}/test"
"${CMAKE_BINARY_DIR}/test"
--build-generator "${CMAKE_GENERATOR}"
--build-project test_tgt
--build-makeprogram "${CMAKE_MAKE_PROGRAM}"
--test-command test_tgt
)
=======
I re-run my cmake in the ${CMAKE_BINARY_DIR} and
execute:
ctest -R test_tgt --verbose
When I observe the output, I see something like:
=======
....
Constructing a list of tests
Done constructing a list of tests
Checking test dependency graph...
test 1
Start 1: test_tgt
1: Test command: ...
1: Test timeout computed to be: 1500
1: Internal cmake changing into directory: ${CMAKE_BINARY_DIR}/test
1: ======== CMake output ======
1: Configuring
1: Configuring done
1: Generating
1: Generating done
1: Build files have been written to: ${CMAKE_BINARY_DIR}/test
1: ======== End CMake output ======
1: Change Dir: ${CMAKE_BINARY_DIR}/test
1:
1: Run Clean Command:/usr/bin/gmake "clean"
1:
1: Run Build Command:/usr/bin/gmake
1: [100%] Building CXX object CMakeFiles/test_tgt.dir/test.cpp.o
1: In file included from ${CMAKE_SOURCE_DIR}/test/test.cpp:5:0:
1: /usr/include/include1/xxx.h:18:20: fatal error: yyy.h: No such file
or directory
1: compilation terminated.
1: gmake[2]: *** [CMakeFiles/test_tgt.dir/test.cpp.o] Error 1
1: gmake[1]: *** [CMakeFiles/test_tgt.dir/all] Error 2
1: gmake: *** [all] Error 2
1/1 Test #1: test_tgt .........................***Failed 0.13 sec
=======
Observe that the test fails, while it tries to include "yyy.h" from
"xxx.h" /usr/include/include1 from, whereas it
should:
1) pick the "xxx.h", as it is located in the ${CMAKE_SOURCE_DIR}
2) find "yyy.h" in the include_directories of project "test_tgt", as
it is stored in that location.
My question:
Is there something wrong with my code? Do I have to set additional
variables? Or is it a bug?
For the record, I'm using Cmake/Ctest 2.8.2.
Kind regards,
Frank Stappers
More information about the CMake
mailing list