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 possibilities
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
29 #=============================================================================
30 # Copyright 2007-2009 Kitware, Inc.
32 # Distributed under the OSI-approved BSD License (the "License");
33 # see accompanying file Copyright.txt for details.
35 # This software is distributed WITHOUT ANY WARRANTY; without even the
36 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
37 # See the License for more information.
38 #=============================================================================
39 # (To distributed this file outside of CMake, substitute the full
40 # License text for the above reference.)
42 get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES)
43 if(NOT _LANGUAGES_ MATCHES Fortran)
44 if(BLAS_FIND_REQUIRED)
45 message(FATAL_ERROR "FindBLAS is Fortran-only so Fortran must be enabled.")
46 else(BLAS_FIND_REQUIRED)
47 message(STATUS "Looking for BLAS... - NOT found (Fortran not enabled)") #
49 endif(BLAS_FIND_REQUIRED)
50 endif(NOT _LANGUAGES_ MATCHES Fortran)
52 include(CheckFortranFunctionExists)
54 macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _threads)
55 # This macro checks for the existence of the combination of fortran libraries
56 # given by _list. If the combination is found, this macro checks (using the
57 # Check_Fortran_Function_Exists macro) whether can link against that library
58 # combination using the name of a routine given by _name using the linker
59 # flags given by _flags. If the combination of libraries is found and passes
60 # the link test, LIBRARIES is set to the list of complete library paths that
61 # have been found. Otherwise, LIBRARIES is set to FALSE.
63 # N.B. _prefix is the prefix applied to the names of all cached variables that
64 # are generated internally and marked advanced by this macro.
66 set(_libraries_work TRUE)
69 foreach(_library ${_list})
70 set(_combined_name ${_combined_name}_${_library})
75 set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
77 find_library(${_prefix}_${_library}_LIBRARY
85 set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
87 find_library(${_prefix}_${_library}_LIBRARY
89 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
94 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so")
96 find_library(${_prefix}_${_library}_LIBRARY
98 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
101 mark_as_advanced(${_prefix}_${_library}_LIBRARY)
102 set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
103 set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
104 endif(_libraries_work)
105 endforeach(_library ${_list})
107 # Test this combination of libraries.
108 set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_threads})
109 # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
110 check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
111 set(CMAKE_REQUIRED_LIBRARIES)
112 mark_as_advanced(${_prefix}${_combined_name}_WORKS)
113 set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
114 endif(_libraries_work)
115 if(NOT _libraries_work)
116 set(${LIBRARIES} FALSE)
117 endif(NOT _libraries_work)
118 #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
119 endmacro(Check_Fortran_Libraries)
121 set(BLAS_LINKER_FLAGS)
123 set(BLAS95_LIBRARIES)
124 if ($ENV{BLA_VENDOR} MATCHES ".+")
125 set(BLA_VENDOR $ENV{BLA_VENDOR})
126 else ($ENV{BLA_VENDOR} MATCHES ".+")
128 set(BLA_VENDOR "All")
129 endif(NOT BLA_VENDOR)
130 endif ($ENV{BLA_VENDOR} MATCHES ".+")
132 if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
133 if(NOT BLAS_LIBRARIES)
134 # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
135 check_fortran_libraries(
140 "cblas;f77blas;atlas"
143 endif(NOT BLAS_LIBRARIES)
144 endif (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
146 # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
147 if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
148 if(NOT BLAS_LIBRARIES)
149 check_fortran_libraries(
157 endif(NOT BLAS_LIBRARIES)
158 endif (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
160 # BLAS in Alpha CXML library?
161 if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
162 if(NOT BLAS_LIBRARIES)
163 check_fortran_libraries(
171 endif(NOT BLAS_LIBRARIES)
172 endif (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
174 # BLAS in Alpha DXML library? (now called CXML, see above)
175 if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
176 if(NOT BLAS_LIBRARIES)
177 check_fortran_libraries(
185 endif(NOT BLAS_LIBRARIES)
186 endif (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
188 # BLAS in Sun Performance library?
189 if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
190 if(NOT BLAS_LIBRARIES)
191 check_fortran_libraries(
200 set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
201 endif(BLAS_LIBRARIES)
202 endif(NOT BLAS_LIBRARIES)
203 endif (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
205 # BLAS in SCSL library? (SGI/Cray Scientific Library)
206 if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
207 if(NOT BLAS_LIBRARIES)
208 check_fortran_libraries(
216 endif(NOT BLAS_LIBRARIES)
217 endif (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
219 # BLAS in SGIMATH library?
220 if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
221 if(NOT BLAS_LIBRARIES)
222 check_fortran_libraries(
230 endif(NOT BLAS_LIBRARIES)
231 endif (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
233 # BLAS in IBM ESSL library? (requires generic BLAS lib, too)
234 if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
235 if(NOT BLAS_LIBRARIES)
236 check_fortran_libraries(
244 endif(NOT BLAS_LIBRARIES)
245 endif (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
247 #BLAS in acml library?
248 if (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
249 if(NOT BLAS_LIBRARIES)
250 check_fortran_libraries(
258 endif(NOT BLAS_LIBRARIES)
259 endif (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
261 # Apple BLAS library?
262 if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
263 if(NOT BLAS_LIBRARIES)
264 check_fortran_libraries(
272 endif(NOT BLAS_LIBRARIES)
273 endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
275 if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
276 if ( NOT BLAS_LIBRARIES )
277 check_fortran_libraries(
285 endif ( NOT BLAS_LIBRARIES )
286 endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
287 # Generic BLAS library?
288 if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
289 if(NOT BLAS_LIBRARIES)
290 check_fortran_libraries(
298 endif(NOT BLAS_LIBRARIES)
299 endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
301 #BLAS in intel mkl 10 library? (em64t 64bit)
302 if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
303 if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
304 if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
305 find_package(Threads)
306 else(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
307 find_package(Threads REQUIRED)
308 endif(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
311 if(NOT BLAS95_LIBRARIES)
312 check_fortran_libraries(
317 "mkl_blas95;mkl_intel_c;mkl_intel_thread;mkl_core;libguide40"
320 endif(NOT BLAS95_LIBRARIES)
322 if(NOT BLAS_LIBRARIES)
323 check_fortran_libraries(
328 "mkl_c_dll;mkl_intel_thread_dll;mkl_core_dll;libguide40"
331 endif(NOT BLAS_LIBRARIES)
334 if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
336 if(NOT BLAS95_LIBRARIES)
337 check_fortran_libraries(
342 "mkl_blas95;mkl_intel;mkl_intel_thread;mkl_core;guide"
343 "${CMAKE_THREAD_LIBS_INIT}"
345 endif(NOT BLAS95_LIBRARIES)
347 if(NOT BLAS_LIBRARIES)
348 check_fortran_libraries(
353 "mkl_intel;mkl_intel_thread;mkl_core;guide"
354 "${CMAKE_THREAD_LIBS_INIT}"
356 endif(NOT BLAS_LIBRARIES)
358 endif (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
359 if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
361 if(NOT BLAS95_LIBRARIES)
362 check_fortran_libraries(
367 "mkl_blas95;mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
368 "${CMAKE_THREAD_LIBS_INIT}"
370 endif(NOT BLAS95_LIBRARIES)
372 if(NOT BLAS_LIBRARIES)
373 check_fortran_libraries(
378 "mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
379 "${CMAKE_THREAD_LIBS_INIT}"
381 endif(NOT BLAS_LIBRARIES)
383 endif (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
385 #older vesions of intel mkl libs
386 # BLAS in intel mkl library? (shared)
387 if(NOT BLAS_LIBRARIES)
388 check_fortran_libraries(
394 "${CMAKE_THREAD_LIBS_INIT}"
396 endif(NOT BLAS_LIBRARIES)
397 #BLAS in intel mkl library? (static, 32bit)
398 if(NOT BLAS_LIBRARIES)
399 check_fortran_libraries(
405 "${CMAKE_THREAD_LIBS_INIT}"
407 endif(NOT BLAS_LIBRARIES)
408 #BLAS in intel mkl library? (static, em64t 64bit)
409 if(NOT BLAS_LIBRARIES)
410 check_fortran_libraries(
416 "${CMAKE_THREAD_LIBS_INIT}"
418 endif(NOT BLAS_LIBRARIES)
419 endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
420 endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
425 set(BLAS95_FOUND TRUE)
426 else(BLAS95_LIBRARIES)
427 set(BLAS95_FOUND FALSE)
428 endif(BLAS95_LIBRARIES)
430 if(NOT BLAS_FIND_QUIETLY)
432 message(STATUS "A library with BLAS95 API found.")
434 if(BLAS_FIND_REQUIRED)
436 "A required library with BLAS95 API not found. Please specify library location.")
437 else(BLAS_FIND_REQUIRED)
439 "A library with BLAS95 API not found. Please specify library location.")
440 endif(BLAS_FIND_REQUIRED)
442 endif(NOT BLAS_FIND_QUIETLY)
444 set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
449 set(BLAS_FOUND FALSE)
450 endif(BLAS_LIBRARIES)
452 if(NOT BLAS_FIND_QUIETLY)
454 message(STATUS "A library with BLAS API found.")
456 if(BLAS_FIND_REQUIRED)
458 "A required library with BLAS API not found. Please specify library location."
460 else(BLAS_FIND_REQUIRED)
462 "A library with BLAS API not found. Please specify library location."
464 endif(BLAS_FIND_REQUIRED)
466 endif(NOT BLAS_FIND_QUIETLY)