Last active
August 3, 2023 05:54
-
-
Save jcfr/e9a281f71b48f52ca6a5ebb903533d62 to your computer and use it in GitHub Desktop.
This file was created while investigating issue associated with https://discourse.slicer.org/t/vs2019-build-problem-please-help/30863
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-FileCopyrightText: Copyright 2023 Kitware, Inc. and Contributors | |
# SPDX-License-Identifier: BSD-3-Clause | |
# Adapted from https://github.com/Kitware/CMake/blob/v3.27.1/Modules/ExternalProject/download.cmake.in | |
function(check_file_hash filepath expected_value) | |
if("${filepath}" STREQUAL "") | |
message(FATAL_ERROR "filepath Can't be empty") | |
endif() | |
if("${expected_value}" STREQUAL "") | |
message(FATAL_ERROR "expected_value Can't be empty") | |
endif() | |
message(STATUS "Verifying file... | |
file='${filepath}'") | |
file("SHA512" "${filepath}" actual_value) | |
if(NOT "${actual_value}" STREQUAL "${expected_value}") | |
message(FATAL_ERROR "SHA512 hash of | |
${filepath} | |
does not match expected value | |
expected: '${expected_value}' | |
actual: '${actual_value}'") | |
endif() | |
message(STATUS "Verifying file... - ok") | |
endfunction() | |
function(slicer_check_cmake_https_download url sha512) | |
set(dest "${CMAKE_CURRENT_BINARY_DIR}/slicer_check_cmake_https_download") | |
if(EXISTS ${dest}) | |
set(msg "Removing '${dest}'") | |
message(STATUS "${msg}") | |
file(REMOVE ${dest}) | |
message(STATUS "${msg} - ok") | |
endif() | |
# Download | |
set(msg "Checking if CMake https download works for '${url}'") | |
message(STATUS "${msg}") | |
file( | |
DOWNLOAD | |
${url} | |
${dest} | |
SHOW_PROGRESS | |
STATUS status | |
) | |
list(GET status 0 error_code) | |
if(error_code) | |
list(GET status 1 error_msg) | |
message(FATAL_ERROR "error: ${error_msg}") | |
endif() | |
message(STATUS "${msg} - ok") | |
message(STATUS "") | |
# Verify | |
check_file_hash(${dest} ${sha512}) | |
# Cleanup | |
file(REMOVE ${dest}) | |
endfunction() | |
slicer_check_cmake_https_download( | |
"https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tgz" | |
"3dc9e6a470a0922bad4856db02bc82cc4174f7a94e355fd0ed8cf9bbfd82dcf0b09d854aa482fe70ed441919a526d49e74658222279b5a25b4aa4fa171f65e9c" | |
) | |
#slicer_check_cmake_https_download( | |
# "https://github.com/Slicer/SlicerBinaryDependencies/releases/download/swig/swigwin-4.0.2.zip" | |
# "b8f105f9b9db6acc1f6e3741990915b533cd1bc206eb9645fd6836457fd30789b7229d2e3219d8e35f2390605ade0fbca493ae162ec3b4bc4e428b57155db03d" | |
# ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
Download the script
SlicerCheckCMakeHTTPSDownload.cmake
Run using CMake
Expected output