Meta: Add a tar extraction CMake wrapper

This is a copy of the zip wrapper adopted for tar archives.
This commit is contained in:
kleines Filmröllchen 2023-01-09 23:40:39 +01:00 committed by Linus Groh
parent 1ee2091b2d
commit a6dd992ad3
Notes: sideshowbarker 2024-07-17 18:49:10 +09:00

View file

@ -267,3 +267,18 @@ function(extract_path dest_dir zip_path source_path dest_path)
endif()
endif()
endfunction()
function(extract_tar_path dest_dir tar_path source_path dest_path)
if (EXISTS "${tar_path}" AND NOT EXISTS "${dest_path}")
if (CMAKE_VERSION VERSION_LESS 3.18.0)
message(STATUS "Extracting using ${TAR_TOOL} ${source_path} from ${tar_path}")
execute_process(COMMAND "${TAR_TOOL}" -xf "${tar_path}" -C "${dest_dir}" "${source_path}" RESULT_VARIABLE untar_result)
if (NOT untar_result EQUAL 0)
message(FATAL_ERROR "Failed to untar ${source_path} from ${tar_path} with status ${untar_result}")
endif()
else()
message(STATUS "Extracting using cmake ${source_path}")
file(ARCHIVE_EXTRACT INPUT "${tar_path}" DESTINATION "${dest_dir}" PATTERNS "${source_path}")
endif()
endif()
endfunction()