Jiang Bian Jiang Bian - 4 months ago 22
C Question

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.

Answer

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, change the configure_file @ONLY argument.

# 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)
Comments