@@ -58,16 +58,52 @@ macro(ocv_lapack_check)
58
58
string (REPLACE ";" "\n " _lapack_content "${_lapack_content} " )
59
59
ocv_update_file ("${CBLAS_H_PROXY_PATH} " "${_lapack_content} " )
60
60
61
+ if (CMAKE_GENERATOR MATCHES "Visual Studio" # MSBuild
62
+ AND LAPACK_IMPL STREQUAL "MKL"
63
+ AND ";${LAPACK_LIBRARIES} ;" MATCHES ";tbb;" AND TARGET tbb
64
+ AND DEFINED TBB_INTERFACE_VERSION AND NOT (TBB_INTERFACE_VERSION LESS 12000 ) # oneTBB/oneAPI workaround
65
+ )
66
+ # workaround DEFAULTLIB:tbb12.lib issue
67
+ get_target_property (_tbb_lib tbb IMPORTED_LOCATION )
68
+ if (NOT _tbb_lib )
69
+ get_target_property (_tbb_lib tbb IMPORTED_LOCATION_RELEASE )
70
+ endif ()
71
+ if (_tbb_lib AND NOT OPENCV_SKIP_WORKAROUND_MKL_LINK_DIRECTORIES_TBB )
72
+ # MSBuild drops content of 'LIB' environment variable,
73
+ # so pass TBB library directory through `link_directories()`
74
+ get_filename_component (_tbb_lib_dir "${_tbb_lib} " DIRECTORY )
75
+ message (STATUS "MKL: adding '${_tbb_lib_dir} ' to link directories (workaround DEFAULTLIB issue)" )
76
+ link_directories ("${_tbb_lib_dir} " )
77
+ elseif (NOT OPENCV_SKIP_WORKAROUND_MKL_DEFAULTLIB )
78
+ # We may have tbb.lib for 'tbb' target, but not 'tbb12.lib'
79
+ ocv_update (OPENCV_MKL_IGNORE_DEFAULTLIB_TBB "tbb12.lib" )
80
+ set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /NODEFAULTLIB:${OPENCV_MKL_IGNORE_DEFAULTLIB_TBB} " )
81
+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:${OPENCV_MKL_IGNORE_DEFAULTLIB_TBB} " )
82
+ endif ()
83
+ endif ()
84
+
85
+ # TODO add cache for try_compile() inputs/results
86
+
87
+ get_property (__link_directories DIRECTORY PROPERTY LINK_DIRECTORIES )
88
+ if (LAPACK_LINK_LIBRARIES )
89
+ list (APPEND __link_directories ${LAPACK_LINK_LIBRARIES} )
90
+ endif ()
91
+
61
92
try_compile (__VALID_LAPACK
62
93
"${OpenCV_BINARY_DIR} "
63
94
"${OpenCV_SOURCE_DIR} /cmake/checks/lapack_check.cpp"
64
95
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${LAPACK_INCLUDE_DIR} \; ${CMAKE_BINARY_DIR} "
65
- "-DLINK_DIRECTORIES:STRING=${LAPACK_LINK_LIBRARIES } "
66
- "-DLINK_LIBRARIES:STRING= ${LAPACK_LIBRARIES} "
96
+ "-DLINK_DIRECTORIES:STRING=${__link_directories } "
97
+ LINK_LIBRARIES ${LAPACK_LIBRARIES}
67
98
OUTPUT_VARIABLE TRY_OUT
68
99
)
69
100
if (NOT __VALID_LAPACK )
70
- #message(FATAL_ERROR "LAPACK: check build log:\n${TRY_OUT}")
101
+ file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /CMakeError.log
102
+ "\n LAPACK(${LAPACK_IMPL} ) check FAILED:\n "
103
+ " LAPACK_INCLUDE_DIR: '${LAPACK_INCLUDE_DIR} '\n "
104
+ " LAPACK_LIBRARIES: '${LAPACK_LIBRARIES} '\n "
105
+ " LAPACK_LINK_LIBRARIES: '${__link_directories} '\n "
106
+ " Output:\n ${TRY_OUT} \n\n " )
71
107
message (STATUS "LAPACK(${LAPACK_IMPL} ): Can't build LAPACK check code. This LAPACK version is not supported." )
72
108
unset (LAPACK_LIBRARIES )
73
109
else ()
0 commit comments