2 # This module finds an installed fortran library that implements the BLAS
3 # linear-algebra interface (see http://www.netlib.org/blas/).
4 # The list of libraries searched for is taken
5 # from the autoconf macro file, acx_blas.m4 (distributed at
6 # http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
8 # This module sets the following variables:
9 # BLAS_FOUND - set to true if a library implementing the BLAS interface
11 # BLAS_LINKER_FLAGS - uncached list of required linker flags (excluding -l
13 # BLAS_LIBRARIES - uncached list of libraries (using full path name) to
14 # link against to use BLAS
15 # BLAS95_LIBRARIES - uncached list of libraries (using full path name)
16 # to link against to use BLAS95 interface
17 # BLAS95_FOUND - set to true if a library implementing the BLAS f95 interface
19 # BLA_STATIC if set on this determines what kind of linkage we do (static)
20 # BLA_VENDOR if set checks only the specified vendor, if not set checks
21 # all the posibilities
22 # BLA_F95 if set on tries to find the f95 interfaces for BLAS/LAPACK
24 ### List of vendors (BLA_VENDOR) valid in this module
25 ## ATLAS, PhiPACK,CXML,DXML,SunPerf,SCSL,SGIMATH,IBMESSL,Intel10_32 (intel mkl v10 32 bit),Intel10_64lp (intel mkl v10 64 bit,lp thread model, lp64 model),
26 ## Intel( older versions of mkl 32 and 64 bit), ACML,Apple, NAS, Generic
27 # C/CXX should be enabled to use Intel mkl
28 get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES)
29 if(NOT _LANGUAGES_ MATCHES Fortran)
30 if(BLAS_FIND_REQUIRED)
31 message(FATAL_ERROR "FindBLAS is Fortran-only so Fortran must be enabled.")
32 else(BLAS_FIND_REQUIRED)
33 message(STATUS "Looking for BLAS... - NOT found (Fortran not enabled)") #
35 endif(BLAS_FIND_REQUIRED)
36 endif(NOT _LANGUAGES_ MATCHES Fortran)
38 include(CheckFortranFunctionExists)
40 macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _threads)
41 # This macro checks for the existence of the combination of fortran libraries
42 # given by _list. If the combination is found, this macro checks (using the
43 # Check_Fortran_Function_Exists macro) whether can link against that library
44 # combination using the name of a routine given by _name using the linker
45 # flags given by _flags. If the combination of libraries is found and passes
46 # the link test, LIBRARIES is set to the list of complete library paths that
47 # have been found. Otherwise, LIBRARIES is set to FALSE.
49 # N.B. _prefix is the prefix applied to the names of all cached variables that
50 # are generated internally and marked advanced by this macro.
52 set(_libraries_work TRUE)
55 foreach(_library ${_list})
56 set(_combined_name ${_combined_name}_${_library})
61 set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
63 find_library(${_prefix}_${_library}_LIBRARY
71 set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
73 find_library(${_prefix}_${_library}_LIBRARY
75 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
80 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so")
82 find_library(${_prefix}_${_library}_LIBRARY
84 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
87 mark_as_advanced(${_prefix}_${_library}_LIBRARY)
88 set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
89 set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
90 endif(_libraries_work)
91 endforeach(_library ${_list})
93 # Test this combination of libraries.
94 set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_threads})
95 # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
96 check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
97 set(CMAKE_REQUIRED_LIBRARIES)
98 mark_as_advanced(${_prefix}${_combined_name}_WORKS)
99 set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
100 endif(_libraries_work)
101 if(NOT _libraries_work)
102 set(${LIBRARIES} FALSE)
103 endif(NOT _libraries_work)
104 #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
105 endmacro(Check_Fortran_Libraries)
107 set(BLAS_LINKER_FLAGS)
109 set(BLAS95_LIBRARIES)
110 if ($ENV{BLA_VENDOR} MATCHES ".+")
111 set(BLA_VENDOR $ENV{BLA_VENDOR})
112 else ($ENV{BLA_VENDOR} MATCHES ".+")
114 set(BLA_VENDOR "All")
115 endif(NOT BLA_VENDOR)
116 endif ($ENV{BLA_VENDOR} MATCHES ".+")
118 if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
119 if(NOT BLAS_LIBRARIES)
120 # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
121 check_fortran_libraries(
126 "cblas;f77blas;atlas"
129 endif(NOT BLAS_LIBRARIES)
130 endif (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
132 # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
133 if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
134 if(NOT BLAS_LIBRARIES)
135 check_fortran_libraries(
143 endif(NOT BLAS_LIBRARIES)
144 endif (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
146 # BLAS in Alpha CXML library?
147 if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
148 if(NOT BLAS_LIBRARIES)
149 check_fortran_libraries(
157 endif(NOT BLAS_LIBRARIES)
158 endif (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
160 # BLAS in Alpha DXML library? (now called CXML, see above)
161 if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
162 if(NOT BLAS_LIBRARIES)
163 check_fortran_libraries(
171 endif(NOT BLAS_LIBRARIES)
172 endif (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
174 # BLAS in Sun Performance library?
175 if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
176 if(NOT BLAS_LIBRARIES)
177 check_fortran_libraries(
186 set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
187 endif(BLAS_LIBRARIES)
188 endif(NOT BLAS_LIBRARIES)
189 endif (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
191 # BLAS in SCSL library? (SGI/Cray Scientific Library)
192 if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
193 if(NOT BLAS_LIBRARIES)
194 check_fortran_libraries(
202 endif(NOT BLAS_LIBRARIES)
203 endif (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
205 # BLAS in SGIMATH library?
206 if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
207 if(NOT BLAS_LIBRARIES)
208 check_fortran_libraries(
216 endif(NOT BLAS_LIBRARIES)
217 endif (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
219 # BLAS in IBM ESSL library? (requires generic BLAS lib, too)
220 if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
221 if(NOT BLAS_LIBRARIES)
222 check_fortran_libraries(
230 endif(NOT BLAS_LIBRARIES)
231 endif (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
233 #BLAS in acml library?
234 if (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
235 if(NOT BLAS_LIBRARIES)
236 check_fortran_libraries(
244 endif(NOT BLAS_LIBRARIES)
245 endif (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
247 # Apple BLAS library?
248 if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
249 if(NOT BLAS_LIBRARIES)
250 check_fortran_libraries(
258 endif(NOT BLAS_LIBRARIES)
259 endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
261 if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
262 if ( NOT BLAS_LIBRARIES )
263 check_fortran_libraries(
271 endif ( NOT BLAS_LIBRARIES )
272 endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
273 # Generic BLAS library?
274 if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
275 if(NOT BLAS_LIBRARIES)
276 check_fortran_libraries(
284 endif(NOT BLAS_LIBRARIES)
285 endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
287 #BLAS in intel mkl 10 library? (em64t 64bit)
288 if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
289 if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
290 if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
291 find_package(Threads)
292 else(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
293 find_package(Threads REQUIRED)
294 endif(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
297 if(NOT BLAS95_LIBRARIES)
298 check_fortran_libraries(
303 "mkl_blas95;mkl_intel_c;mkl_intel_thread;mkl_core;libguide40"
306 endif(NOT BLAS95_LIBRARIES)
308 if(NOT BLAS_LIBRARIES)
309 check_fortran_libraries(
314 "mkl_c_dll;mkl_intel_thread_dll;mkl_core_dll;libguide40"
317 endif(NOT BLAS_LIBRARIES)
320 if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
322 if(NOT BLAS95_LIBRARIES)
323 check_fortran_libraries(
328 "mkl_blas95;mkl_intel;mkl_intel_thread;mkl_core;guide"
329 "${CMAKE_THREAD_LIBS_INIT}"
331 endif(NOT BLAS95_LIBRARIES)
333 if(NOT BLAS_LIBRARIES)
334 check_fortran_libraries(
339 "mkl_intel;mkl_intel_thread;mkl_core;guide"
340 "${CMAKE_THREAD_LIBS_INIT}"
342 endif(NOT BLAS_LIBRARIES)
344 endif (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
345 if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
347 if(NOT BLAS95_LIBRARIES)
348 check_fortran_libraries(
353 "mkl_blas95;mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
354 "${CMAKE_THREAD_LIBS_INIT}"
356 endif(NOT BLAS95_LIBRARIES)
358 if(NOT BLAS_LIBRARIES)
359 check_fortran_libraries(
364 "mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
365 "${CMAKE_THREAD_LIBS_INIT}"
367 endif(NOT BLAS_LIBRARIES)
369 endif (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
371 #older vesions of intel mkl libs
372 # BLAS in intel mkl library? (shared)
373 if(NOT BLAS_LIBRARIES)
374 check_fortran_libraries(
380 "${CMAKE_THREAD_LIBS_INIT}"
382 endif(NOT BLAS_LIBRARIES)
383 #BLAS in intel mkl library? (static, 32bit)
384 if(NOT BLAS_LIBRARIES)
385 check_fortran_libraries(
391 "${CMAKE_THREAD_LIBS_INIT}"
393 endif(NOT BLAS_LIBRARIES)
394 #BLAS in intel mkl library? (static, em64t 64bit)
395 if(NOT BLAS_LIBRARIES)
396 check_fortran_libraries(
402 "${CMAKE_THREAD_LIBS_INIT}"
404 endif(NOT BLAS_LIBRARIES)
405 endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
406 endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
411 set(BLAS95_FOUND TRUE)
412 else(BLAS95_LIBRARIES)
413 set(BLAS95_FOUND FALSE)
414 endif(BLAS95_LIBRARIES)
416 if(NOT BLAS_FIND_QUIETLY)
418 message(STATUS "A library with BLAS95 API found.")
420 if(BLAS_FIND_REQUIRED)
422 "A required library with BLAS95 API not found. Please specify library location.")
423 else(BLAS_FIND_REQUIRED)
425 "A library with BLAS95 API not found. Please specify library location.")
426 endif(BLAS_FIND_REQUIRED)
428 endif(NOT BLAS_FIND_QUIETLY)
430 set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
435 set(BLAS_FOUND FALSE)
436 endif(BLAS_LIBRARIES)
438 if(NOT BLAS_FIND_QUIETLY)
440 message(STATUS "A library with BLAS API found.")
442 if(BLAS_FIND_REQUIRED)
444 "A required library with BLAS API not found. Please specify library location."
446 else(BLAS_FIND_REQUIRED)
448 "A library with BLAS API not found. Please specify library location."
450 endif(BLAS_FIND_REQUIRED)
452 endif(NOT BLAS_FIND_QUIETLY)