How to copy directory from source tree to binary tree?

Copying directory from source tree to binary tree. For example: How to copy www to bin folder.

work
├─bin
└─src
    ├─doing
    │  └─www
    ├─include
    └─lib

Thanks.


Since version 2.8, the file command has a copy argument:

file(COPY yourDir DESTINATION yourDestination)

Note that:

Relative input paths are evaluated with respect to the current source directory, and a relative destination is evaluated with respect to the current build directory


With CMake 2.8, use the file(COPY ...) command.

With older CMake versions, this macro copies files from one directory to another. If you don't want to substitute variables in the copied files, then change the configure_file @ONLY argument (for example to COPYONLY).

# Copy files from source directory to destination directory, substituting any
# variables.  Create destination directory if it does not exist.

macro(configure_files srcDir destDir)
    message(STATUS "Configuring directory ${destDir}")
    make_directory(${destDir})

    file(GLOB templateFiles RELATIVE ${srcDir} ${srcDir}/*)
    foreach(templateFile ${templateFiles})
        set(srcTemplatePath ${srcDir}/${templateFile})
        if(NOT IS_DIRECTORY ${srcTemplatePath})
            message(STATUS "Configuring file ${templateFile}")
            configure_file(
                    ${srcTemplatePath}
                    ${destDir}/${templateFile}
                    @ONLY)
        endif(NOT IS_DIRECTORY ${srcTemplatePath})
    endforeach(templateFile)
endmacro(configure_files)

As nobody has mentioned cmake -E copy_directory as a custom target, here's what I've used:

add_custom_target(copy-runtime-files ALL
    COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/runtime-files-dir ${CMAKE_BINARY_DIR}/runtime-files-dir
    DEPENDS ${MY_TARGET})