[CMake] can a dependency be added to a specific test (CXX Test)?

Edward Flanigan eflanigan00 at hotmail.com
Tue Jul 22 23:50:18 EDT 2008



I am trying to create a test.

The traditional way uses the command :   add_test (simpleTest executable)
I want to know if there is any way to add a dependency to a specific test?
CMake does not recognize simpleTest as a target.

For my application I am trying to use cxx test.
A script (executable) is ran which produces a *.cpp file.
That file is then compiled to an executable test (simpleTest).

The target for the test (creating the *.cpp and test executable) should only build with command 'make test'
A simple 'make' should not build the target of the test (create *.cpp and test executable)


The way I have gotten this to work in the past is to have a new "Simple" project for the simple test, and use add_custom_command within the Simple project to generate the *.cpp file.

add_test (simpleTest ${CMAKE_CTEST_COMMAND}
        --build-and-test "a directory/test"

                         "a directory/test"

        --build-generator ${CMAKE_GENERATOR}
        --build-makeprogram ${CMAKE_MAKE_PROGRAM}
        --build-project Simple
        --test-command simple)

The add_test command calls the "Simple" project, builds the executable (simple) and then runs the test (simpleTest).

If possible I want to avoid having to create a new project because my application requires that a lot of shell variables be set as well as a lot of libs to be linked in.

When I call  'make test'
I want the following:
1.) have the script execute to create a *.cpp file,
2.) build the test executable from the *.cpp file
3.) run the test.
4.) This all must be done without calling new projects

My thoughts are the following:
If I could add a dependency to a specific test,
I could use target property "EXCLUDE_FROM_ALL" to make sure the test *.cpp and executable are only created during 'make test'
and not during 'make'.


Thanks in advance for any help.





_________________________________________________________________
Time for vacation? WIN what you need- enter now!
http://www.gowindowslive.com/summergiveaway/?ocid=tag_jlyhm


More information about the CMake mailing list