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
)
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.
The CMake FAQ states that the
add_custom_command/add_custom_target
commands, which define custom targets, have a DEPENDS parameter.Edit
This will not work for built-in target
test
because of following feature request.But you always can create custom target
check
or whatever as suggested in CMake FAQ