CMake file(ARCHIVE_EXTRACT) syntax

CMake file(ARCHIVE_EXTRACT), is more robust and easy to use than the command-line cmake -E tar syntax when within a CMakeLists.txt file. The option PATTERNS_EXCLUDE saves time and disk space by skipping the extraction of files that are not needed, such as documentation files.

cmake_minimum_required(VERSION 3.18)

if(CMAKE_VERSION VERSION_GREATER_EQUAL 4.5)
  set(_pat_excl_docs PATTERNS_EXCLUDE "docs/*")
endif()

file(ARCHIVE_EXTRACT
  INPUT ${archive}
  DESTINATION ${out_dir}
  ${_pat_excl_docs}
)