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