cmake -E tar: Ability to Specify Output Paths of Individual Files When Creating Archive
It would be nice if the built-in CMake tar
command could support specifying output paths for each file passed to it. My use case is I need to package some files into a zip that is to be consumed by an application as a plugin, and I need to rename the dll I am zipping to "__CORE_DLL__.dll". There are also some other files whose output paths don't match their relative location in the build output that I need to redirect.
Currently I have very little control over the paths of the individual files in the archive. They take on their relative paths from the working directory. This means the only option is to copy the files I'd like to archive to a temporary folder where their locations and names match what I want, and then create the archive with that temp folder as the working directory. It would be preferable if the command could handle this since many zipping tools allow you to transform or configure the output paths. I think an ideal interface would be something like:
add_custom_command(
OUTPUT "${OUTPUT_FILE}"
COMMAND ${CMAKE_COMMAND} -E tar cfv "${OUTPUT_FILE}" --format=zip -- ${FILES_TO_ZIP} -- ${REL_OUTPUT_PATHS}
#WORKING_DIRECTORY "${BASE_DIR}" # working dir shouldn't make a difference when specifying output paths
VERBATIM
)
where REL_OUTPUT_PATHS
contains the relative output paths that correspond to each file in FILES_TO_ZIP
.
Alternatively an implementation of tar
's --transform
argument may work as well, but it seems more complicated.