2 # The script to detect Intel(R) Math Kernel Library (MKL)
8 # On return this will define:
10 # HAVE_MKL - True if Intel MKL found
11 # MKL_ROOT_DIR - root of MKL installation
12 # MKL_INCLUDE_DIRS - MKL include folder
13 # MKL_LIBRARIES - MKL libraries that are used by OpenCV
16 macro (mkl_find_lib VAR NAME DIRS)
17 find_path(${VAR} ${NAME} ${DIRS} NO_DEFAULT_PATH)
18 set(${VAR} ${${VAR}}/${NAME})
24 set(MKL_ROOT_DIR "${MKL_ROOT_DIR}" CACHE PATH "Path to MKL directory")
28 macro(get_mkl_version VERSION_FILE)
29 # read MKL version info from file
30 file(STRINGS ${VERSION_FILE} STR1 REGEX "__INTEL_MKL__")
31 file(STRINGS ${VERSION_FILE} STR2 REGEX "__INTEL_MKL_MINOR__")
32 file(STRINGS ${VERSION_FILE} STR3 REGEX "__INTEL_MKL_UPDATE__")
33 #file(STRINGS ${VERSION_FILE} STR4 REGEX "INTEL_MKL_VERSION")
35 # extract info and assign to variables
36 string(REGEX MATCHALL "[0-9]+" MKL_VERSION_MAJOR ${STR1})
37 string(REGEX MATCHALL "[0-9]+" MKL_VERSION_MINOR ${STR2})
38 string(REGEX MATCHALL "[0-9]+" MKL_VERSION_UPDATE ${STR3})
39 set(MKL_VERSION_STR "${MKL_VERSION_MAJOR}.${MKL_VERSION_MINOR}.${MKL_VERSION_UPDATE}" CACHE STRING "MKL version" FORCE)
43 if(NOT DEFINED MKL_USE_MULTITHREAD)
44 OCV_OPTION(MKL_WITH_TBB "Use MKL with TBB multithreading" OFF)#ON IF WITH_TBB)
45 OCV_OPTION(MKL_WITH_OPENMP "Use MKL with OpenMP multithreading" OFF)#ON IF WITH_OPENMP)
48 #check current MKL_ROOT_DIR
49 if(NOT MKL_ROOT_DIR OR NOT EXISTS "${MKL_ROOT_DIR}/include/mkl.h")
50 set(mkl_root_paths "${MKL_ROOT_DIR}")
51 if(DEFINED ENV{MKLROOT})
52 list(APPEND mkl_root_paths "$ENV{MKLROOT}")
55 if(WITH_MKL AND NOT mkl_root_paths)
57 set(ProgramFilesx86 "ProgramFiles(x86)")
58 list(APPEND mkl_root_paths $ENV{${ProgramFilesx86}}/IntelSWTools/compilers_and_libraries/windows/mkl)
61 list(APPEND mkl_root_paths "/opt/intel/mkl")
65 find_path(MKL_ROOT_DIR include/mkl.h PATHS ${mkl_root_paths})
68 set(MKL_INCLUDE_DIRS "${MKL_ROOT_DIR}/include" CACHE PATH "Path to MKL include directory")
71 OR NOT EXISTS "${MKL_ROOT_DIR}"
72 OR NOT EXISTS "${MKL_INCLUDE_DIRS}"
73 OR NOT EXISTS "${MKL_INCLUDE_DIRS}/mkl_version.h"
78 get_mkl_version(${MKL_INCLUDE_DIRS}/mkl_version.h)
81 if(CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8)
83 set(MKL_ARCH "intel64")
85 include(CheckTypeSize)
86 CHECK_TYPE_SIZE(int _sizeof_int)
87 if (_sizeof_int EQUAL 4)
88 set(MKL_ARCH_SUFFIX "lp64")
90 set(MKL_ARCH_SUFFIX "ilp64")
94 set(MKL_ARCH_SUFFIX "c")
97 if(MKL_VERSION_STR VERSION_GREATER "11.3.0" OR MKL_VERSION_STR VERSION_EQUAL "11.3.0")
98 set(mkl_lib_find_paths
100 ${MKL_ROOT_DIR}/lib/${MKL_ARCH} ${MKL_ROOT_DIR}/../tbb/lib/${MKL_ARCH})
102 set(mkl_lib_list "mkl_intel_${MKL_ARCH_SUFFIX}")
105 list(APPEND mkl_lib_list mkl_tbb_thread tbb)
106 elseif(MKL_WITH_OPENMP)
108 list(APPEND mkl_lib_list mkl_intel_thread libiomp5md)
110 list(APPEND mkl_lib_list mkl_gnu_thread)
113 list(APPEND mkl_lib_list mkl_sequential)
116 list(APPEND mkl_lib_list mkl_core)
118 message(STATUS "MKL version ${MKL_VERSION_STR} is not supported")
122 set(MKL_LIBRARIES "")
123 foreach(lib ${mkl_lib_list})
124 find_library(${lib} ${lib} ${mkl_lib_find_paths})
125 mark_as_advanced(${lib})
129 list(APPEND MKL_LIBRARIES ${${lib}})
132 message(STATUS "Found MKL ${MKL_VERSION_STR} at: ${MKL_ROOT_DIR}")
134 set(MKL_ROOT_DIR "${MKL_ROOT_DIR}" CACHE PATH "Path to MKL directory")
135 set(MKL_INCLUDE_DIRS "${MKL_INCLUDE_DIRS}" CACHE PATH "Path to MKL include directory")
136 set(MKL_LIBRARIES "${MKL_LIBRARIES}" CACHE STRING "MKL libarries")
137 if(UNIX AND NOT MKL_LIBRARIES_DONT_HACK)
138 #it's ugly but helps to avoid cyclic lib problem
139 set(MKL_LIBRARIES ${MKL_LIBRARIES} ${MKL_LIBRARIES} ${MKL_LIBRARIES} "-lpthread" "-lm" "-ldl")