file(COPY): Add RENAME option
In case you want to copy a directory to another directory, it is currently not possible to change the destination name.
For example, if you want to copy the directory ${sourceDir}/mydir
to ${targetDir}/newdirname
, you cannot use file(COPY)
directly as this:
file(COPY ${sourceDir} DESTINATION "${targetDir}/newdirname")
would lead in the example to "${targetDir}/newdirname/mydir" instead of the wanted directory structure. As it is also not possible to pass wildcards to the source (file(COPY "${sourceDir}/*" DESTINATION "${targetDir}/newdirname")
), you have to bypass this issue by:
file(GLOB sourceFiles LIST_DIRECTORIES TRUE "${sourceDir}/*")
file(COPY ${sourceFiles} DESTINATION ${targetDir})
As install(FILES)
supports the command RENAME
it would be nice, when file(COPY)
also supports this (only for the case only a single directory or filepath is passed to the command).
So you could simply call:
file(COPY ${sourceDir} DESTINATION ${targetDir} RENAME "newdirname")