I am trying to copy files from one destination to another by using configure_file
. I found the following solution How to copy directory from source tree to binary tree?.
function(USR_copy_directory srcDir destDir)
make_directory(${destDir})
file(GLOB_RECURSE files RELATIVE ${srcDir} ${srcDir}/*)
foreach(file ${files})
set(srcFile ${srcDir}/${file})
if(NOT IS_DIRECTORY ${srcFile})
configure_file(${srcFile} ${destDir}/${file} COPYONLY)
endif(NOT IS_DIRECTORY ${srcFile})
endforeach(file)
endfunction()
This solution allowed me to do the job. But when I tried to place the for
in another function it stopped creating directories. It just flat copied the files without preserving the structure. Basically both snippets of code are the same, it's just I remove the for
loop and placed it in another function, that's all. What am I doing wrong?
function(USR_copy_directory srcDir destDir)
make_directory(${destDir})
file(GLOB_RECURSE files RELATIVE ${srcDir} ${srcDir}/*)
set(srcFile "")
foreach(file ${files}) #this for loop allows me to append file and path
list(APPEND srcFile "${srcDir}/${file}")
endforeach(file)
USR_copy_files("${srcFile}" ${destDir})
endfunction()
function(USR_copy_files files destDir)
foreach(file ${files})
if(NOT IS_DIRECTORY ${file})
get_filename_component(filename ${file} NAME)
configure_file(${file} ${destDir}/${filename} COPYONLY)
endif(NOT IS_DIRECTORY ${file})
endforeach(file)
endfunction()