Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add dependency in cmake targets

Tags:

cmake

I have defined a custom target in cmake. I now want to ensure that this target is only build when the cmake target test was executed. How can I achieve this.

Lets say that I have a target make coverage which should depend on the target make test to be called before, or call make test before executing.

How can I define this behavior in cmake?

Here my code that did not work as expected. I want to achive that make coverage depend that make test has to be called before.

    ADD_CUSTOM_TARGET(
        coverage COMMAND /bin/bash ${LIBPIPE_BINARY_DIR}/cmake/scripts/coverage.sh
        DEPENDS test
    )  
like image 260
tune2fs Avatar asked Nov 10 '11 00:11

tune2fs


1 Answers

You cannot add a "DEPENDS test" clause. The pre-defined/built-in targets in CMake (all, install, package, test, clean) are not available as actual targets in a CMakeLists.txt file. So you cannot express a dependency on a built-in target.

There is an outstanding feature request in the CMake bug tracker for this feature, but it is not yet implemented. See http://public.kitware.com/Bug/view.php?id=8438

However, you could change your command for your custom target, though, such that it calls "make test" first, and then runs your coverage command.

like image 63
DLRdave Avatar answered Sep 27 '22 21:09

DLRdave