Suggestion: Enable FetchContent to Support Extracting Files with '.zst' Extension

Used CMake version: 4.0.3

I am trying to use FetchContent to fetch MINGW64-ICU on Windows. Here is my CMake configuration code:

cmake_minimum_required(VERSION 3.20)

FetchContent_Declare(
    ICU
    # Download from MSYS2
    URL "${CMAKE_SOURCE_DIR}/local_repo/mingw-w64-x86_64-icu-77.1-2-any.pkg.tar.zst"
)
FetchContent_Populate(ICU)
FetchContent_GetProperties(ICU SOURCE_DIR ICU_MINGW64_ROOT)
set(ICU_ROOT ${ICU_MINGW64_ROOT}/mingw64)
find_package(ICU REQUIRED COMPONENTS uc)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE ICU::uc)

It resulted in an error:
Do not know how to extract ‘local_repo/mingw-w64-x86_64-icu-77.1-2-any.pkg.tar.zst’
Known types are: .7z, .tar, .tar.bz2, .tar.gz, .tar.xz, .tbz2, .tgz

I tried changing the file extension to ‘.zip’, and it worked.

I also attempted modifying ${CMAKE_INSTALL_DIR}\share\cmake-4.0\Modules\ExternalProject\shared_internal_commands.cmake as follows, and it also worked:

function(_ep_write_extractfile_script
  script_filename
  name
  filename
  directory
  options
)
  set(args "")

  if(filename MATCHES
#    "(\\.|=)(7z|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$") # DELETED
    "(\\.|=)(7z|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zst|zip)$") # NEW LINE
    set(args xfz)
  endif()

  if(filename MATCHES "(\\.|=)tar$")
    set(args xf)
  endif()

  if(args STREQUAL "")
    message(FATAL_ERROR
      "Do not know how to extract '${filename}' -- known types are: "
      ".7z, .tar, .tar.bz2, .tar.gz, .tar.xz, .tbz2, .tgz, .txz and .zip"
    )
  endif()

  configure_file(
    "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/extractfile.cmake.in"
    "${script_filename}"
    @ONLY
  )
endfunction()

Therefore, I suggest that CMake should officially add support for the ‘.zst’ extension.

Please try the CMake 4.1.0 release candidate. A change has already been made to ExternalProject (which FetchContent uses for its implementation) so that it looks at the file’s content rather than the file extension to work out the format. Any format that cmake -E tar supports can now be used with ExternalProject and FetchContent. The change was made in MR 10715.

2 Likes