Open Source Computer Vision Library https://opencv.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
3.5 KiB

Merge pull request #21531 from fengyuentau:add_3rdparty_mirrors Support downloading 3rdparty resources from Gitcode & Gitlab-style mirrors * replace github.com with gitcode.net for ocv_download * replace raw.githubusercontent.com with gitcode.net for ocv_download * rename funtions and remove some comments * add options for custom mirrors, which simply replace domain github.com & githubusercontent.com * run ocv_init_download once; replace DL_URL with mirrored one when calling ocv_download * fix for empty download links when not using mirror * fix bugs: set(.. .. PARENT_SCOPE) for ocv_init_download; correct macro names for replace github archives and raw githubusercontent * adjusted mirror swapping impl: replace with mirrored link before each ocv_download; update md5sum for archives * fix a bug: macro invoked with incorrect arguments by non-set vars * enclose if statement * workable impl * shorten the var names of two key options * scalable implementation of downloading from mirror and using custom mirror * improve ocv_init_download help message * fix the different extracted directory name in case of ADE & TBB which are downloaded from release page * improve help message printing * Download ADE & TBB using commit ids instead of from release pages * support custom mirrors on downloading archives * improve hints * add missing parentheses * reset ocv_download calls * mirror support implementation using ocv_cmake_hook & ocv_cmake_hook_append * move ocv_init_download into cmake/OpenCVDownload.cmake * move ocv_cmake_hook before checking CMake cache * improve hints when not fetching as git repo * add WORKING_DIRECTORY in execute_process in ocv_init_download * use OPENCV_DOWNLOAD_MIRROR_ID * add custom.cmake for custom mirror * detect github origin * fix broken var name * download from github by default if custom tbb is set * add checksum checks for gitcode.cmake before replacing urls and checksums * add checksum checks for custom.cmake before replacing urls and checkusms * use description specify instead of set for messages in custom.cmake; use warning message for warnings * updates and fixes
3 years ago
# Gitlab-style mirror
# CMake scripts look for opencv/opencv_3rdparty,
# OAID/Tengine, 01org/tbb(oneAPI/oneTBB), opencv/ade
# from OPENCV_DOWNLOAD_MIRROR
ocv_update(OPENCV_DOWNLOAD_MIRROR_URL "")
# Tengine
ocv_update(TENGINE_PKG_MD5_CUSTOM "")
ocv_update(TENGINE_PKG_MD5_ORIGINAL 23f61ebb1dd419f1207d8876496289c5) # same as tengine_md5sum for TENGINE commit of e89cf8870de2ff0a80cfe626c0b52b2a16fb302e
# TBB
ocv_update(TBB_RELEASE_CUSTOM "")
ocv_update(TBB_PKG_NAME_CUSTOM "")
ocv_update(TBB_PKG_MD5_CUSTOM "")
ocv_update(TBB_PKG_MD5_ORIGINAL 5af6f6c2a24c2043e62e47205e273b1f) # same as OPENCV_TBB_RELEASE_MD5 for TBB release of v2020.2
# ADE
ocv_update(ADE_RELEASE_CUSTOM "")
ocv_update(ADE_PKG_NAME_CUSTOM "")
ocv_update(ADE_PKG_MD5_CUSTOM "")
ocv_update(ADE_PKG_MD5_ORIGINAL b624b995ec9c439cbc2e9e6ee940d3a2) # same as ade_md5 for ADE release of v0.1.1f
macro(ocv_download_url_custom_usercontent)
string(REPLACE "/" ";" DL_URL_split ${DL_URL})
list(GET DL_URL_split 5 __COMMIT_ID)
list(GET DL_URL_split 6 __PKG_NAME)
set(DL_URL "https://${OPENCV_DOWNLOAD_MIRROR_URL}/opencv/opencv_3rdparty/-/raw/${__COMMIT_ID}/${__PKG_NAME}/")
endmacro()
macro(ocv_download_url_custom_archive_commit_id)
if("m${${DL_ID}_PKG_MD5_CUSTOM}" STREQUAL "m")
message(WARNING "ocv_download: specify ${DL_ID}_PKG_MD5_CUSTOM to download ${DL_ID} from custom source.")
elseif(${DL_ID}_PKG_MD5_ORIGINAL STREQUAL "${DL_HASH}")
string(REPLACE "/" ";" DL_URL_split ${DL_URL})
list(GET DL_URL_split 3 __OWNER)
list(GET DL_URL_split 4 __REPO_NAME)
set(DL_URL "https://${OPENCV_DOWNLOAD_MIRROR_URL}/${__OWNER}/${__REPO_NAME}/-/archive/")
set(DL_HASH "${${DL_ID}_PKG_MD5_CUSTOM}")
else()
message(WARNING "No information about mirrors for downloading ${DL_FILENAME} from URL='${DL_URL}' and MD5=${DL_HASH}.")
endif()
endmacro()
macro(ocv_download_url_custom_archive_release)
if("m${${DL_ID}_RELEASE_CUSTOM}" STREQUAL "m")
message(WARNING "ocv_download: specify ${DL_ID}_RELEASE_CUSTOM to download ${DL_ID} from custom source.")
return()
endif()
if("m${${DL_ID}_PKG_NAME_CUSTOM}" STREQUAL "m")
message(WARNING "ocv_download: specify ${DL_ID}_PKG_NAME_CUSTOM to download ${DL_ID} from custom source.")
return()
endif()
if("m${${DL_ID}_PKG_MD5_CUSTOM}" STREQUAL "m")
message(WARNING "ocv_download: specify ${DL_ID}_PKG_MD5_CUSTOM to download ${DL_ID} from custom source.")
return()
endif()
string(REPLACE "/" ";" DL_URL_split ${DL_URL})
list(GET DL_URL_split 3 __OWNER)
list(GET DL_URL_split 4 __REPO_NAME)
set(DL_URL "https://${OPENCV_DOWNLOAD_MIRROR_URL}/${__OWNER}/${__REPO_NAME}/-/archive/${${DL_ID}_PKG_RELEASE_CUSTOM}/${__REPO_NAME}-")
set(DL_HASH "${${DL_ID}_PKG_MD5_CUSTOM}")
endmacro()
if("m${OPENCV_DOWNLOAD_MIRROR_URL}" STREQUAL "m")
message(WARNING "ocv_download: specify OPENCV_DOWNLOAD_MIRROR_URL to use custom mirror.")
else()
if((DL_ID STREQUAL "FFMPEG") OR (DL_ID STREQUAL "IPPICV"))
ocv_download_url_custom_usercontent()
elseif(DL_ID STREQUAL "TENGINE")
ocv_download_url_custom_archive_commit_id()
elseif(DL_ID STREQUAL "TBB")
ocv_download_url_custom_archive_release()
set(OPENCV_TBB_SUBDIR "${TBB_PKG_NAME_CUSTOM}" PARENT_SCOPE)
elseif(DL_ID STREQUAL "ADE")
ocv_download_url_custom_archive_release()
set(ade_subdir "${ADE_PKG_NAME_CUSTOM}" PARENT_SCOPE)
else()
message(STATUS "ocv_download: Unknown download ID ${DL_ID} for using mirror ${OPENCV_DOWNLOAD_MIRROR_URL}. Use original source instead.")
endif()
endif()