OpenCVFindIPP.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. #
  2. # The script to detect Intel(R) Integrated Performance Primitives (IPP)
  3. # installation/package
  4. #
  5. # By default, ICV version will be used.
  6. # To use standalone IPP update cmake command line:
  7. # cmake ... -DIPPROOT=<path> ...
  8. #
  9. # Note: Backward compatibility is broken, IPPROOT environment path is ignored
  10. #
  11. #
  12. # On return this will define:
  13. #
  14. # HAVE_IPP - True if Intel IPP found
  15. # HAVE_IPP_ICV - True if Intel IPP ICV version is available
  16. # IPP_ROOT_DIR - root of IPP installation
  17. # IPP_INCLUDE_DIRS - IPP include folder
  18. # IPP_LIBRARIES - IPP libraries that are used by OpenCV
  19. # IPP_VERSION_STR - string with the newest detected IPP version
  20. # IPP_VERSION_MAJOR - numbers of IPP version (MAJOR.MINOR.BUILD)
  21. # IPP_VERSION_MINOR
  22. # IPP_VERSION_BUILD
  23. #
  24. # Created: 30 Dec 2010 by Vladimir Dudnik (vladimir.dudnik@intel.com)
  25. #
  26. unset(HAVE_IPP CACHE)
  27. unset(HAVE_IPP_ICV)
  28. unset(IPP_ROOT_DIR)
  29. unset(IPP_INCLUDE_DIRS)
  30. unset(IPP_LIBRARIES)
  31. unset(IPP_VERSION_STR)
  32. unset(IPP_VERSION_MAJOR)
  33. unset(IPP_VERSION_MINOR)
  34. unset(IPP_VERSION_BUILD)
  35. if (X86 AND UNIX AND NOT APPLE AND NOT ANDROID AND BUILD_SHARED_LIBS)
  36. message(STATUS "On 32-bit Linux Intel IPP can not currently be used with dynamic libs because of linker errors. Set BUILD_SHARED_LIBS=OFF")
  37. return()
  38. endif()
  39. set(IPP_X64 0)
  40. if(X86_64)
  41. set(IPP_X64 1)
  42. endif()
  43. # This function detects Intel IPP version by analyzing .h file
  44. macro(ipp_get_version VERSION_FILE)
  45. unset(_VERSION_STR)
  46. unset(_MAJOR)
  47. unset(_MINOR)
  48. unset(_BUILD)
  49. # read Intel IPP version info from file
  50. file(STRINGS ${VERSION_FILE} STR1 REGEX "IPP_VERSION_MAJOR")
  51. file(STRINGS ${VERSION_FILE} STR2 REGEX "IPP_VERSION_MINOR")
  52. file(STRINGS ${VERSION_FILE} STR3 REGEX "IPP_VERSION_BUILD")
  53. if("${STR3}" STREQUAL "")
  54. file(STRINGS ${VERSION_FILE} STR3 REGEX "IPP_VERSION_UPDATE")
  55. endif()
  56. file(STRINGS ${VERSION_FILE} STR4 REGEX "IPP_VERSION_STR")
  57. # extract info and assign to variables
  58. string(REGEX MATCHALL "[0-9]+" _MAJOR ${STR1})
  59. string(REGEX MATCHALL "[0-9]+" _MINOR ${STR2})
  60. string(REGEX MATCHALL "[0-9]+" _BUILD ${STR3})
  61. string(REGEX MATCHALL "[0-9]+[.]+[0-9]+[^\"]+|[0-9]+[.]+[0-9]+" _VERSION_STR ${STR4})
  62. # export info to parent scope
  63. set(IPP_VERSION_STR ${_VERSION_STR})
  64. set(IPP_VERSION_MAJOR ${_MAJOR})
  65. set(IPP_VERSION_MINOR ${_MINOR})
  66. set(IPP_VERSION_BUILD ${_BUILD})
  67. endmacro()
  68. macro(_ipp_not_supported)
  69. message(STATUS ${ARGN})
  70. unset(HAVE_IPP)
  71. unset(HAVE_IPP_ICV)
  72. unset(IPP_VERSION_STR)
  73. return()
  74. endmacro()
  75. # This macro uses IPP_ROOT_DIR variable
  76. # TODO Cleanup code after ICV package stabilization
  77. macro(ipp_detect_version)
  78. set(IPP_INCLUDE_DIRS ${IPP_ROOT_DIR}/include)
  79. set(__msg)
  80. if(EXISTS ${IPP_ROOT_DIR}/include/ippicv_redefs.h)
  81. set(__msg " (ICV version)")
  82. set(HAVE_IPP_ICV 1)
  83. elseif(EXISTS ${IPP_ROOT_DIR}/include/ipp.h)
  84. # nothing
  85. else()
  86. _ipp_not_supported("Can't resolve Intel IPP directory: ${IPP_ROOT_DIR}")
  87. endif()
  88. ipp_get_version(${IPP_INCLUDE_DIRS}/ippversion.h)
  89. ocv_assert(IPP_VERSION_STR VERSION_GREATER "1.0")
  90. message(STATUS "found Intel IPP${__msg}: ${_MAJOR}.${_MINOR}.${_BUILD} [${IPP_VERSION_STR}]")
  91. message(STATUS "at: ${IPP_ROOT_DIR}")
  92. if(IPP_VERSION_STR VERSION_LESS "7.0")
  93. _ipp_not_supported("Intel IPP ${IPP_VERSION_STR} is not supported")
  94. endif()
  95. set(HAVE_IPP 1)
  96. macro(_ipp_set_library_dir DIR)
  97. if(NOT EXISTS ${DIR})
  98. _ipp_not_supported("Intel IPP library directory not found")
  99. endif()
  100. set(IPP_LIBRARY_DIR ${DIR})
  101. endmacro()
  102. if(APPLE AND NOT HAVE_IPP_ICV)
  103. _ipp_set_library_dir(${IPP_ROOT_DIR}/lib)
  104. elseif(IPP_X64)
  105. _ipp_set_library_dir(${IPP_ROOT_DIR}/lib/intel64)
  106. else()
  107. _ipp_set_library_dir(${IPP_ROOT_DIR}/lib/ia32)
  108. endif()
  109. macro(_ipp_add_library name)
  110. # dynamic linking is only supported for standalone version of Intel IPP
  111. if (BUILD_WITH_DYNAMIC_IPP AND NOT HAVE_IPP_ICV)
  112. if (WIN32)
  113. set(IPP_LIB_PREFIX ${CMAKE_IMPORT_LIBRARY_PREFIX})
  114. set(IPP_LIB_SUFFIX ${CMAKE_IMPORT_LIBRARY_SUFFIX})
  115. else (WIN32)
  116. set(IPP_LIB_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX})
  117. set(IPP_LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
  118. endif (WIN32)
  119. else ()
  120. set(IPP_LIB_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX})
  121. set(IPP_LIB_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
  122. endif ()
  123. if (EXISTS ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX})
  124. if (BUILD_WITH_DYNAMIC_IPP AND NOT HAVE_IPP_ICV)
  125. # When using dynamic libraries from standalone Intel IPP it is your responsibility to install those on the target system
  126. list(APPEND IPP_LIBRARIES ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX})
  127. else ()
  128. add_library(ipp${name} STATIC IMPORTED)
  129. set(_filename "${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}")
  130. set_target_properties(ipp${name} PROPERTIES
  131. IMPORTED_LINK_INTERFACE_LIBRARIES ""
  132. IMPORTED_LOCATION ${IPP_LIBRARY_DIR}/${_filename}
  133. )
  134. if("${name}" STREQUAL "core") # https://github.com/opencv/opencv/pull/19681
  135. if(OPENCV_FORCE_IPP_EXCLUDE_LIBS OR OPENCV_FORCE_IPP_EXCLUDE_LIBS_CORE
  136. OR (UNIX AND NOT ANDROID AND NOT APPLE
  137. AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|Intel"
  138. )
  139. AND NOT OPENCV_SKIP_IPP_EXCLUDE_LIBS_CORE
  140. )
  141. if(CMAKE_VERSION VERSION_LESS "3.13.0")
  142. set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--exclude-libs,${_filename} ${CMAKE_SHARED_LINKER_FLAGS}")
  143. else()
  144. target_link_options(ipp${name} INTERFACE "LINKER:--exclude-libs,${_filename}")
  145. endif()
  146. endif()
  147. endif()
  148. list(APPEND IPP_LIBRARIES ipp${name})
  149. if (NOT BUILD_SHARED_LIBS AND (HAVE_IPP_ICV OR ";${OPENCV_INSTALL_EXTERNAL_DEPENDENCIES};" MATCHES ";ipp;"))
  150. # CMake doesn't support "install(TARGETS ${IPP_PREFIX}${name} " command with imported targets
  151. install(FILES ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
  152. DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
  153. string(TOUPPER ${name} uname)
  154. set(IPP${uname}_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/${OPENCV_3P_LIB_INSTALL_PATH}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}" CACHE INTERNAL "" FORCE)
  155. set(IPP${uname}_LOCATION_PATH "${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}" CACHE INTERNAL "" FORCE)
  156. endif()
  157. endif()
  158. else()
  159. message(STATUS "Can't find Intel IPP library: ${name} at ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}")
  160. endif()
  161. endmacro()
  162. set(IPP_PREFIX "ipp")
  163. if(IPP_VERSION_STR VERSION_LESS "8.0")
  164. if (BUILD_WITH_DYNAMIC_IPP AND NOT HAVE_IPP_ICV)
  165. set(IPP_SUFFIX "") # dynamic not threaded libs suffix Intel IPP 7.x
  166. else ()
  167. set(IPP_SUFFIX "_l") # static not threaded libs suffix Intel IPP 7.x
  168. endif ()
  169. else ()
  170. if(WIN32)
  171. if (BUILD_WITH_DYNAMIC_IPP AND NOT HAVE_IPP_ICV)
  172. set(IPP_SUFFIX "") # dynamic not threaded libs suffix Intel IPP 8.x for Windows
  173. else ()
  174. set(IPP_SUFFIX "mt") # static not threaded libs suffix Intel IPP 8.x for Windows
  175. endif ()
  176. else()
  177. set(IPP_SUFFIX "") # static not threaded libs suffix Intel IPP 8.x for Linux/OS X
  178. endif()
  179. endif()
  180. if(HAVE_IPP_ICV)
  181. _ipp_add_library(icv)
  182. else()
  183. _ipp_add_library(cv)
  184. _ipp_add_library(i)
  185. _ipp_add_library(cc)
  186. _ipp_add_library(s)
  187. _ipp_add_library(vm)
  188. _ipp_add_library(core)
  189. if(UNIX AND IPP_VERSION_MAJOR LESS 2017)
  190. get_filename_component(INTEL_COMPILER_LIBRARY_DIR ${IPP_ROOT_DIR}/../lib REALPATH)
  191. if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR})
  192. get_filename_component(INTEL_COMPILER_LIBRARY_DIR ${IPP_ROOT_DIR}/../compiler/lib REALPATH)
  193. endif()
  194. if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR})
  195. _ipp_not_supported("Intel IPP configuration error: can't find Intel compiler library dir ${INTEL_COMPILER_LIBRARY_DIR}")
  196. endif()
  197. if(NOT APPLE)
  198. if(IPP_X64)
  199. if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/intel64)
  200. message(SEND_ERROR "Intel compiler EM64T libraries not found")
  201. endif()
  202. set(INTEL_COMPILER_LIBRARY_DIR ${INTEL_COMPILER_LIBRARY_DIR}/intel64)
  203. else()
  204. if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/ia32)
  205. message(SEND_ERROR "Intel compiler IA32 libraries not found")
  206. endif()
  207. set(INTEL_COMPILER_LIBRARY_DIR ${INTEL_COMPILER_LIBRARY_DIR}/ia32)
  208. endif()
  209. endif()
  210. macro(_ipp_add_compiler_library name)
  211. if (EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/${IPP_LIB_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX})
  212. list(APPEND IPP_LIBRARIES ${INTEL_COMPILER_LIBRARY_DIR}/${IPP_LIB_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX})
  213. else()
  214. message(STATUS "Can't find compiler library: ${name} at ${INTEL_COMPILER_LIBRARY_DIR}/${IPP_LIB_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
  215. endif()
  216. endmacro()
  217. _ipp_add_compiler_library(irc)
  218. _ipp_add_compiler_library(imf)
  219. _ipp_add_compiler_library(svml)
  220. endif()
  221. endif()
  222. #message(STATUS "Intel IPP libs: ${IPP_LIBRARIES}")
  223. endmacro()
  224. # OPENCV_IPP_PATH is an environment variable for internal usage only, do not use it
  225. if(DEFINED ENV{OPENCV_IPP_PATH} AND NOT DEFINED IPPROOT)
  226. set(IPPROOT "$ENV{OPENCV_IPP_PATH}")
  227. endif()
  228. if(NOT DEFINED IPPROOT)
  229. if(APPLE AND NOT IPP_X64)
  230. message(STATUS "IPPICV: 32-bit binaries are not supported on Apple platform (MacOSX)")
  231. return()
  232. endif()
  233. include("${OpenCV_SOURCE_DIR}/3rdparty/ippicv/ippicv.cmake")
  234. download_ippicv(ICV_PACKAGE_ROOT)
  235. if(NOT ICV_PACKAGE_ROOT)
  236. return()
  237. endif()
  238. set(IPPROOT "${ICV_PACKAGE_ROOT}/icv")
  239. ocv_install_3rdparty_licenses(ippicv "${IPPROOT}/readme.htm")
  240. if(WIN32)
  241. ocv_install_3rdparty_licenses(ippicv "${ICV_PACKAGE_ROOT}/EULA.rtf")
  242. else()
  243. ocv_install_3rdparty_licenses(ippicv "${ICV_PACKAGE_ROOT}/EULA.txt")
  244. endif()
  245. ocv_install_3rdparty_licenses(ippicv "${ICV_PACKAGE_ROOT}/third-party-programs.txt")
  246. endif()
  247. file(TO_CMAKE_PATH "${IPPROOT}" __IPPROOT)
  248. if(EXISTS "${__IPPROOT}/include/ippversion.h")
  249. set(IPP_ROOT_DIR ${__IPPROOT})
  250. ipp_detect_version()
  251. endif()
  252. if(WIN32 AND MINGW AND NOT IPP_VERSION_MAJOR LESS 7)
  253. # Since Intel IPP built with Microsoft compiler and /GS option
  254. # ======================================================
  255. # From Windows SDK 7.1
  256. # (usually in "C:\Program Files\Microsoft Visual Studio 10.0\VC\lib"),
  257. # to avoid undefined reference to __security_cookie and _chkstk:
  258. set(MSV_RUNTMCHK "RunTmChk")
  259. set(IPP_LIBRARIES ${IPP_LIBRARIES} ${MSV_RUNTMCHK}${IPP_LIB_SUFFIX})
  260. # To avoid undefined reference to _alldiv and _chkstk
  261. # ===================================================
  262. # NB: it may require a recompilation of w32api (after having modified
  263. # the file ntdll.def) to export the required functions
  264. # See http://code.opencv.org/issues/1906 for additional details
  265. set(MSV_NTDLL "ntdll")
  266. set(IPP_LIBRARIES ${IPP_LIBRARIES} ${MSV_NTDLL}${IPP_LIB_SUFFIX})
  267. endif()