1 # Copyright (C) 2018 Intel Corporation
3 # SPDX-License-Identifier: Apache-2.0
6 cmake_minimum_required (VERSION 2.8)
8 include ("download_and_check")
10 function (GetNameAndUrlToDownload name url archive_name_unified archive_name_win archive_name_lin archive_name_mac)
11 if (archive_name_unified)
12 set (${url} "${archive_name_unified}" PARENT_SCOPE)
13 set (${name} ${archive_name_unified} PARENT_SCOPE)
15 if (LINUX OR (APPLE AND NOT archive_name_mac))
16 if (NOT archive_name_lin)
19 set (PLATFORM_FOLDER linux)
20 set (archive_name ${archive_name_lin})
22 if (NOT archive_name_mac)
25 set (PLATFORM_FOLDER mac)
26 set (archive_name ${archive_name_mac})
28 #if no dependency for target platfrom skip it
29 if (NOT archive_name_win)
32 set (PLATFORM_FOLDER windows)
33 set (archive_name ${archive_name_win})
36 set (${name} ${archive_name} PARENT_SCOPE)
37 set (${url} "${archive_name}" PARENT_SCOPE)
39 endfunction(GetNameAndUrlToDownload)
41 #download from paltform specific folder from share server
42 function (DownloadAndExtractPlatformSpecific
52 GetNameAndUrlToDownload(archive_name RELATIVE_URL ${archive_name_unified} ${archive_name_win} ${archive_name_lin} ${archive_name_mac} )
53 if (NOT archive_name OR NOT RELATIVE_URL)
56 CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} result_path2 ${folder} TRUE FALSE TRUE)
57 set (${result_path} ${result_path2} PARENT_SCOPE)
59 endfunction(DownloadAndExtractPlatformSpecific)
61 #download from common folder
62 function (DownloadAndExtract component archive_name unpacked_path result_path folder)
63 set (RELATIVE_URL "${archive_name}")
65 CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} result_path2 ${folder} ${fattal} result TRUE)
68 DownloadAndExtractPlatformSpecific(${component} ${archive_name} ${archive_name} ${archive_name} ${unpacked_path} ${result_path2} ${folder})
71 set (${result_path} ${result_path2} PARENT_SCOPE)
73 endfunction(DownloadAndExtract)
76 function (DownloadAndExtractInternal URL archive_path unpacked_path folder fattal result123)
78 DownloadAndCheck(${URL} ${archive_path} ${fattal} result1)
79 if ("${result1}" STREQUAL "ARCHIVE_DOWNLOAD_FAIL")
80 #check alternative url as well
82 file(REMOVE_RECURSE "${archive_path}")
85 if ("${result1}" STREQUAL "CHECKSUM_DOWNLOAD_FAIL" OR "${result1}" STREQUAL "HASH_MISMATCH")
87 file(REMOVE_RECURSE "${archive_path}")
90 if("${status}" STREQUAL "ON")
91 ExtractWithVersion(${URL} ${archive_path} ${unpacked_path} ${folder} result)
94 set (result123 ${status} PARENT_SCOPE)
96 endfunction(DownloadAndExtractInternal)
98 function (ExtractWithVersion URL archive_path unpacked_path folder result)
100 debug_message("ExtractWithVersion : ${archive_path} : ${unpacked_path}")
101 extract(${archive_path} ${unpacked_path} ${folder} status)
102 #dont need archive actually after unpacking
103 file(REMOVE_RECURSE "${archive_path}")
105 set (version_file ${unpacked_path}/ie_dependency.info)
106 file(WRITE ${version_file} ${URL})
108 file(REMOVE_RECURSE "${unpacked_path}")
110 set (${result} ${status} PARENT_SCOPE)
111 endfunction (ExtractWithVersion)
113 function (DownloadOrExtractInternal URL archive_path unpacked_path folder fattal result123)
114 debug_message("checking wether archive downloaded : ${archive_path}")
116 if (NOT EXISTS ${archive_path})
117 DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result)
120 if (ENABLE_UNSAFE_LOCATIONS)
121 ExtractWithVersion(${URL} ${archive_path} ${unpacked_path} ${folder} result)
123 DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result)
126 debug_message("archive found on FS : ${archive_path}, however we cannot check it's checksum and think that it is invalid")
127 file(REMOVE_RECURSE "${archive_path}")
128 DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result)
135 message(FATAL_ERROR "error: extract of '${archive_path}' failed")
138 endfunction(DownloadOrExtractInternal)
140 file(REMOVE ${CMAKE_BINARY_DIR}/dependencies_64.txt)
142 function (CheckOrDownloadAndExtract component RELATIVE_URL archive_name unpacked_path result_path folder fattal result123 use_alternatives)
143 set (archive_path ${TEMP}/download/${archive_name})
145 set (on_master FALSE)
147 set (URL "https://download.01.org/openvinotoolkit/2018_R3/dldt/inference_engine/${RELATIVE_URL}")
149 #no message on recursive calls
150 if (${use_alternatives})
151 set(DEP_INFO "${component}=${URL}")
152 debug_message (STATUS "DEPENDENCY_URL: ${DEP_INFO}")
153 file(APPEND ${CMAKE_BINARY_DIR}/dependencies_64.txt "${DEP_INFO}\n")
156 debug_message ("checking that unpacked directory exist: ${unpacked_path}")
158 if (NOT EXISTS ${unpacked_path})
159 DownloadOrExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} status)
160 else(NOT EXISTS ${unpacked_path})
161 #path exists, so we would like to check what was unpacked version
162 set (version_file ${unpacked_path}/ie_dependency.info)
164 if (DEFINED TEAMCITY_GIT_BRANCH)
165 if(${TEAMCITY_GIT_BRANCH} STREQUAL "master")
167 debug_message ("On master branch, update data in DL_SDK_TEMP if necessary")
171 if (NOT EXISTS ${version_file} AND NOT ${ENABLE_ALTERNATIVE_TEMP})
172 clean_message(FATAL_ERROR "error: Dependency doesn't contain version file. Please select actions: \n"
173 "if you are not sure about your FS dependency - remove it : \n"
174 "\trm -rf ${unpacked_path}\n"
176 "If your dependency is fine, then execute:\n\techo ${URL} > ${unpacked_path}/ie_dependency.info\n")
177 # file(REMOVE_RECURSE "${unpacked_path}")
178 # DownloadOrExtractInternal(${URL} ${archive_path} ${unpacked_path} ${fattal} status)
180 if (EXISTS ${version_file})
181 file(READ "${version_file}" dependency_url)
182 string(REGEX REPLACE "\n" ";" dependency_url "${dependency_url}")
183 #we have decided to stick each dependency to unique url that will be that record in version file
184 debug_message("dependency_info on FS : \"${dependency_url}\"\n"
185 "compare to : \"${URL}\"" )
187 debug_message("no version file available at ${version_file}")
190 if (NOT EXISTS ${version_file} OR NOT ${dependency_url} STREQUAL ${URL})
191 if (${use_alternatives} AND ALTERNATIVE_PATH AND NOT ${on_master})
192 #creating alternative_path
193 string(REPLACE ${TEMP} ${ALTERNATIVE_PATH} unpacked_path ${unpacked_path})
194 string(REPLACE ${TEMP} ${ALTERNATIVE_PATH} archive_path ${archive_path})
196 debug_message("dependency different: use local path for fetching updated version: ${alternative_path}")
197 CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} ${result_path} ${folder} ${fattal} ${result123} FALSE)
200 debug_message("dependency updated: download it again")
201 file(REMOVE_RECURSE "${unpacked_path}")
202 DownloadOrExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} status)
208 if (${use_alternatives} OR ${on_master})
209 set (${result123} "${status}" PARENT_SCOPE)
210 set (${result_path} ${unpacked_path} PARENT_SCOPE)
215 endfunction(CheckOrDownloadAndExtract)