1 macro(_find_header_file_in_dirs VAR NAME)
4 if(" ${ARGN}" STREQUAL " ")
5 check_include_file("${NAME}" HAVE_${VAR})
7 set(${VAR} "${NAME}") # fallback
12 find_path(${VAR} "${NAME}" ${ARGN} NO_DEFAULT_PATH)
14 set(${VAR} "${${VAR}}/${NAME}")
23 macro(ocv_lapack_check)
24 string(REGEX REPLACE "[^a-zA-Z0-9_]" "_" _lapack_impl "${LAPACK_IMPL}")
25 message(STATUS "LAPACK(${LAPACK_IMPL}): LAPACK_LIBRARIES: ${LAPACK_LIBRARIES}")
26 _find_header_file_in_dirs(OPENCV_CBLAS_H_PATH_${_lapack_impl} "${LAPACK_CBLAS_H}" "${LAPACK_INCLUDE_DIR}")
27 _find_header_file_in_dirs(OPENCV_LAPACKE_H_PATH_${_lapack_impl} "${LAPACK_LAPACKE_H}" "${LAPACK_INCLUDE_DIR}")
28 if(NOT OPENCV_CBLAS_H_PATH_${_lapack_impl} OR NOT OPENCV_LAPACKE_H_PATH_${_lapack_impl})
29 message(WARNING "LAPACK(${LAPACK_IMPL}): CBLAS/LAPACK headers are not found in '${LAPACK_INCLUDE_DIR}'")
30 unset(LAPACK_LIBRARIES)
32 # adding proxy opencv_lapack.h header
33 set(CBLAS_H_PROXY_PATH ${CMAKE_BINARY_DIR}/opencv_lapack.h)
34 set(_lapack_include_str "\#include \"${OPENCV_CBLAS_H_PATH_${_lapack_impl}}\"")
35 if(NOT "${OPENCV_CBLAS_H_PATH_${_lapack_impl}}" STREQUAL "${OPENCV_LAPACKE_H_PATH_${_lapack_impl}}")
36 set(_lapack_include_str "${_lapack_include_str}\n#include \"${OPENCV_LAPACKE_H_PATH_${_lapack_impl}}\"")
38 # update file contents (if required)
40 if(EXISTS "${CBLAS_H_PROXY_PATH}")
41 file(READ "${CBLAS_H_PROXY_PATH}" __content_str)
43 if(NOT " ${__content_str}" STREQUAL " ${_lapack_include_str}")
44 file(WRITE "${CBLAS_H_PROXY_PATH}" "${_lapack_include_str}")
47 try_compile(__VALID_LAPACK
48 "${OpenCV_BINARY_DIR}"
49 "${OpenCV_SOURCE_DIR}/cmake/checks/lapack_check.cpp"
50 CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${LAPACK_INCLUDE_DIR}\;${CMAKE_BINARY_DIR}"
51 "-DLINK_DIRECTORIES:STRING=${LAPACK_LINK_LIBRARIES}"
52 "-DLINK_LIBRARIES:STRING=${LAPACK_LIBRARIES}"
53 OUTPUT_VARIABLE TRY_OUT
55 if(NOT __VALID_LAPACK)
56 #message(FATAL_ERROR "LAPACK: check build log:\n${TRY_OUT}")
57 message(STATUS "LAPACK(${LAPACK_IMPL}): Can't build LAPACK check code. This LAPACK version is not supported.")
58 unset(LAPACK_LIBRARIES)
60 message(STATUS "LAPACK(${LAPACK_IMPL}): Support is enabled.")
61 ocv_include_directories(${LAPACK_INCLUDE_DIR})
68 ocv_update(LAPACK_IMPL "Unknown")
69 if(NOT OPENCV_LAPACK_FIND_PACKAGE_ONLY)
70 if(NOT LAPACK_LIBRARIES AND NOT OPENCV_LAPACK_DISABLE_MKL)
71 include(cmake/OpenCVFindMKL.cmake)
73 set(LAPACK_INCLUDE_DIR ${MKL_INCLUDE_DIRS})
74 set(LAPACK_LIBRARIES ${MKL_LIBRARIES})
75 set(LAPACK_CBLAS_H "mkl_cblas.h")
76 set(LAPACK_LAPACKE_H "mkl_lapack.h")
77 set(LAPACK_IMPL "MKL")
81 if(NOT LAPACK_LIBRARIES)
82 include(cmake/OpenCVFindOpenBLAS.cmake)
84 set(LAPACK_INCLUDE_DIR ${OpenBLAS_INCLUDE_DIR})
85 set(LAPACK_LIBRARIES ${OpenBLAS_LIB})
86 set(LAPACK_CBLAS_H "cblas.h")
87 set(LAPACK_LAPACKE_H "lapacke.h")
88 set(LAPACK_IMPL "OpenBLAS")
92 if(NOT LAPACK_LIBRARIES AND UNIX)
93 include(cmake/OpenCVFindAtlas.cmake)
95 set(LAPACK_INCLUDE_DIR ${Atlas_INCLUDE_DIR})
96 set(LAPACK_LIBRARIES ${Atlas_LIBRARIES})
97 set(LAPACK_CBLAS_H "cblas.h")
98 set(LAPACK_LAPACKE_H "lapacke.h")
99 set(LAPACK_IMPL "Atlas")
105 if(NOT LAPACK_LIBRARIES)
106 if(WIN32 AND NOT OPENCV_LAPACK_SHARED_LIBS)
111 if(NOT DEFINED LAPACKE_INCLUDE_DIR)
112 find_path(LAPACKE_INCLUDE_DIR "lapacke.h")
114 if(NOT DEFINED MKL_LAPACKE_INCLUDE_DIR)
115 find_path(MKL_LAPACKE_INCLUDE_DIR "mkl_lapack.h")
117 if(MKL_LAPACKE_INCLUDE_DIR AND NOT OPENCV_LAPACK_DISABLE_MKL)
118 set(LAPACK_INCLUDE_DIR ${MKL_LAPACKE_INCLUDE_DIR})
119 set(LAPACK_CBLAS_H "mkl_cblas.h")
120 set(LAPACK_LAPACKE_H "mkl_lapack.h")
121 set(LAPACK_IMPL "LAPACK/MKL")
125 if(LAPACKE_INCLUDE_DIR)
126 set(LAPACK_INCLUDE_DIR ${LAPACKE_INCLUDE_DIR})
127 set(LAPACK_CBLAS_H "cblas.h")
128 set(LAPACK_LAPACKE_H "lapacke.h")
129 set(LAPACK_IMPL "LAPACK/Generic")
132 set(LAPACK_CBLAS_H "Accelerate/Accelerate.h")
133 set(LAPACK_LAPACKE_H "Accelerate/Accelerate.h")
134 set(LAPACK_IMPL "LAPACK/Apple")
140 unset(LAPACK_LIBRARIES)
141 unset(LAPACK_LIBRARIES CACHE)
145 if(NOT LAPACK_LIBRARIES AND APPLE AND NOT OPENCV_LAPACK_FIND_PACKAGE_ONLY)
146 set(LAPACK_INCLUDE_DIR "")
147 set(LAPACK_LIBRARIES "-framework Accelerate")
148 set(LAPACK_CBLAS_H "Accelerate/Accelerate.h")
149 set(LAPACK_LAPACKE_H "Accelerate/Accelerate.h")
150 set(LAPACK_IMPL "Apple")
154 if(NOT HAVE_LAPACK AND LAPACK_LIBRARIES AND LAPACK_CBLAS_H AND LAPACK_LAPACKE_H)
158 set(LAPACK_INCLUDE_DIR ${LAPACK_INCLUDE_DIR} CACHE PATH "Path to BLAS include dir" FORCE)
159 set(LAPACK_CBLAS_H ${LAPACK_CBLAS_H} CACHE STRING "Alternative name of cblas.h" FORCE)
160 set(LAPACK_LAPACKE_H ${LAPACK_LAPACKE_H} CACHE STRING "Alternative name of lapacke.h" FORCE)
161 set(LAPACK_LIBRARIES ${LAPACK_LIBRARIES} CACHE STRING "Names of BLAS & LAPACK binaries (.so, .dll, .a, .lib)" FORCE)
162 set(LAPACK_IMPL ${LAPACK_IMPL} CACHE STRING "Lapack implementation id" FORCE)