Skip to content

Commit 4261355

Browse files
Find packages without needing to source.
1 parent 57d41b2 commit 4261355

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

FindMKL.cmake

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,19 @@
7070
# Link line for C API
7171
#===============================================================================
7272

73+
if(TARGET MKL::MKL)
74+
message(STATUS "MKL::MKL target has already been loaded.")
75+
return()
76+
endif()
77+
7378
if(${CMAKE_VERSION} VERSION_LESS "3.13")
7479
message(FATAL_ERROR "The minimum supported CMake version is 3.13. You are running version ${CMAKE_VERSION}")
7580
endif()
7681

7782
include(FindPackageHandleStandardArgs)
7883

84+
set(MKLROOT_DEFAULT "/opt/intel/oneapi/mkl/latest")
85+
7986
if(NOT MKL_LIBRARIES)
8087

8188
# Set CMake policies for well-defined behavior across CMake versions
@@ -124,11 +131,15 @@ if(NOT MKL_LIBRARIES)
124131
if(NOT DEFINED MKL_ROOT)
125132
if(DEFINED ENV{MKLROOT})
126133
set(MKL_ROOT $ENV{MKLROOT})
134+
elseif(EXISTS ${MKLROOT_DEFAULT})
135+
set(MKL_ROOT ${MKLROOT_DEFAULT})
127136
else()
128137
message(FATAL_ERROR "MKLROOT environment variable is not defined.")
129138
endif()
130139
endif()
131140

141+
set(MKL_INCLUDE "${MKL_ROOT}/include")
142+
132143
# Define MKL_LINK
133144
set(MKL_LINK static)
134145
set(MKL_INTERFACE "lp64")
@@ -209,12 +220,12 @@ if(NOT MKL_LIBRARIES)
209220
target_compile_options(
210221
MKL::MKL INTERFACE $<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,C>:${MKL_C_COPT}>
211222
$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:${MKL_CXX_COPT}>)
223+
target_compile_definitions(MKL::MKL INTERFACE EIGEN_USE_MKL_ALL)
212224
target_link_libraries(MKL::MKL INTERFACE ${MKL_LINK_LINE} ${MKL_THREAD_LIB} ${MKL_SUPP_LINK})
213225
list(APPEND LINK_TYPES MKL::MKL)
214-
215226
foreach(link ${LINK_TYPES})
216227
# Set properties on all INTERFACE targets
217-
target_include_directories(${link} BEFORE INTERFACE "${MKL_INCLUDE}")
228+
target_include_directories(${link} BEFORE INTERFACE ${MKL_INCLUDE})
218229
list(APPEND MKL_IMPORTED_TARGETS ${link})
219230
endforeach(link) # LINK_TYPES
220231

0 commit comments

Comments
 (0)