1 # Copyright (C) 2018-2019 Intel Corporation
3 # SPDX-License-Identifier: Apache-2.0
8 function (DownloadAndCheck from to fatal result)
12 get_filename_component(download_dir ${to} DIRECTORY)
13 if (NOT EXISTS ${download_dir})
14 file(MAKE_DIRECTORY ${download_dir})
17 if(NOT EXISTS "${to}")
18 if (${from} MATCHES "(http:)|(https:)|(ftp:)")
19 message(STATUS "Downloading from ${from} to ${to} ...")
20 find_program(aria2c "aria2c")
21 if (${aria2c} STREQUAL "aria2c-NOTFOUND")
22 if (NOT ${WGET_FOUND})
23 Download(${from} ${to} ${fatal} ${result} output)
24 list(GET output 0 status_code)
26 message(STATUS "${WGET_EXECUTABLE} --no-cache ${from}")
27 execute_process(COMMAND ${WGET_EXECUTABLE} "--no-cache" "--no-check-certificate" "${from}" "-O" "${to}"
29 RESULT_VARIABLE status_code)
32 message(STATUS "${aria2c} ,*.*.*.* -d ${download_dir} ${from}")
33 execute_process(COMMAND "${aria2c}" "-s10" "-x10" "--dir=${download_dir}" "${from}"
35 RESULT_VARIABLE status_code)
38 if(NOT status_code EQUAL 0)
40 message(FATAL_ERROR "fatal error: downloading '${from}' failed
41 status_code: ${status_code}
42 status_string: ${status_string}
45 set(status_res "ARCHIVE_DOWNLOAD_FAIL")
46 message("error: downloading '${from}' failed
47 status_code: ${status_code}")
51 message(STATUS "Copying from local folder ${from} to ${to} ... ")
52 file(COPY ${from} DESTINATION ${download_dir})
56 file(REMOVE ${to}.md5)
57 set(${result} "${status_res}" PARENT_SCOPE)
59 endfunction(DownloadAndCheck)