1 # Copyright (C) 2018-2019 Intel Corporation
2 # SPDX-License-Identifier: Apache-2.0
7 function (DownloadAndCheck from to fatal result)
11 get_filename_component(download_dir ${to} DIRECTORY)
12 if (NOT EXISTS ${download_dir})
13 file(MAKE_DIRECTORY ${download_dir})
16 if(NOT EXISTS "${to}")
17 if (${from} MATCHES "(http:)|(https:)|(ftp:)")
18 message(STATUS "Downloading from ${from} to ${to} ...")
19 find_program(aria2c "aria2c")
20 if (${aria2c} STREQUAL "aria2c-NOTFOUND")
21 if (NOT ${WGET_FOUND})
22 Download(${from} ${to} ${fatal} ${result} output)
23 list(GET output 0 status_code)
25 message(STATUS "${WGET_EXECUTABLE} --no-cache ${from}")
26 execute_process(COMMAND ${WGET_EXECUTABLE} "--no-cache" "--no-check-certificate" "${from}" "-O" "${to}"
28 RESULT_VARIABLE status_code)
31 message(STATUS "${aria2c} ,*.*.*.* -d ${download_dir} ${from}")
32 execute_process(COMMAND "${aria2c}" "-s10" "-x10" "--dir=${download_dir}" "${from}"
34 RESULT_VARIABLE status_code)
37 if(NOT status_code EQUAL 0)
39 message(FATAL_ERROR "fatal error: downloading '${from}' failed
40 status_code: ${status_code}
41 status_string: ${status_string}
44 set(status_res "ARCHIVE_DOWNLOAD_FAIL")
45 message("error: downloading '${from}' failed
46 status_code: ${status_code}")
50 message(STATUS "Copying from local folder ${from} to ${to} ... ")
51 file(COPY ${from} DESTINATION ${download_dir})
55 file(REMOVE ${to}.md5)
56 set(${result} "${status_res}" PARENT_SCOPE)
58 endfunction(DownloadAndCheck)