[CMake] add_test with --build-and-run fails

David Cole david.cole at kitware.com
Fri Sep 10 07:32:25 EDT 2010


Print out the value of CMAKE_SOURCE_DIR in your CMakeLists.txt file... It's
different in the context of your outer project and your test project.

If it's "/my/proj" for your outer project, it's going to be "/my/proj/test"
in your test project.

Is there a directory named "/my/proj/test/include1"?

If not, you'll need to pass down:

      --build-options

        -DINCLUDE_DIR:PATH=${CMAKE_SOURCE_DIR}/include1
and reference that in your test/CMakeLists.txt file...


HTH,
David


On Fri, Sep 10, 2010 at 5:06 AM, Frank Stappers <f.p.m.stappers at tue.nl>wrote:

> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100910/1aa69566/attachment-0001.htm>


More information about the CMake mailing list