Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake: 'add_custom_target' - using 'file' command

Tags:

cmake

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)
    )
like image 821
nil Avatar asked Nov 13 '13 11:11

nil


People also ask

What does Add_custom_target do in CMake?

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.

What is a target in CMake?

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.

What is CMake build?

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.

What is add_custom_command?

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."


1 Answers

Try the following:

add_custom_target(
    clean_output
    COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_BINARY_DIR}/output"
)
like image 93
ixSci Avatar answered Oct 11 '22 23:10

ixSci