Skip to content

Commit 58334a0

Browse files
committed
static MKL detection and linkage fixes
1 parent f805a83 commit 58334a0

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,13 @@ ENDIF()
303303
FIND_PACKAGE(BLAS)
304304
IF(BLAS_FOUND)
305305
SET(USE_BLAS 1)
306-
TARGET_LINK_LIBRARIES(TH ${BLAS_LIBRARIES})
306+
IF ($ENV{TH_BINARY_BUILD})
307+
MESSAGE(STATUS "TH_BINARY_BUILD detected. Enabling special linkage.")
308+
TARGET_LINK_LIBRARIES(TH "${BLAS_LIBRARIES};${BLAS_LIBRARIES};${BLAS_LIBRARIES}")
309+
ELSE ($ENV{TH_BINARY_BUILD})
310+
TARGET_LINK_LIBRARIES(TH ${BLAS_LIBRARIES})
311+
ENDIF ($ENV{TH_BINARY_BUILD})
312+
307313
IF(BLAS_INFO STREQUAL "mkl")
308314
ADD_DEFINITIONS(-DTH_BLAS_MKL)
309315
ENDIF()

cmake/FindMKL.cmake

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ENDIF ("${SIZE_OF_VOIDP}" EQUAL 8)
5050
IF(CMAKE_COMPILER_IS_GNUCC)
5151
SET(mklthreads "mkl_gnu_thread" "mkl_intel_thread")
5252
SET(mklifaces "gf" "intel")
53-
SET(mklrtls "iomp5")
53+
SET(mklrtls "gomp" "iomp5")
5454
ELSE(CMAKE_COMPILER_IS_GNUCC)
5555
SET(mklthreads "mkl_intel_thread")
5656
SET(mklifaces "intel")
@@ -92,7 +92,7 @@ ENDIF (INTEL_MKL_DIR)
9292
# Try linking multiple libs
9393
MACRO(CHECK_ALL_LIBRARIES LIBRARIES _name _list _flags)
9494
# This macro checks for the existence of the combination of libraries given by _list.
95-
# If the combination is found, this macro whether we can link against that library
95+
# If the combination is found, this macro checks whether we can link against that library
9696
# combination using the name of a routine given by _name using the linker
9797
# flags given by _flags. If the combination of libraries is found and passes
9898
# the link test, LIBRARIES is set to the list of complete library paths that
@@ -116,8 +116,15 @@ MACRO(CHECK_ALL_LIBRARIES LIBRARIES _name _list _flags)
116116
message(STATUS "Checking for [${__list}]")
117117
FOREACH(_library ${_list})
118118
SET(_combined_name ${_combined_name}_${_library})
119-
IF(_libraries_work)
120-
FIND_LIBRARY(${_prefix}_${_library}_LIBRARY NAMES ${_library})
119+
IF(_libraries_work)
120+
IF(${_library} STREQUAL "gomp")
121+
FIND_PACKAGE(OpenMP)
122+
IF(OPENMP_FOUND)
123+
SET(${_prefix}_${_library}_LIBRARY ${OpenMP_C_FLAGS})
124+
ENDIF(OPENMP_FOUND)
125+
ELSE(${_library} STREQUAL "gomp")
126+
FIND_LIBRARY(${_prefix}_${_library}_LIBRARY NAMES ${_library})
127+
ENDIF(${_library} STREQUAL "gomp")
121128
MARK_AS_ADVANCED(${_prefix}_${_library}_LIBRARY)
122129
SET(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
123130
SET(_libraries_work ${${_prefix}_${_library}_LIBRARY})
@@ -131,6 +138,7 @@ MACRO(CHECK_ALL_LIBRARIES LIBRARIES _name _list _flags)
131138
# Test this combination of libraries.
132139
IF(_libraries_work)
133140
SET(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}})
141+
SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};${CMAKE_REQUIRED_LIBRARIES}")
134142
CHECK_FUNCTION_EXISTS(${_name} ${_prefix}${_combined_name}_WORKS)
135143
SET(CMAKE_REQUIRED_LIBRARIES)
136144
MARK_AS_ADVANCED(${_prefix}${_combined_name}_WORKS)
@@ -150,6 +158,11 @@ else(WIN32)
150158
set(mkl_m "m")
151159
endif(WIN32)
152160

161+
if(UNIX AND NOT APPLE)
162+
set(mkl_dl "${CMAKE_DL_LIBS}")
163+
else(UNIX AND NOT APPLE)
164+
set(mkl_dl "")
165+
endif(UNIX AND NOT APPLE)
153166

154167
# Check for version 10/11
155168
IF (NOT MKL_LIBRARIES)
@@ -161,7 +174,7 @@ FOREACH(mklrtl ${mklrtls} "")
161174
FOREACH(mklthread ${mklthreads})
162175
IF (NOT MKL_LIBRARIES AND NOT INTEL_MKL_SEQUENTIAL)
163176
CHECK_ALL_LIBRARIES(MKL_LIBRARIES cblas_sgemm
164-
"mkl_${mkliface}${mkl64};${mklthread};mkl_core;${mklrtl};pthread;${mkl_m}" "")
177+
"mkl_${mkliface}${mkl64};${mklthread};mkl_core;${mklrtl};pthread;${mkl_m};${mkl_dl}" "")
165178
ENDIF (NOT MKL_LIBRARIES AND NOT INTEL_MKL_SEQUENTIAL)
166179
ENDFOREACH(mklthread)
167180
ENDFOREACH(mkl64)
@@ -172,7 +185,7 @@ FOREACH(mklrtl ${mklrtls} "")
172185
FOREACH(mkl64 ${mkl64s} "")
173186
IF (NOT MKL_LIBRARIES)
174187
CHECK_ALL_LIBRARIES(MKL_LIBRARIES cblas_sgemm
175-
"mkl_${mkliface}${mkl64};mkl_sequential;mkl_core;${mkl_m}" "")
188+
"mkl_${mkliface}${mkl64};mkl_sequential;mkl_core;${mkl_m};${mkl_dl}" "")
176189
IF (MKL_LIBRARIES)
177190
SET(mklseq "_sequential")
178191
ENDIF (MKL_LIBRARIES)
@@ -186,7 +199,7 @@ FOREACH(mklrtl ${mklrtls} "")
186199
FOREACH(mklthread ${mklthreads})
187200
IF (NOT MKL_LIBRARIES)
188201
CHECK_ALL_LIBRARIES(MKL_LIBRARIES cblas_sgemm
189-
"mkl_${mkliface}${mkl64};${mklthread};mkl_core;${mklrtl};pthread;${mkl_m}" "")
202+
"mkl_${mkliface}${mkl64};${mklthread};mkl_core;${mklrtl};pthread;${mkl_m};${mkl_dl}" "")
190203
ENDIF (NOT MKL_LIBRARIES)
191204
ENDFOREACH(mklthread)
192205
ENDFOREACH(mkl64)

0 commit comments

Comments
 (0)