1 # Copyright (C) 2018-2019 Intel Corporation
2 # SPDX-License-Identifier: Apache-2.0
6 include ("download_and_check")
8 function (GetNameAndUrlToDownload name url archive_name_unified archive_name_win archive_name_lin archive_name_mac)
9 if (archive_name_unified)
10 set (${url} "${archive_name_unified}" PARENT_SCOPE)
11 set (${name} ${archive_name_unified} PARENT_SCOPE)
13 if (LINUX OR (APPLE AND NOT archive_name_mac))
14 if (NOT archive_name_lin)
17 set (PLATFORM_FOLDER linux)
18 set (archive_name ${archive_name_lin})
20 if (NOT archive_name_mac)
23 set (PLATFORM_FOLDER mac)
24 set (archive_name ${archive_name_mac})
26 #if no dependency for target platfrom skip it
27 if (NOT archive_name_win)
30 set (PLATFORM_FOLDER windows)
31 set (archive_name ${archive_name_win})
34 set (${name} ${archive_name} PARENT_SCOPE)
35 set (${url} "${archive_name}" PARENT_SCOPE)
37 endfunction(GetNameAndUrlToDownload)
39 #download from paltform specific folder from share server
40 function (DownloadAndExtractPlatformSpecific
50 GetNameAndUrlToDownload(archive_name RELATIVE_URL ${archive_name_unified} ${archive_name_win} ${archive_name_lin} ${archive_name_mac} )
51 if (NOT archive_name OR NOT RELATIVE_URL)
54 CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} result_path2 ${folder} TRUE FALSE TRUE)
55 set (${result_path} ${result_path2} PARENT_SCOPE)
57 endfunction(DownloadAndExtractPlatformSpecific)
59 #download from common folder
60 function (DownloadAndExtract component archive_name unpacked_path result_path folder)
61 set (RELATIVE_URL "${archive_name}")
63 CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} result_path2 ${folder} ${fattal} result TRUE)
66 DownloadAndExtractPlatformSpecific(${component} ${archive_name} ${archive_name} ${archive_name} ${unpacked_path} ${result_path2} ${folder})
69 set (${result_path} ${result_path2} PARENT_SCOPE)
71 endfunction(DownloadAndExtract)
74 function (DownloadAndExtractInternal URL archive_path unpacked_path folder fattal result123)
76 DownloadAndCheck(${URL} ${archive_path} ${fattal} result1)
77 if ("${result1}" STREQUAL "ARCHIVE_DOWNLOAD_FAIL")
78 #check alternative url as well
80 file(REMOVE_RECURSE "${archive_path}")
83 if ("${result1}" STREQUAL "CHECKSUM_DOWNLOAD_FAIL" OR "${result1}" STREQUAL "HASH_MISMATCH")
85 file(REMOVE_RECURSE "${archive_path}")
88 if("${status}" STREQUAL "ON")
89 ExtractWithVersion(${URL} ${archive_path} ${unpacked_path} ${folder} result)
92 set (result123 ${status} PARENT_SCOPE)
94 endfunction(DownloadAndExtractInternal)
96 function (ExtractWithVersion URL archive_path unpacked_path folder result)
98 debug_message("ExtractWithVersion : ${archive_path} : ${unpacked_path}")
99 extract(${archive_path} ${unpacked_path} ${folder} status)
100 #dont need archive actually after unpacking
101 file(REMOVE_RECURSE "${archive_path}")
103 set (version_file ${unpacked_path}/ie_dependency.info)
104 file(WRITE ${version_file} ${URL})
106 file(REMOVE_RECURSE "${unpacked_path}")
108 set (${result} ${status} PARENT_SCOPE)
109 endfunction (ExtractWithVersion)
111 function (DownloadOrExtractInternal URL archive_path unpacked_path folder fattal result123)
112 debug_message("checking wether archive downloaded : ${archive_path}")
114 if (NOT EXISTS ${archive_path})
115 DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result)
118 if (ENABLE_UNSAFE_LOCATIONS)
119 ExtractWithVersion(${URL} ${archive_path} ${unpacked_path} ${folder} result)
121 DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result)
124 debug_message("archive found on FS : ${archive_path}, however we cannot check it's checksum and think that it is invalid")
125 file(REMOVE_RECURSE "${archive_path}")
126 DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result)
133 message(FATAL_ERROR "error: extract of '${archive_path}' failed")
136 endfunction(DownloadOrExtractInternal)
138 file(REMOVE ${CMAKE_BINARY_DIR}/dependencies_64.txt)
140 function (CheckOrDownloadAndExtract component RELATIVE_URL archive_name unpacked_path result_path folder fattal result123 use_alternatives)
141 set (archive_path ${TEMP}/download/${archive_name})
143 set (on_master FALSE)
145 if(DEFINED ENV{IE_PATH_TO_DEPS})
146 set(URL "$ENV{IE_PATH_TO_DEPS}/${RELATIVE_URL}")
148 if(DEFINED DEPENDENCIES_BASE_URL)
149 set(URL "${DEPENDENCIES_BASE_URL}/${RELATIVE_URL}")
151 set(URL "https://download.01.org/opencv/master/openvinotoolkit/2019_R4/inference_engine/${RELATIVE_URL}")
155 #no message on recursive calls
156 if (${use_alternatives})
157 set(DEP_INFO "${component}=${URL}")
158 debug_message (STATUS "DEPENDENCY_URL: ${DEP_INFO}")
159 file(APPEND ${CMAKE_BINARY_DIR}/dependencies_64.txt "${DEP_INFO}\n")
162 debug_message ("checking that unpacked directory exist: ${unpacked_path}")
164 if (NOT EXISTS ${unpacked_path})
165 DownloadOrExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} status)
166 else(NOT EXISTS ${unpacked_path})
167 #path exists, so we would like to check what was unpacked version
168 set (version_file ${unpacked_path}/ie_dependency.info)
170 if (DEFINED TEAMCITY_GIT_BRANCH)
171 if(${TEAMCITY_GIT_BRANCH} STREQUAL "master")
173 debug_message ("On master branch, update data in DL_SDK_TEMP if necessary")
177 if (NOT EXISTS ${version_file} AND NOT ${ENABLE_ALTERNATIVE_TEMP})
178 clean_message(FATAL_ERROR "error: Dependency doesn't contain version file. Please select actions: \n"
179 "if you are not sure about your FS dependency - remove it : \n"
180 "\trm -rf ${unpacked_path}\n"
182 "If your dependency is fine, then execute:\n\techo ${URL} > ${unpacked_path}/ie_dependency.info\n")
183 # file(REMOVE_RECURSE "${unpacked_path}")
184 # DownloadOrExtractInternal(${URL} ${archive_path} ${unpacked_path} ${fattal} status)
186 if (EXISTS ${version_file})
187 file(READ "${version_file}" dependency_url)
188 string(REGEX REPLACE "\n" ";" dependency_url "${dependency_url}")
189 #we have decided to stick each dependency to unique url that will be that record in version file
190 debug_message("dependency_info on FS : \"${dependency_url}\"\n"
191 "compare to : \"${URL}\"" )
193 debug_message("no version file available at ${version_file}")
196 if (NOT EXISTS ${version_file} OR NOT ${dependency_url} STREQUAL ${URL})
197 if (${use_alternatives} AND ALTERNATIVE_PATH AND NOT ${on_master})
198 #creating alternative_path
199 string(REPLACE ${TEMP} ${ALTERNATIVE_PATH} unpacked_path ${unpacked_path})
200 string(REPLACE ${TEMP} ${ALTERNATIVE_PATH} archive_path ${archive_path})
202 debug_message("dependency different: use local path for fetching updated version: ${alternative_path}")
203 CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} ${result_path} ${folder} ${fattal} ${result123} FALSE)
206 debug_message("dependency updated: download it again")
207 file(REMOVE_RECURSE "${unpacked_path}")
208 DownloadOrExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} status)
214 if (${use_alternatives} OR ${on_master})
215 set (${result123} "${status}" PARENT_SCOPE)
216 set (${result_path} ${unpacked_path} PARENT_SCOPE)
221 endfunction(CheckOrDownloadAndExtract)