[CMake] test dependencies, labels, and tests in multiple directories

Mark mpictor at gmail.com
Sat Oct 29 21:02:51 EDT 2011


CMake 2.8.5, Debian Linux

I have tests in two different directories; the tests in one directory depend
on one test that is found in another directory.

If I try to test using 'make test', the tests run. Same for a ctest -S
script that doesn't use labels, and a script that runs all tests in the
proper order with labels. If I use a 'ctest -S' script that only tests
certain labels, I get an error in spite of the dependencies:
$ ctest -S run_ctest.cmake

> Unable to find executable: p21read
> Error in read script: /opt/step/scl/run_ctest.cmake


It seems that test dependencies are ignored when the dependencies refer to
tests in another directory. If a test is being built because of its label,
aren't its dependencies also supposed to be built?

Also, when I add a test in test/p21 that uses a binary built in data/, I
have to specify the full path to the binary instead of just specifying the
target name (p21read). Is this correct behavior?

Regards
Mark

The following has been shortened a lot - I hope there are no typos.


In project/CMakeLists.txt, I have
    ADD_SUBDIRECTORY(data)
    ADD_SUBDIRECTORY( test/p21 )

In project/data/CMakeLists.txt, I have
    set( SRCS "..." )
    set( LIBS "..." )
    add_executable( p21read ${SRCS} )
    target_link_libraries( p21read ${LIBS} )
    set_target_properties( p21read PROPERTIES EXCLUDE_FROM_ALL ON ) ### some
of the source for this target is generated, exclude it from all so it can be
used for a test
    add_test( NAME build_p21read
              WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
              COMMAND ${CMAKE_COMMAND} --build .
                                       --target p21read
                                       --config $<CONFIGURATION> )
    add_test( NAME generate_cpp COMMAND ... )     ### details omitted
    set_tests_properties( build_p21read PROPERTIES DEPENDS generate_cpp
LABELS cpp_schema_build )
    set_tests_properties( generate_cpp PROPERTIES LABELS cpp_schema_gen )

In project/test/p21/CMakeLists.txt, I have
    add_test( test_good_schema_name
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/p21read" path/file.p21 )   ###even though
p21read is a target, I have to specify the path to the binary
    set_tests_properties( test_good_schema_name PROPERTIES
DEPENDS build_p21read LABELS exchange_file )

    #get_property(dep TEST build_p21read PROPERTY DEPENDS )    ### added for
troubleshooting
    #message("test dir - build dep ${dep}")

#########################
If I uncomment the get_property() and message() lines immediately above,
configuration fails. The message that appears in Config.xml is

CMake Error at test/p21/CMakeLists.txt:27 (get_property):
  get_property given TEST name that does not exist:
  build_p21read
  test dir - build dep
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111029/e744f381/attachment-0001.htm>


More information about the CMake mailing list