aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--third-party/cmake/DownloadAndExtractFile.cmake75
1 files changed, 41 insertions, 34 deletions
diff --git a/third-party/cmake/DownloadAndExtractFile.cmake b/third-party/cmake/DownloadAndExtractFile.cmake
index e008fa8a8a..abb1ddc81a 100644
--- a/third-party/cmake/DownloadAndExtractFile.cmake
+++ b/third-party/cmake/DownloadAndExtractFile.cmake
@@ -59,41 +59,48 @@ string(REPLACE ";" "-" fname "${fname}")
set(file ${DOWNLOAD_DIR}/${fname})
message(STATUS "file: ${file}")
-message(STATUS "downloading...
- src='${URL}'
- dst='${file}'
- timeout='${timeout_msg}'")
-
-file(DOWNLOAD ${URL} ${file}
- ${timeout_args}
- ${hash_args}
- STATUS status
- LOG log)
-
-list(GET status 0 status_code)
-list(GET status 1 status_string)
-
-if(NOT status_code EQUAL 0)
- # Retry on certain errors, e.g. CURLE_COULDNT_RESOLVE_HOST, which is often
- # seen with libtermkey (www.leonerd.org.uk).
- if((status_code EQUAL 6) # "Couldn't resolve host name"
- OR (status_code EQUAL 7)) # "Couldn't connect to server"
- message(STATUS "warning: retrying '${URL}' (${status_string}, status ${status_code})")
- execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 10)
- file(DOWNLOAD ${URL} ${file}
- ${timeout_args}
- ${hash_args}
- STATUS status
- LOG log)
- list(GET status 0 status_code)
- list(GET status 1 status_string)
- endif()
+set(EXISTING_SHA256 "")
+if(EXISTS ${file})
+ file(SHA256 ${file} EXISTING_SHA256)
+endif()
+
+if(NOT EXISTING_SHA256 STREQUAL ${EXPECTED_SHA256})
+ message(STATUS "downloading...
+ src='${URL}'
+ dst='${file}'
+ timeout='${timeout_msg}'")
+
+ file(DOWNLOAD ${URL} ${file}
+ ${timeout_args}
+ ${hash_args}
+ STATUS status
+ LOG log)
+
+ list(GET status 0 status_code)
+ list(GET status 1 status_string)
+
if(NOT status_code EQUAL 0)
- message(FATAL_ERROR "error: downloading '${URL}' failed
- status_code: ${status_code}
- status_string: ${status_string}
- log: ${log}
-")
+ # Retry on certain errors, e.g. CURLE_COULDNT_RESOLVE_HOST, which is often
+ # seen with libtermkey (www.leonerd.org.uk).
+ if((status_code EQUAL 6) # "Couldn't resolve host name"
+ OR (status_code EQUAL 7)) # "Couldn't connect to server"
+ message(STATUS "warning: retrying '${URL}' (${status_string}, status ${status_code})")
+ execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 10)
+ file(DOWNLOAD ${URL} ${file}
+ ${timeout_args}
+ ${hash_args}
+ STATUS status
+ LOG log)
+ list(GET status 0 status_code)
+ list(GET status 1 status_string)
+ endif()
+ if(NOT status_code EQUAL 0)
+ message(FATAL_ERROR "error: downloading '${URL}' failed
+ status_code: ${status_code}
+ status_string: ${status_string}
+ log: ${log}
+ ")
+ endif()
endif()
endif()