Currently I have External_Project_Add_Step to copy directory from "source dir" to "dest dir". Lately I have realized that I am copying around 4 GB for data in this process, while I would actually need to copy selective files ( many files but total size ~1 GB).
ExternalProject_Add_Step(${EXTERNAL_TARGET} lib_step
COMMAND ${CMAKE_COMMAND} -E make_directory ${TGT_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${SRC_DIR} ${TGT_DIR}
COMMENT "Copying lib from ${SRC_DIR} to ${TGT_DIR}"
DEPENDEES install)
However I do have list of files which I want to copy. I was wondering if I can put loop inside External_Project_AddStep to have single step to copy all the files required. Something as below (It doesn't work though)
ExternalProject_Add_Step(${EXTERNAL_TARGET} lib_step
COMMAND ${CMAKE_COMMAND} -E make_directory ${TGT_DIR}
foreach(copy_file ${ALL_FILES})
file(copy ${SRC_DIR}/${copy_file} ${TGT_DIR})
endforeach(copy_file)
COMMENT "Copying lib from ${SRC_DIR} to ${TGT_DIR}"
DEPENDEES install)
I believe probable solution could be have script being called via ExternalProject_Add_Step which does copy internally or have loop over ExternalProject_Add_Step with different step name. Not sure which is cleaner/better approach
In CMake functions calls and other constructions cannot be nested one into another. So, using
foreach()
command insideExternalProject_Add_Step
parameters is wrong.But you may use
foreach()
for generate arguments forExternalProject_Add_Step
:In case of your files are direct childs of the source directory (that is,
ALL_FILES
does not contain subdirectories), you may use single invocation ofcopy
: