1# 2# The script downloads ICV package 3# 4# On return this will define: 5# OPENCV_ICV_PATH - path to unpacked downloaded package 6# 7 8function(_icv_downloader) 9 # Define actual ICV versions 10 if(APPLE) 11 set(OPENCV_ICV_PACKAGE_NAME "ippicv_macosx_20141027.tgz") 12 set(OPENCV_ICV_PACKAGE_HASH "9662fe0694a67e59491a0dcc82fa26e0") 13 set(OPENCV_ICV_PLATFORM "macosx") 14 set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_osx") 15 elseif(UNIX) 16 if(ANDROID AND (NOT ANDROID_ABI STREQUAL x86)) 17 return() 18 endif() 19 set(OPENCV_ICV_PACKAGE_NAME "ippicv_linux_20141027.tgz") 20 set(OPENCV_ICV_PACKAGE_HASH "8b449a536a2157bcad08a2b9f266828b") 21 set(OPENCV_ICV_PLATFORM "linux") 22 set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_lnx") 23 elseif(WIN32 AND NOT ARM) 24 set(OPENCV_ICV_PACKAGE_NAME "ippicv_windows_20141027.zip") 25 set(OPENCV_ICV_PACKAGE_HASH "b59f865d1ba16e8c84124e19d78eec57") 26 set(OPENCV_ICV_PLATFORM "windows") 27 set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_win") 28 else() 29 return() # Not supported 30 endif() 31 32 set(OPENCV_ICV_UNPACK_PATH "${CMAKE_CURRENT_LIST_DIR}/unpack") 33 set(OPENCV_ICV_PATH "${OPENCV_ICV_UNPACK_PATH}${OPENCV_ICV_PACKAGE_SUBDIR}") 34 35 if(DEFINED OPENCV_ICV_PACKAGE_DOWNLOADED 36 AND OPENCV_ICV_PACKAGE_DOWNLOADED STREQUAL OPENCV_ICV_PACKAGE_HASH 37 AND EXISTS ${OPENCV_ICV_PATH}) 38 # Package has been downloaded and checked by the previous build 39 set(OPENCV_ICV_PATH "${OPENCV_ICV_PATH}" PARENT_SCOPE) 40 return() 41 else() 42 if(EXISTS ${OPENCV_ICV_UNPACK_PATH}) 43 message(STATUS "ICV: Removing previous unpacked package: ${OPENCV_ICV_UNPACK_PATH}") 44 file(REMOVE_RECURSE ${OPENCV_ICV_UNPACK_PATH}) 45 endif() 46 endif() 47 unset(OPENCV_ICV_PACKAGE_DOWNLOADED CACHE) 48 49 set(OPENCV_ICV_PACKAGE_ARCHIVE "${CMAKE_CURRENT_LIST_DIR}/downloads/${OPENCV_ICV_PLATFORM}-${OPENCV_ICV_PACKAGE_HASH}/${OPENCV_ICV_PACKAGE_NAME}") 50 get_filename_component(OPENCV_ICV_PACKAGE_ARCHIVE_DIR "${OPENCV_ICV_PACKAGE_ARCHIVE}" PATH) 51 if(EXISTS "${OPENCV_ICV_PACKAGE_ARCHIVE}") 52 file(MD5 "${OPENCV_ICV_PACKAGE_ARCHIVE}" archive_md5) 53 if(NOT archive_md5 STREQUAL OPENCV_ICV_PACKAGE_HASH) 54 message(WARNING "ICV: Local copy of ICV package has invalid MD5 hash: ${archive_md5} (expected: ${OPENCV_ICV_PACKAGE_HASH})") 55 file(REMOVE "${OPENCV_ICV_PACKAGE_ARCHIVE}") 56 file(REMOVE_RECURSE "${OPENCV_ICV_PACKAGE_ARCHIVE_DIR}") 57 endif() 58 endif() 59 60 if(NOT EXISTS "${OPENCV_ICV_PACKAGE_ARCHIVE}") 61 if(NOT DEFINED OPENCV_ICV_URL) 62 if(DEFINED ENV{OPENCV_ICV_URL}) 63 set(OPENCV_ICV_URL $ENV{OPENCV_ICV_URL}) 64 else() 65 set(OPENCV_ICV_URL "http://sourceforge.net/projects/opencvlibrary/files/3rdparty/ippicv") 66 endif() 67 endif() 68 69 file(MAKE_DIRECTORY ${OPENCV_ICV_PACKAGE_ARCHIVE_DIR}) 70 message(STATUS "ICV: Downloading ${OPENCV_ICV_PACKAGE_NAME}...") 71 file(DOWNLOAD "${OPENCV_ICV_URL}/${OPENCV_ICV_PACKAGE_NAME}" "${OPENCV_ICV_PACKAGE_ARCHIVE}" 72 TIMEOUT 600 STATUS __status 73 EXPECTED_MD5 ${OPENCV_ICV_PACKAGE_HASH}) 74 if(NOT __status EQUAL 0) 75 message(FATAL_ERROR "ICV: Failed to download ICV package: ${OPENCV_ICV_PACKAGE_NAME}. Status=${__status}") 76 else() 77 # Don't remove this code, because EXPECTED_MD5 parameter doesn't fail "file(DOWNLOAD)" step 78 # on wrong hash 79 file(MD5 "${OPENCV_ICV_PACKAGE_ARCHIVE}" archive_md5) 80 if(NOT archive_md5 STREQUAL OPENCV_ICV_PACKAGE_HASH) 81 message(FATAL_ERROR "ICV: Downloaded copy of ICV package has invalid MD5 hash: ${archive_md5} (expected: ${OPENCV_ICV_PACKAGE_HASH})") 82 endif() 83 endif() 84 endif() 85 86 ocv_assert(EXISTS "${OPENCV_ICV_PACKAGE_ARCHIVE}") 87 ocv_assert(NOT EXISTS "${OPENCV_ICV_UNPACK_PATH}") 88 file(MAKE_DIRECTORY ${OPENCV_ICV_UNPACK_PATH}) 89 ocv_assert(EXISTS "${OPENCV_ICV_UNPACK_PATH}") 90 91 message(STATUS "ICV: Unpacking ${OPENCV_ICV_PACKAGE_NAME} to ${OPENCV_ICV_UNPACK_PATH}...") 92 execute_process(COMMAND ${CMAKE_COMMAND} -E tar xz "${OPENCV_ICV_PACKAGE_ARCHIVE}" 93 WORKING_DIRECTORY "${OPENCV_ICV_UNPACK_PATH}" 94 RESULT_VARIABLE __result) 95 96 if(NOT __result EQUAL 0) 97 message(FATAL_ERROR "ICV: Failed to unpack ICV package from ${OPENCV_ICV_PACKAGE_ARCHIVE} to ${OPENCV_ICV_UNPACK_PATH} with error ${__result}") 98 endif() 99 100 ocv_assert(EXISTS "${OPENCV_ICV_PATH}") 101 102 set(OPENCV_ICV_PACKAGE_DOWNLOADED "${OPENCV_ICV_PACKAGE_HASH}" CACHE INTERNAL "ICV package hash") 103 104 message(STATUS "ICV: Package successfully downloaded") 105 set(OPENCV_ICV_PATH "${OPENCV_ICV_PATH}" PARENT_SCOPE) 106endfunction() 107 108_icv_downloader() 109