OpenCVFindIPPIW.cmake 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #
  2. # The script to detect Intel(R) Integrated Performance Primitives Integration Wrappers (IPP Integration Wrappers)
  3. # installation/package
  4. #
  5. #
  6. # On return this will define:
  7. #
  8. # HAVE_IPP_IW - True if Intel IPP Integration Wrappers found
  9. # HAVE_IPP_IW_LL - True if Intel IPP Integration Wrappers found with Low Level API header
  10. # IPP_IW_PATH - Root of Intel IPP Integration Wrappers directory
  11. # IPP_IW_LIBRARIES - Intel IPP Integration Wrappers libraries
  12. # IPP_IW_INCLUDES - Intel IPP Integration Wrappers include folder
  13. #
  14. unset(HAVE_IPP_IW CACHE)
  15. unset(HAVE_IPP_IW_LL CACHE)
  16. unset(IPP_IW_PATH)
  17. unset(IPP_IW_LIBRARIES)
  18. unset(IPP_IW_INCLUDES)
  19. unset(IW_CONFIG_DEBUG)
  20. #set(IW_CONFIG_DEBUG 1)
  21. if(NOT HAVE_IPP)
  22. return()
  23. endif()
  24. macro(ippiw_debugmsg MESSAGE)
  25. if(DEFINED IW_CONFIG_DEBUG)
  26. message(STATUS "${MESSAGE}")
  27. endif()
  28. endmacro()
  29. macro(ippiw_done)
  30. foreach(__file ${IPP_IW_LICENSE_FILES})
  31. if(EXISTS "${__file}")
  32. ocv_install_3rdparty_licenses(ippiw "${__file}")
  33. endif()
  34. endforeach()
  35. return()
  36. endmacro()
  37. file(TO_CMAKE_PATH "${IPPROOT}" IPPROOT)
  38. # This function detects Intel IPP Integration Wrappers version by analyzing .h file
  39. macro(ippiw_setup PATH BUILD)
  40. set(FILE "${PATH}/include/iw/iw_version.h")
  41. if(${BUILD})
  42. ippiw_debugmsg("Checking sources: ${PATH}")
  43. else()
  44. ippiw_debugmsg("Checking binaries: ${PATH}")
  45. endif()
  46. if(EXISTS "${FILE}")
  47. ippiw_debugmsg("vfile\tfound")
  48. file(STRINGS "${FILE}" IW_VERSION_MAJOR REGEX "IW_VERSION_MAJOR")
  49. file(STRINGS "${FILE}" IW_VERSION_MINOR REGEX "IW_VERSION_MINOR")
  50. file(STRINGS "${FILE}" IW_VERSION_UPDATE REGEX "IW_VERSION_UPDATE")
  51. file(STRINGS "${FILE}" IW_MIN_COMPATIBLE_IPP_MAJOR REGEX "IW_MIN_COMPATIBLE_IPP_MAJOR")
  52. file(STRINGS "${FILE}" IW_MIN_COMPATIBLE_IPP_MINOR REGEX "IW_MIN_COMPATIBLE_IPP_MINOR")
  53. file(STRINGS "${FILE}" IW_MIN_COMPATIBLE_IPP_UPDATE REGEX "IW_MIN_COMPATIBLE_IPP_UPDATE")
  54. string(REGEX MATCH "[0-9]+" IW_MIN_COMPATIBLE_IPP_MAJOR ${IW_MIN_COMPATIBLE_IPP_MAJOR})
  55. string(REGEX MATCH "[0-9]+" IW_MIN_COMPATIBLE_IPP_MINOR ${IW_MIN_COMPATIBLE_IPP_MINOR})
  56. string(REGEX MATCH "[0-9]+" IW_MIN_COMPATIBLE_IPP_UPDATE ${IW_MIN_COMPATIBLE_IPP_UPDATE})
  57. string(REGEX MATCH "[0-9]+" IW_VERSION_MAJOR ${IW_VERSION_MAJOR})
  58. string(REGEX MATCH "[0-9]+" IW_VERSION_MINOR ${IW_VERSION_MINOR})
  59. string(REGEX MATCH "[0-9]+" IW_VERSION_UPDATE ${IW_VERSION_UPDATE})
  60. math(EXPR IPP_VERSION_EXP "${IPP_VERSION_MAJOR}*10000 + ${IPP_VERSION_MINOR}*100 + ${IPP_VERSION_BUILD}")
  61. math(EXPR IW_MIN_COMPATIBLE_IPP_EXP "${IW_MIN_COMPATIBLE_IPP_MAJOR}*10000 + ${IW_MIN_COMPATIBLE_IPP_MINOR}*100 + ${IW_MIN_COMPATIBLE_IPP_UPDATE}")
  62. if((IPP_VERSION_EXP GREATER IW_MIN_COMPATIBLE_IPP_EXP) OR (IPP_VERSION_EXP EQUAL IW_MIN_COMPATIBLE_IPP_EXP))
  63. ippiw_debugmsg("vcheck\tpassed")
  64. if(${BUILD})
  65. # check sources
  66. if(EXISTS "${PATH}/src/iw_core.c")
  67. ippiw_debugmsg("sources\tyes")
  68. set(IPP_IW_PATH "${PATH}")
  69. message(STATUS "found Intel IPP Integration Wrappers sources: ${IW_VERSION_MAJOR}.${IW_VERSION_MINOR}.${IW_VERSION_UPDATE}")
  70. message(STATUS "at: ${IPP_IW_PATH}")
  71. set(IPP_IW_LIBRARY ippiw)
  72. set(IPP_IW_INCLUDES "${IPP_IW_PATH}/include")
  73. set(IPP_IW_LIBRARIES ${IPP_IW_LIBRARY})
  74. execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OpenCV_SOURCE_DIR}/3rdparty/ippicv/CMakeLists.txt" "${IPP_IW_PATH}/")
  75. add_subdirectory("${IPP_IW_PATH}/" ${OpenCV_BINARY_DIR}/3rdparty/ippiw)
  76. set(HAVE_IPP_IW 1)
  77. set(FILE "${PATH}/include/iw/iw_ll.h") # check if Intel IPP Integration Wrappers is OpenCV specific
  78. if(EXISTS "${FILE}")
  79. set(HAVE_IPP_IW_LL 1)
  80. endif()
  81. ippiw_done()
  82. else()
  83. ippiw_debugmsg("sources\tno")
  84. endif()
  85. else()
  86. # check binaries
  87. if(IPP_X64)
  88. set(FILE "${PATH}/lib/intel64/${CMAKE_STATIC_LIBRARY_PREFIX}ipp_iw${CMAKE_STATIC_LIBRARY_SUFFIX}")
  89. else()
  90. set(FILE "${PATH}/lib/ia32/${CMAKE_STATIC_LIBRARY_PREFIX}ipp_iw${CMAKE_STATIC_LIBRARY_SUFFIX}")
  91. endif()
  92. if(EXISTS ${FILE})
  93. ippiw_debugmsg("binaries\tyes (64=${IPP_X64})")
  94. set(IPP_IW_PATH "${PATH}")
  95. message(STATUS "found Intel IPP Integration Wrappers binaries: ${IW_VERSION_MAJOR}.${IW_VERSION_MINOR}.${IW_VERSION_UPDATE}")
  96. message(STATUS "at: ${IPP_IW_PATH}")
  97. add_library(ipp_iw STATIC IMPORTED)
  98. set_target_properties(ipp_iw PROPERTIES
  99. IMPORTED_LINK_INTERFACE_LIBRARIES ""
  100. IMPORTED_LOCATION "${FILE}"
  101. )
  102. if (NOT BUILD_SHARED_LIBS AND ";${OPENCV_INSTALL_EXTERNAL_DEPENDENCIES};" MATCHES ";ipp;")
  103. # CMake doesn't support "install(TARGETS ${name} ...)" command with imported targets
  104. install(FILES "${FILE}"
  105. DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
  106. set(IPPIW_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/${OPENCV_3P_LIB_INSTALL_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}ipp_iw${CMAKE_STATIC_LIBRARY_SUFFIX}" CACHE INTERNAL "" FORCE)
  107. set(IPPIW_LOCATION_PATH "${FILE}" CACHE INTERNAL "" FORCE)
  108. endif()
  109. set(IPP_IW_INCLUDES "${IPP_IW_PATH}/include")
  110. set(IPP_IW_LIBRARIES ipp_iw)
  111. set(HAVE_IPP_IW 1)
  112. set(BUILD_IPP_IW 0)
  113. set(FILE "${PATH}/include/iw/iw_ll.h") # check if Intel IPP Integration Wrappers is OpenCV specific
  114. if(EXISTS "${FILE}")
  115. set(HAVE_IPP_IW_LL 1)
  116. endif()
  117. ippiw_done()
  118. else()
  119. ippiw_debugmsg("binaries\tno")
  120. endif()
  121. endif()
  122. else()
  123. ippiw_debugmsg("vcheck\tfailed")
  124. endif()
  125. else()
  126. ippiw_debugmsg("vfile\tnot found")
  127. endif()
  128. set(HAVE_IPP_IW 0)
  129. set(HAVE_IPP_IW_LL 0)
  130. endmacro()
  131. # check build options first
  132. if(BUILD_IPP_IW)
  133. # custom path
  134. if(DEFINED IPPIWROOT)
  135. ippiw_setup("${IPPIWROOT}/" 1)
  136. message(STATUS "Can't find Intel IPP Integration Wrappers sources at: ${IPPIWROOT}")
  137. endif()
  138. # local sources
  139. ippiw_setup("${OpenCV_SOURCE_DIR}/3rdparty/ippiw" 1)
  140. set(IPPIW_ROOT "${IPPROOT}/../iw")
  141. set(IPP_IW_LICENSE_FILES ${IPP_IW_LICENSE_FILES_EXTRA}
  142. "${IPPIW_ROOT}/../support.txt"
  143. "${IPPIW_ROOT}/../third-party-programs.txt"
  144. "${IPPIW_ROOT}/../EULA.rtf"
  145. "${IPPIW_ROOT}/../EULA.txt"
  146. )
  147. # Package sources
  148. get_filename_component(__PATH "${IPPROOT}/../iw/" ABSOLUTE)
  149. ippiw_setup("${__PATH}" 1)
  150. # take Intel IPP Integration Wrappers from ICV package
  151. if(NOT HAVE_IPP_ICV)
  152. message(STATUS "Cannot find Intel IPP Integration Wrappers. Checking \"Intel IPP for OpenCV\" package")
  153. set(TEMP_ROOT 0)
  154. include("${OpenCV_SOURCE_DIR}/3rdparty/ippicv/ippicv.cmake")
  155. download_ippicv(TEMP_ROOT)
  156. set(IPPIW_ROOT "${TEMP_ROOT}/iw/")
  157. set(IPP_IW_LICENSE_FILES ${IPP_IW_LICENSE_FILES_EXTRA}
  158. "${IPPIW_ROOT}/../EULA.txt"
  159. "${IPPIW_ROOT}/../support.txt"
  160. "${IPPIW_ROOT}/../third-party-programs.txt"
  161. )
  162. ippiw_setup("${IPPIW_ROOT}" 1)
  163. endif()
  164. endif()
  165. # custom binaries
  166. if(DEFINED IPPIWROOT)
  167. ippiw_setup("${IPPIWROOT}/" 0)
  168. message(STATUS "Can't find Intel IPP Integration Wrappers binaries at: ${IPPIWROOT}")
  169. endif()
  170. # check binaries in IPP folder
  171. ippiw_setup("${IPPROOT}/" 0)
  172. # check binaries near IPP folder
  173. ippiw_setup("${IPPROOT}/../iw/" 0)
  174. set(HAVE_IPP_IW 0)
  175. set(HAVE_IPP_IW_LL 0)
  176. message(STATUS "Cannot find Intel IPP Integration Wrappers, optimizations will be limited. Use IPPIWROOT to set custom location")
  177. return()