1 # Copyright (C) 2018-2019 Intel Corporation
3 # SPDX-License-Identifier: Apache-2.0
7 include ("download_and_check")
9 function (GetNameAndUrlToDownload name url archive_name_unified archive_name_win archive_name_lin archive_name_mac)
10 if (archive_name_unified)
11 set (${url} "${archive_name_unified}" PARENT_SCOPE)
12 set (${name} ${archive_name_unified} PARENT_SCOPE)
14 if (LINUX OR (APPLE AND NOT archive_name_mac))
15 if (NOT archive_name_lin)
18 set (PLATFORM_FOLDER linux)
19 set (archive_name ${archive_name_lin})
21 if (NOT archive_name_mac)
24 set (PLATFORM_FOLDER mac)
25 set (archive_name ${archive_name_mac})
27 #if no dependency for target platfrom skip it
28 if (NOT archive_name_win)
31 set (PLATFORM_FOLDER windows)
32 set (archive_name ${archive_name_win})
35 set (${name} ${archive_name} PARENT_SCOPE)
36 set (${url} "${archive_name}" PARENT_SCOPE)
38 endfunction(GetNameAndUrlToDownload)
40 #download from paltform specific folder from share server
41 function (DownloadAndExtractPlatformSpecific
51 GetNameAndUrlToDownload(archive_name RELATIVE_URL ${archive_name_unified} ${archive_name_win} ${archive_name_lin} ${archive_name_mac} )
52 if (NOT archive_name OR NOT RELATIVE_URL)
55 CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} result_path2 ${folder} TRUE FALSE TRUE)
56 set (${result_path} ${result_path2} PARENT_SCOPE)
58 endfunction(DownloadAndExtractPlatformSpecific)
60 #download from common folder
61 function (DownloadAndExtract component archive_name unpacked_path result_path folder)
62 set (RELATIVE_URL "${archive_name}")
64 CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} result_path2 ${folder} ${fattal} result TRUE)
67 DownloadAndExtractPlatformSpecific(${component} ${archive_name} ${archive_name} ${archive_name} ${unpacked_path} ${result_path2} ${folder})
70 set (${result_path} ${result_path2} PARENT_SCOPE)
72 endfunction(DownloadAndExtract)
75 function (DownloadAndExtractInternal URL archive_path unpacked_path folder fattal result123)
77 DownloadAndCheck(${URL} ${archive_path} ${fattal} result1)
78 if ("${result1}" STREQUAL "ARCHIVE_DOWNLOAD_FAIL")
79 #check alternative url as well
81 file(REMOVE_RECURSE "${archive_path}")
84 if ("${result1}" STREQUAL "CHECKSUM_DOWNLOAD_FAIL" OR "${result1}" STREQUAL "HASH_MISMATCH")
86 file(REMOVE_RECURSE "${archive_path}")
89 if("${status}" STREQUAL "ON")
90 ExtractWithVersion(${URL} ${archive_path} ${unpacked_path} ${folder} result)
93 set (result123 ${status} PARENT_SCOPE)
95 endfunction(DownloadAndExtractInternal)
97 function (ExtractWithVersion URL archive_path unpacked_path folder result)
99 debug_message("ExtractWithVersion : ${archive_path} : ${unpacked_path}")
100 extract(${archive_path} ${unpacked_path} ${folder} status)
101 #dont need archive actually after unpacking
102 file(REMOVE_RECURSE "${archive_path}")
104 set (version_file ${unpacked_path}/ie_dependency.info)
105 file(WRITE ${version_file} ${URL})
107 file(REMOVE_RECURSE "${unpacked_path}")
109 set (${result} ${status} PARENT_SCOPE)
110 endfunction (ExtractWithVersion)
112 function (DownloadOrExtractInternal URL archive_path unpacked_path folder fattal result123)
113 debug_message("checking wether archive downloaded : ${archive_path}")
115 if (NOT EXISTS ${archive_path})
116 DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result)
119 if (ENABLE_UNSAFE_LOCATIONS)
120 ExtractWithVersion(${URL} ${archive_path} ${unpacked_path} ${folder} result)
122 DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result)
125 debug_message("archive found on FS : ${archive_path}, however we cannot check it's checksum and think that it is invalid")
126 file(REMOVE_RECURSE "${archive_path}")
127 DownloadAndExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} result)
134 message(FATAL_ERROR "error: extract of '${archive_path}' failed")
137 endfunction(DownloadOrExtractInternal)
139 file(REMOVE ${CMAKE_BINARY_DIR}/dependencies_64.txt)
141 function (CheckOrDownloadAndExtract component RELATIVE_URL archive_name unpacked_path result_path folder fattal result123 use_alternatives)
142 set (archive_path ${TEMP}/download/${archive_name})
144 set (on_master FALSE)
146 if(DEFINED ENV{IE_PATH_TO_DEPS})
147 set(URL "$ENV{IE_PATH_TO_DEPS}/${RELATIVE_URL}")
149 set(URL "https://download.01.org/opencv/2019/openvinotoolkit/R1/inference_engine/${RELATIVE_URL}")
152 #no message on recursive calls
153 if (${use_alternatives})
154 set(DEP_INFO "${component}=${URL}")
155 debug_message (STATUS "DEPENDENCY_URL: ${DEP_INFO}")
156 file(APPEND ${CMAKE_BINARY_DIR}/dependencies_64.txt "${DEP_INFO}\n")
159 debug_message ("checking that unpacked directory exist: ${unpacked_path}")
161 if (NOT EXISTS ${unpacked_path})
162 DownloadOrExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} status)
163 else(NOT EXISTS ${unpacked_path})
164 #path exists, so we would like to check what was unpacked version
165 set (version_file ${unpacked_path}/ie_dependency.info)
167 if (DEFINED TEAMCITY_GIT_BRANCH)
168 if(${TEAMCITY_GIT_BRANCH} STREQUAL "master")
170 debug_message ("On master branch, update data in DL_SDK_TEMP if necessary")
174 if (NOT EXISTS ${version_file} AND NOT ${ENABLE_ALTERNATIVE_TEMP})
175 clean_message(FATAL_ERROR "error: Dependency doesn't contain version file. Please select actions: \n"
176 "if you are not sure about your FS dependency - remove it : \n"
177 "\trm -rf ${unpacked_path}\n"
179 "If your dependency is fine, then execute:\n\techo ${URL} > ${unpacked_path}/ie_dependency.info\n")
180 # file(REMOVE_RECURSE "${unpacked_path}")
181 # DownloadOrExtractInternal(${URL} ${archive_path} ${unpacked_path} ${fattal} status)
183 if (EXISTS ${version_file})
184 file(READ "${version_file}" dependency_url)
185 string(REGEX REPLACE "\n" ";" dependency_url "${dependency_url}")
186 #we have decided to stick each dependency to unique url that will be that record in version file
187 debug_message("dependency_info on FS : \"${dependency_url}\"\n"
188 "compare to : \"${URL}\"" )
190 debug_message("no version file available at ${version_file}")
193 if (NOT EXISTS ${version_file} OR NOT ${dependency_url} STREQUAL ${URL})
194 if (${use_alternatives} AND ALTERNATIVE_PATH AND NOT ${on_master})
195 #creating alternative_path
196 string(REPLACE ${TEMP} ${ALTERNATIVE_PATH} unpacked_path ${unpacked_path})
197 string(REPLACE ${TEMP} ${ALTERNATIVE_PATH} archive_path ${archive_path})
199 debug_message("dependency different: use local path for fetching updated version: ${alternative_path}")
200 CheckOrDownloadAndExtract(${component} ${RELATIVE_URL} ${archive_name} ${unpacked_path} ${result_path} ${folder} ${fattal} ${result123} FALSE)
203 debug_message("dependency updated: download it again")
204 file(REMOVE_RECURSE "${unpacked_path}")
205 DownloadOrExtractInternal(${URL} ${archive_path} ${unpacked_path} ${folder} ${fattal} status)
211 if (${use_alternatives} OR ${on_master})
212 set (${result123} "${status}" PARENT_SCOPE)
213 set (${result_path} ${unpacked_path} PARENT_SCOPE)
218 endfunction(CheckOrDownloadAndExtract)