Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / cmake / download_and_check.cmake
1 # Copyright (C) 2018-2019 Intel Corporation
2 #
3 # SPDX-License-Identifier: Apache-2.0
4 #
5
6 include (FindWget)
7
8 function (DownloadAndCheck from to fatal result)
9   set(status_res "ON")
10   set(output 1)
11
12   get_filename_component(download_dir ${to} DIRECTORY)
13   if (NOT EXISTS ${download_dir})
14     file(MAKE_DIRECTORY ${download_dir})
15   endif()
16
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)
25         else()
26           message(STATUS "${WGET_EXECUTABLE} --no-cache ${from}")
27           execute_process(COMMAND ${WGET_EXECUTABLE} "--no-cache" "--no-check-certificate" "${from}" "-O" "${to}"
28             TIMEOUT 2000
29             RESULT_VARIABLE status_code)
30         endif()
31       else()
32         message(STATUS "${aria2c} ,*.*.*.* -d ${download_dir} ${from}")
33         execute_process(COMMAND "${aria2c}" "-s10" "-x10" "--dir=${download_dir}" "${from}"
34             TIMEOUT 2000
35             RESULT_VARIABLE status_code)
36       endif()
37
38       if(NOT status_code EQUAL 0)
39         if (fatal)
40           message(FATAL_ERROR "fatal error: downloading '${from}' failed
41             status_code: ${status_code}
42             status_string: ${status_string}
43             log: ${log}")
44         else()
45           set(status_res "ARCHIVE_DOWNLOAD_FAIL")
46           message("error: downloading '${from}' failed
47             status_code: ${status_code}")
48         endif()
49       endif()
50     else()
51       message(STATUS "Copying from local folder ${from} to ${to} ... ")
52       file(COPY ${from} DESTINATION ${download_dir})
53     endif()
54   endif()
55
56   file(REMOVE ${to}.md5)
57   set(${result} "${status_res}" PARENT_SCOPE)
58
59 endfunction(DownloadAndCheck)