ExternalProject_Add: Optionally retain single root directory when extracting archive
When it comes to extracting and archive, ExternalProject_Add tries to be smart in extractfile.cmake.in.
If the archive contains only a single directory in the root, that top-most directory will not be copied to the source directory, only it's contents. https://github.com/Kitware/CMake/blob/b8449712a3fb87d63390a6b1802cd6b212a65aa3/Modules/ExternalProject/extractfile.cmake.in#L45-L51
Unless I missed something, I presume this behaviour is intended to "fix" user mistakes where some applications will create this structure. E.g. on Windows, right clicking a directory and choosing 'Send To -> Compressed (zipped) folder' you will end up with a single directory in the archive root named exactly the same as the archive itself (modulo extension), which might be unintended by the user.
I could not find this behaviour documented anywhere, and I would be every happy if this behaviour was opt-out as sometimes this directory structure is actually intended, especially if the top most directory does not share the name of the archive. Assuming user intent and trying to fix it feels slightly strange, even if it works for the majority of the users.
In our archives we have singular top-most directories which are usually named "bin" or "include", which end up disappearing when fetched with ExternalProject_Add.
Our current work-around is to specify DOWNLOAD_NO_EXTRACT
and then doing cmake -E tar
ourselves in an extra ExternalProject_Add_Step.
NB: Also, the behaviour of deleting all .DS_Store files in extractfile.cmake.in, albeit useful, should probably be documented somewhere as well.