1*da0073e9SAndroid Build Coastguard Workerfind_package(MKL QUIET) 2*da0073e9SAndroid Build Coastguard Worker 3*da0073e9SAndroid Build Coastguard Workerif(TARGET caffe2::mkl) 4*da0073e9SAndroid Build Coastguard Worker return() 5*da0073e9SAndroid Build Coastguard Workerendif() 6*da0073e9SAndroid Build Coastguard Worker 7*da0073e9SAndroid Build Coastguard Workeradd_library(caffe2::mkl INTERFACE IMPORTED) 8*da0073e9SAndroid Build Coastguard Workertarget_include_directories(caffe2::mkl INTERFACE ${MKL_INCLUDE_DIR}) 9*da0073e9SAndroid Build Coastguard Workertarget_link_libraries(caffe2::mkl INTERFACE ${MKL_LIBRARIES}) 10*da0073e9SAndroid Build Coastguard Workerforeach(MKL_LIB IN LISTS MKL_LIBRARIES) 11*da0073e9SAndroid Build Coastguard Worker if(EXISTS "${MKL_LIB}") 12*da0073e9SAndroid Build Coastguard Worker get_filename_component(MKL_LINK_DIR "${MKL_LIB}" DIRECTORY) 13*da0073e9SAndroid Build Coastguard Worker if(IS_DIRECTORY "${MKL_LINK_DIR}") 14*da0073e9SAndroid Build Coastguard Worker target_link_directories(caffe2::mkl INTERFACE "${MKL_LINK_DIR}") 15*da0073e9SAndroid Build Coastguard Worker endif() 16*da0073e9SAndroid Build Coastguard Worker endif() 17*da0073e9SAndroid Build Coastguard Workerendforeach() 18*da0073e9SAndroid Build Coastguard Worker 19*da0073e9SAndroid Build Coastguard Worker# TODO: This is a hack, it will not pick up architecture dependent 20*da0073e9SAndroid Build Coastguard Worker# MKL libraries correctly; see https://github.com/pytorch/pytorch/issues/73008 21*da0073e9SAndroid Build Coastguard Workerset_property( 22*da0073e9SAndroid Build Coastguard Worker TARGET caffe2::mkl PROPERTY INTERFACE_LINK_DIRECTORIES 23*da0073e9SAndroid Build Coastguard Worker ${MKL_ROOT}/lib ${MKL_ROOT}/lib/intel64 ${MKL_ROOT}/lib/intel64_win ${MKL_ROOT}/lib/win-x64) 24*da0073e9SAndroid Build Coastguard Worker 25*da0073e9SAndroid Build Coastguard Workerif(UNIX) 26*da0073e9SAndroid Build Coastguard Worker if(USE_STATIC_MKL) 27*da0073e9SAndroid Build Coastguard Worker foreach(MKL_LIB_PATH IN LISTS MKL_LIBRARIES) 28*da0073e9SAndroid Build Coastguard Worker if(NOT EXISTS "${MKL_LIB_PATH}") 29*da0073e9SAndroid Build Coastguard Worker continue() 30*da0073e9SAndroid Build Coastguard Worker endif() 31*da0073e9SAndroid Build Coastguard Worker 32*da0073e9SAndroid Build Coastguard Worker get_filename_component(MKL_LIB_NAME "${MKL_LIB_PATH}" NAME) 33*da0073e9SAndroid Build Coastguard Worker 34*da0073e9SAndroid Build Coastguard Worker # Match archive libraries starting with "libmkl_" 35*da0073e9SAndroid Build Coastguard Worker if(MKL_LIB_NAME MATCHES "^libmkl_" AND MKL_LIB_NAME MATCHES ".a$") 36*da0073e9SAndroid Build Coastguard Worker target_link_options(caffe2::mkl INTERFACE "-Wl,--exclude-libs,${MKL_LIB_NAME}") 37*da0073e9SAndroid Build Coastguard Worker endif() 38*da0073e9SAndroid Build Coastguard Worker endforeach() 39*da0073e9SAndroid Build Coastguard Worker endif() 40*da0073e9SAndroid Build Coastguard Workerendif() 41