Merge pull request #3063 from akarsakov:ocl_warps_check
[profile/ivi/opencv.git] / cmake / OpenCVFindIPP.cmake
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_ONLY - 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
27 unset(HAVE_IPP CACHE)
28 unset(HAVE_IPP_ICV_ONLY)
29 unset(IPP_ROOT_DIR)
30 unset(IPP_INCLUDE_DIRS)
31 unset(IPP_LIBRARIES)
32 unset(IPP_VERSION_STR)
33 unset(IPP_VERSION_MAJOR)
34 unset(IPP_VERSION_MINOR)
35 unset(IPP_VERSION_BUILD)
36
37 set(IPP_LIB_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX})
38 set(IPP_LIB_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})
39
40 set(IPP_X64 0)
41 if(CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8)
42     set(IPP_X64 1)
43 endif()
44 if(CMAKE_CL_64)
45     set(IPP_X64 1)
46 endif()
47
48 # This function detects IPP version by analyzing .h file
49 macro(ipp_get_version VERSION_FILE)
50   unset(_VERSION_STR)
51   unset(_MAJOR)
52   unset(_MINOR)
53   unset(_BUILD)
54
55   # read IPP version info from file
56   file(STRINGS ${VERSION_FILE} STR1 REGEX "IPP_VERSION_MAJOR")
57   file(STRINGS ${VERSION_FILE} STR2 REGEX "IPP_VERSION_MINOR")
58   file(STRINGS ${VERSION_FILE} STR3 REGEX "IPP_VERSION_BUILD")
59   if("${STR3}" STREQUAL "")
60     file(STRINGS ${VERSION_FILE} STR3 REGEX "IPP_VERSION_UPDATE")
61   endif()
62   file(STRINGS ${VERSION_FILE} STR4 REGEX "IPP_VERSION_STR")
63
64   # extract info and assign to variables
65   string(REGEX MATCHALL "[0-9]+" _MAJOR ${STR1})
66   string(REGEX MATCHALL "[0-9]+" _MINOR ${STR2})
67   string(REGEX MATCHALL "[0-9]+" _BUILD ${STR3})
68   string(REGEX MATCHALL "[0-9]+[.]+[0-9]+[^\"]+|[0-9]+[.]+[0-9]+" _VERSION_STR ${STR4})
69
70   # export info to parent scope
71   set(IPP_VERSION_STR   ${_VERSION_STR})
72   set(IPP_VERSION_MAJOR ${_MAJOR})
73   set(IPP_VERSION_MINOR ${_MINOR})
74   set(IPP_VERSION_BUILD ${_BUILD})
75 endmacro()
76
77 macro(_ipp_not_supported)
78   message(STATUS ${ARGN})
79   unset(HAVE_IPP)
80   unset(HAVE_IPP_ICV_ONLY)
81   unset(IPP_VERSION_STR)
82   return()
83 endmacro()
84
85 # This macro uses IPP_ROOT_DIR variable
86 # TODO Cleanup code after ICV package stabilization
87 macro(ipp_detect_version)
88   set(IPP_INCLUDE_DIRS ${IPP_ROOT_DIR}/include)
89
90   set(__msg)
91   if(EXISTS ${IPP_ROOT_DIR}/include/ippicv_redefs.h)
92     set(__msg " (ICV version)")
93     set(HAVE_IPP_ICV_ONLY 1)
94   elseif(EXISTS ${IPP_ROOT_DIR}/include/ipp.h)
95     # nothing
96   else()
97     _ipp_not_supported("Can't resolve IPP directory: ${IPP_ROOT_DIR}")
98   endif()
99
100   ipp_get_version(${IPP_INCLUDE_DIRS}/ippversion.h)
101   ocv_assert(IPP_VERSION_STR VERSION_GREATER "1.0")
102
103   message(STATUS "found IPP${__msg}: ${_MAJOR}.${_MINOR}.${_BUILD} [${IPP_VERSION_STR}]")
104   message(STATUS "at: ${IPP_ROOT_DIR}")
105
106   if(${IPP_VERSION_STR} VERSION_LESS "7.0")
107     _ipp_not_supported("IPP ${IPP_VERSION_STR} is not supported")
108   endif()
109
110   set(HAVE_IPP 1)
111
112   macro(_ipp_set_library_dir DIR)
113     if(NOT EXISTS ${DIR})
114       _ipp_not_supported("IPP library directory not found")
115     endif()
116     set(IPP_LIBRARY_DIR ${DIR})
117   endmacro()
118
119   if(APPLE)
120     _ipp_set_library_dir(${IPP_ROOT_DIR}/lib)
121   elseif(IPP_X64)
122     _ipp_set_library_dir(${IPP_ROOT_DIR}/lib/intel64)
123   else()
124     _ipp_set_library_dir(${IPP_ROOT_DIR}/lib/ia32)
125   endif()
126
127   macro(_ipp_add_library name)
128     if (EXISTS ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX})
129       add_library(ipp${name} STATIC IMPORTED)
130       set_target_properties(ipp${name} PROPERTIES
131         IMPORTED_LINK_INTERFACE_LIBRARIES ""
132         IMPORTED_LOCATION ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
133       )
134       list(APPEND IPP_LIBRARIES ipp${name})
135       # CMake doesn't support "install(TARGETS ipp${name} " command with imported targets
136       install(FILES ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}
137               DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main)
138       string(TOUPPER ${name} uname)
139       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)
140       set(IPP${uname}_LOCATION_PATH "${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}" CACHE INTERNAL "" FORCE)
141     else()
142       message(STATUS "Can't find IPP library: ${name} at ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}")
143     endif()
144   endmacro()
145
146   set(IPP_PREFIX "ipp")
147   if(${IPP_VERSION_STR} VERSION_LESS "8.0")
148     set(IPP_SUFFIX "_l")      # static not threaded libs suffix IPP 7.x
149   else()
150     if(WIN32)
151       set(IPP_SUFFIX "mt")    # static not threaded libs suffix IPP 8.x for Windows
152     else()
153       set(IPP_SUFFIX "")      # static not threaded libs suffix IPP 8.x for Linux/OS X
154     endif()
155   endif()
156
157   if(HAVE_IPP_ICV_ONLY)
158     _ipp_add_library(icv)
159   else()
160     _ipp_add_library(core)
161     _ipp_add_library(s)
162     _ipp_add_library(i)
163     _ipp_add_library(cc)
164     _ipp_add_library(cv)
165     _ipp_add_library(vm)
166     _ipp_add_library(m)
167
168     if(UNIX)
169       get_filename_component(INTEL_COMPILER_LIBRARY_DIR ${IPP_ROOT_DIR}/../lib REALPATH)
170       if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR})
171         get_filename_component(INTEL_COMPILER_LIBRARY_DIR ${IPP_ROOT_DIR}/../compiler/lib REALPATH)
172       endif()
173       if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR})
174         _ipp_not_supported("IPP configuration error: can't find Intel compiler library dir ${INTEL_COMPILER_LIBRARY_DIR}")
175       endif()
176       if(NOT APPLE)
177         if(IPP_X64)
178           if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/intel64)
179             message(SEND_ERROR "Intel compiler EM64T libraries not found")
180           endif()
181           set(INTEL_COMPILER_LIBRARY_DIR ${INTEL_COMPILER_LIBRARY_DIR}/intel64)
182         else()
183           if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/ia32)
184             message(SEND_ERROR "Intel compiler IA32 libraries not found")
185           endif()
186           set(INTEL_COMPILER_LIBRARY_DIR ${INTEL_COMPILER_LIBRARY_DIR}/ia32)
187         endif()
188       endif()
189
190       macro(_ipp_add_compiler_library name)
191         if (EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/${IPP_LIB_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX})
192           list(APPEND IPP_LIBRARIES ${INTEL_COMPILER_LIBRARY_DIR}/${IPP_LIB_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX})
193         else()
194           message(STATUS "Can't find compiler library: ${name}")
195         endif()
196       endmacro()
197
198       _ipp_add_compiler_library(irc)
199       _ipp_add_compiler_library(imf)
200       _ipp_add_compiler_library(svml)
201     endif(UNIX)
202   endif()
203
204   #message(STATUS "IPP libs: ${IPP_LIBRARIES}")
205 endmacro()
206
207 # OPENCV_IPP_PATH is an environment variable for internal usage only, do not use it
208 if(DEFINED ENV{OPENCV_IPP_PATH} AND NOT DEFINED IPPROOT)
209   set(IPPROOT "$ENV{OPENCV_IPP_PATH}")
210 endif()
211 if(NOT DEFINED IPPROOT)
212   include("${OpenCV_SOURCE_DIR}/3rdparty/ippicv/downloader.cmake")
213   if(DEFINED OPENCV_ICV_PATH)
214     set(IPPROOT "${OPENCV_ICV_PATH}")
215   else()
216     return()
217   endif()
218 endif()
219
220 file(TO_CMAKE_PATH "${IPPROOT}" __IPPROOT)
221 if(EXISTS "${__IPPROOT}/include/ippversion.h")
222   set(IPP_ROOT_DIR ${__IPPROOT})
223   ipp_detect_version()
224 endif()
225
226
227 if(WIN32 AND MINGW AND NOT IPP_VERSION_MAJOR LESS 7)
228     # Since IPP built with Microsoft compiler and /GS option
229     # ======================================================
230     # From Windows SDK 7.1
231     #   (usually in "C:\Program Files\Microsoft Visual Studio 10.0\VC\lib"),
232     # to avoid undefined reference to __security_cookie and _chkstk:
233     set(MSV_RUNTMCHK "RunTmChk")
234     set(IPP_LIBRARIES ${IPP_LIBRARIES} ${MSV_RUNTMCHK}${IPP_LIB_SUFFIX})
235
236     # To avoid undefined reference to _alldiv and _chkstk
237     # ===================================================
238     # NB: it may require a recompilation of w32api (after having modified
239     #     the file ntdll.def) to export the required functions
240     #     See http://code.opencv.org/issues/1906 for additional details
241     set(MSV_NTDLL    "ntdll")
242     set(IPP_LIBRARIES ${IPP_LIBRARIES} ${MSV_NTDLL}${IPP_LIB_SUFFIX})
243 endif()