I'm trying to create a custom target which should be used to cleaning out the output of my program. Is it possible to do something like this:
add_custom_target(
clean_output
file(REMOVE_RECURSE ${PROJECT_BINARY_DIR}/output)
)
Adds a target with the given name that executes the given commands. The target has no output file and is always considered out of date even if the commands try to create a file with the name of the target.
A CMake-based buildsystem is organized as a set of high-level logical targets. Each target corresponds to an executable or library, or is a custom target containing custom commands.
CMake is a cross-platform build system generator. Projects specify their build process with platform-independent CMake listfiles included in each directory of a source tree with the name CMakeLists. txt. Users build a project by using CMake to generate a build system for a native tool on their platform.
The add_custom_command() documentation says "This defines a command to generate specified OUTPUT file(s). A target created in the same directory (CMakeLists. txt file) that specifies any output of the custom command as a source file is given a rule to generate the file using the command at build time."
Try the following:
add_custom_target(
clean_output
COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_BINARY_DIR}/output"
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With