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

Yuri Timenkov ytimenkov at parallels.com
Wed Jul 23 03:24:32 EDT 2008


On Wednesday 23 July 2008 07:50:18 Edward Flanigan wrote:
> 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.
Macros can help you. Also, you can store essential part of your environment at 
CMake time and pass to test build with --build-options defines to make latter 
"environment-independent". Or you can dump it into some file on your build 
directory and load it later when building test. Also, you can use cmake in 
script-mode to load environment and build your complex target:
Instead of:
  CMakeLists.txt:
    add_custom_command(myscript.sh)

Use:
  GenerateTest.cmake:
    set(ENV{MyVal} foo)
    execute_process(myscript.sh)
  CMakeLists.txt:
    add_custom_command(cmake -P GenerateTest.cmake -DParam1=val1)

>
> 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'.
Also, you can look at KDE's add_test wrappers, they have some ideas about how 
to exclude tests from regular build, but they rely on BUILD_TESTS define too.

>
>
> Thanks in advance for any help.
>
>
>
>
>
> _________________________________________________________________
> Time for vacation? WIN what you need- enter now!
> http://www.gowindowslive.com/summergiveaway/?ocid=tag_jlyhm
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list