[CMake] add_test in an out-of-tree source

Philipp Moeller philipp.moeller at geometryfactory.com
Wed Jun 6 09:47:06 EDT 2012


Hello list,

I have the following directory layout

TopLevel
  -- Dir1
     -- CMakeLists.txt (3)
     -- foo.cpp
  -- Installation
     -- CMakeLists.txt (2)
  -- CMakeLists.txt (1)

with (1)

add_subdirectory(Installation) 

and (2)

enable_testing()
add_subdirectory("${CMAKE_SOURCE_DIR}/Dir1" "${CMAKE_BINARY_DIR}/test/Dir1")
                                            # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                            # has to be specified,
                                            # because Dir1 is a
                                            # out-of-tree source

and in (3) 

add_executable(foo foo.cpp)
add_test(foo_test ${CMAKE_CURRENT_BINARY_DIR}/foo)


No CTestTestFile.cmake will be added to the build directory, no test
target is created and ctest will complain about no tests.

If I use add_subdirectory("${CMAKE_SOURCE_DIR}/Dir1") from (1)
everything works fine.

I could find related things in the bug-tracker, but they were not quite
as this case. Is there an easy work-around or am I misunderstanding something?

cmake --version 
cmake version 2.8.8

Cheers,
Philipp


More information about the CMake mailing list