Skip to content

cmake -E tar xzf file.tar.gz -- file_name always extracts the whole archive

Documentation for cmake -E states that you can pass file names to the tar command by using --, but I cannot make this work with CMake 3.10.2, it always extract all files from the archive.

Here is an example:

set(mysql_src_url
    "https://downloads.mariadb.org/f/mariadb-10.0.10/kvm-tarbake-jaunty-x86/mariadb-10.0.10.tar.gz/from/http%3A//ftp.hosteurope.de/mirror/archive.mariadb.org/?serve")
set(mysql_src_checksum "14ce22b8197d4eae88d237776d47220f")
set(mysql_src_archive "${CMAKE_CURRENT_BINARY_DIR}/mariadb-10.0.10.tar.gz")
file(DOWNLOAD
  "${mysql_src_url}"
  "${mysql_src_archive}"
  EXPECTED_HASH MD5=${mysql_src_checksum}
  SHOW_PROGRESS)
message("Extracting ${mysql_src_archive}")
execute_process(COMMAND
  ${CMAKE_COMMAND} -E
  tar xvzf "${mysql_src_archive}" -- "mariadb-10.0.10/include")

I want to only extract the contents of "mariadb-10.0.10/include" and skip everything else. Am I doing something wrong?

By the way the help message for cmake does not mention that you need to use --, this is what I tried at first. But that also didn't work.

Edited by Sergey Zolotarev
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information