TLDR: Please add an option to copy_directory
to copy the directory AND its contents, i.e. copy_directory -r d1 d2 dest
will result in dest/d1/...
and dest/d2/...
.
copy_directory
surprises me often by not quite behaving like any other directory copy operations I work with. The name suggests it will copy the directory structure: directory and contents.
Current behavior is what I would call “copy_directory_contents”.
On Mac and mobile, folders are often treated as objects (.app, .bundle, etc). Copying the contents makes no sense, and is further confused when you try to copy multiple dirs:
x: x/1, x/2
y: y/2, y/3
${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/x ${CMAKE_CURRENT_LIST_DIR}/y z)
expected:
build/z/x/1, z/x/2, z/y/2, z/y/3
actual:
build/z/1, z/2, z/3
My current use case is the following:
add_library (soandso INTERFACE)
set_target_properties (soandso PROPERTIES RUNTIME_STUFF something.bundle something.framework)
...
function (post_build target)
get_target_property (_runtimes ${target} RUNTIME_STUFF)
if (_runtimes)
add_custom_command (
TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${_runtimes} $<TARGET_FILE_DIR:${target}>
COMMAND_EXPAND_LISTS
)
endif ()
endfunction ()
This just creates a directory-scramble with the contents of all those folders merged into one directory, instead I have to unpack the lists myself and mess around separating out the folder name:
...
foreach (_runtime ${_runtimes})
get_filename_component (_folder ${_runtime} NAME)
add_custom_command (
TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${_runtime}
$<TARGET_FILE_DIR:${target}>/${_folder}
)
endforeach ()
...