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 ## Goto,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 ## Intel10_64lp_seq (intel mkl v10 64 bit,sequential code, lp64 model),
27 ## Intel( older versions of mkl 32 and 64 bit), ACML,ACML_MP,ACML_GPU,Apple, NAS, Generic
28 # C/CXX should be enabled to use Intel mkl
30 #=============================================================================
31 # Copyright 2007-2009 Kitware, Inc.
33 # Distributed under the OSI-approved BSD License (the "License");
34 # see accompanying file Copyright.txt for details.
36 # This software is distributed WITHOUT ANY WARRANTY; without even the
37 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
38 # See the License for more information.
39 #=============================================================================
40 # (To distribute this file outside of CMake, substitute the full
41 # License text for the above reference.)
43 include(CheckFunctionExists)
44 include(CheckFortranFunctionExists)
46 set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
48 # Check the language being used
49 get_property( _LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES )
50 if( _LANGUAGES_ MATCHES Fortran )
51 set( _CHECK_FORTRAN TRUE )
52 elseif( (_LANGUAGES_ MATCHES C) OR (_LANGUAGES_ MATCHES CXX) )
53 set( _CHECK_FORTRAN FALSE )
55 if(BLAS_FIND_REQUIRED)
56 message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.")
57 else(BLAS_FIND_REQUIRED)
58 message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)")
60 endif(BLAS_FIND_REQUIRED)
63 macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _thread)
64 # This macro checks for the existence of the combination of fortran libraries
65 # given by _list. If the combination is found, this macro checks (using the
66 # Check_Fortran_Function_Exists macro) whether can link against that library
67 # combination using the name of a routine given by _name using the linker
68 # flags given by _flags. If the combination of libraries is found and passes
69 # the link test, LIBRARIES is set to the list of complete library paths that
70 # have been found. Otherwise, LIBRARIES is set to FALSE.
72 # N.B. _prefix is the prefix applied to the names of all cached variables that
73 # are generated internally and marked advanced by this macro.
77 set(_libraries_work TRUE)
84 set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH)
86 set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH)
90 foreach(_library ${_list})
91 set(_combined_name ${_combined_name}_${_library})
96 set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
99 set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
101 set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
104 if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
105 # for ubuntu's libblas3gf and liblapack3gf packages
106 set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
109 find_library(${_prefix}_${_library}_LIBRARY
113 mark_as_advanced(${_prefix}_${_library}_LIBRARY)
114 set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
115 set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
116 endif(_libraries_work)
117 endforeach(_library ${_list})
119 # Test this combination of libraries.
120 set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_thread})
121 # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
123 check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
125 check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
127 set(CMAKE_REQUIRED_LIBRARIES)
128 mark_as_advanced(${_prefix}${_combined_name}_WORKS)
129 set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
130 endif(_libraries_work)
131 if(NOT _libraries_work)
132 set(${LIBRARIES} FALSE)
133 endif(NOT _libraries_work)
134 #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
135 endmacro(Check_Fortran_Libraries)
137 set(BLAS_LINKER_FLAGS)
139 set(BLAS95_LIBRARIES)
140 if ($ENV{BLA_VENDOR} MATCHES ".+")
141 set(BLA_VENDOR $ENV{BLA_VENDOR})
142 else ($ENV{BLA_VENDOR} MATCHES ".+")
144 set(BLA_VENDOR "All")
145 endif(NOT BLA_VENDOR)
146 endif ($ENV{BLA_VENDOR} MATCHES ".+")
148 if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
149 if(NOT BLAS_LIBRARIES)
150 # gotoblas (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
151 check_fortran_libraries(
159 endif(NOT BLAS_LIBRARIES)
160 endif (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
162 if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
163 if(NOT BLAS_LIBRARIES)
164 # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
165 check_fortran_libraries(
173 endif(NOT BLAS_LIBRARIES)
174 endif (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
176 # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
177 if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
178 if(NOT BLAS_LIBRARIES)
179 check_fortran_libraries(
187 endif(NOT BLAS_LIBRARIES)
188 endif (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
190 # BLAS in Alpha CXML library?
191 if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
192 if(NOT BLAS_LIBRARIES)
193 check_fortran_libraries(
201 endif(NOT BLAS_LIBRARIES)
202 endif (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
204 # BLAS in Alpha DXML library? (now called CXML, see above)
205 if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
206 if(NOT BLAS_LIBRARIES)
207 check_fortran_libraries(
215 endif(NOT BLAS_LIBRARIES)
216 endif (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
218 # BLAS in Sun Performance library?
219 if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
220 if(NOT BLAS_LIBRARIES)
221 check_fortran_libraries(
230 set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
231 endif(BLAS_LIBRARIES)
232 endif(NOT BLAS_LIBRARIES)
233 endif (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
235 # BLAS in SCSL library? (SGI/Cray Scientific Library)
236 if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
237 if(NOT BLAS_LIBRARIES)
238 check_fortran_libraries(
246 endif(NOT BLAS_LIBRARIES)
247 endif (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
249 # BLAS in SGIMATH library?
250 if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
251 if(NOT BLAS_LIBRARIES)
252 check_fortran_libraries(
260 endif(NOT BLAS_LIBRARIES)
261 endif (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
263 # BLAS in IBM ESSL library? (requires generic BLAS lib, too)
264 if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
265 if(NOT BLAS_LIBRARIES)
266 check_fortran_libraries(
274 endif(NOT BLAS_LIBRARIES)
275 endif (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
277 #BLAS in acml library?
278 if (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All")
279 if( ((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
280 ((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR
281 ((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS))
283 # try to find acml in "standard" paths
285 file( GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt" )
287 file( GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt" )
290 file( GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples" )
292 file( GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples" )
294 list(GET _ACML_ROOT 0 _ACML_ROOT)
295 list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)
297 get_filename_component( _ACML_ROOT ${_ACML_ROOT} PATH )
298 if( SIZEOF_INTEGER EQUAL 8 )
299 set( _ACML_PATH_SUFFIX "_int64" )
301 set( _ACML_PATH_SUFFIX "" )
303 if( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
304 set( _ACML_COMPILER32 "ifort32" )
305 set( _ACML_COMPILER64 "ifort64" )
306 elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
307 set( _ACML_COMPILER32 "sun32" )
308 set( _ACML_COMPILER64 "sun64" )
309 elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" )
310 set( _ACML_COMPILER32 "pgi32" )
312 set( _ACML_COMPILER64 "win64" )
314 set( _ACML_COMPILER64 "pgi64" )
316 elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Open64" )
317 # 32 bit builds not supported on Open64 but for code simplicity
318 # We'll just use the same directory twice
319 set( _ACML_COMPILER32 "open64_64" )
320 set( _ACML_COMPILER64 "open64_64" )
321 elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" )
322 set( _ACML_COMPILER32 "nag32" )
323 set( _ACML_COMPILER64 "nag64" )
324 else() #if( CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" )
325 set( _ACML_COMPILER32 "gfortran32" )
326 set( _ACML_COMPILER64 "gfortran64" )
329 if( BLA_VENDOR STREQUAL "ACML_MP" )
330 set(_ACML_MP_LIB_DIRS
331 "${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib"
332 "${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib" )
333 else() #if( _BLAS_VENDOR STREQUAL "ACML" )
335 "${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib"
336 "${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib" )
339 elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)
340 set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})
343 if( BLA_VENDOR STREQUAL "ACML_MP" )
344 foreach( BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS})
345 check_fortran_libraries (
349 "" "acml_mp;acml_mv" "" ${BLAS_ACML_MP_LIB_DIRS}
355 elseif( BLA_VENDOR STREQUAL "ACML_GPU" )
356 foreach( BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS})
357 check_fortran_libraries (
361 "" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS}
367 else() #if( _BLAS_VENDOR STREQUAL "ACML" )
368 foreach( BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS} )
369 check_fortran_libraries (
373 "" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS}
381 # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
382 if(NOT BLAS_LIBRARIES)
383 check_fortran_libraries(
391 endif(NOT BLAS_LIBRARIES)
392 if(NOT BLAS_LIBRARIES)
393 check_fortran_libraries(
401 endif(NOT BLAS_LIBRARIES)
402 if(NOT BLAS_LIBRARIES)
403 check_fortran_libraries(
408 "acml;acml_mv;CALBLAS"
411 endif(NOT BLAS_LIBRARIES)
414 # Apple BLAS library?
415 if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
416 if(NOT BLAS_LIBRARIES)
417 check_fortran_libraries(
425 endif(NOT BLAS_LIBRARIES)
426 endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
428 if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
429 if ( NOT BLAS_LIBRARIES )
430 check_fortran_libraries(
438 endif ( NOT BLAS_LIBRARIES )
439 endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
440 # Generic BLAS library?
441 if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
442 if(NOT BLAS_LIBRARIES)
443 check_fortran_libraries(
451 endif(NOT BLAS_LIBRARIES)
452 endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
454 #BLAS in intel mkl 10 library? (em64t 64bit)
455 if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
459 if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
460 if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
461 find_package(Threads)
462 else(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
463 find_package(Threads REQUIRED)
464 endif(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
466 set(BLAS_SEARCH_LIBS "")
469 set(BLAS_mkl_SEARCH_SYMBOL SGEMM)
470 set(_LIBRARIES BLAS95_LIBRARIES)
472 list(APPEND BLAS_SEARCH_LIBS
473 "mkl_blas95 mkl_intel_c mkl_intel_thread mkl_core libguide40")
475 if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
476 list(APPEND BLAS_SEARCH_LIBS
477 "mkl_blas95 mkl_intel mkl_intel_thread mkl_core guide")
479 if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
481 list(APPEND BLAS_SEARCH_LIBS
482 "mkl_blas95 mkl_intel_lp64 mkl_intel_thread mkl_core guide")
485 if (CMAKE_C_COMPILER MATCHES ".+gcc.*")
486 list(APPEND BLAS_SEARCH_LIBS
487 "mkl_blas95_lp64 mkl_intel_lp64 mkl_gnu_thread mkl_core")
488 set(LM "${LM};-lgomp")
490 list(APPEND BLAS_SEARCH_LIBS
491 "mkl_blas95_lp64 mkl_intel_lp64 mkl_intel_thread mkl_core iomp5")
495 if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
496 list(APPEND BLAS_SEARCH_LIBS
497 "mkl_blas95_lp64 mkl_intel_lp64 mkl_sequential mkl_core")
500 set(BLAS_mkl_SEARCH_SYMBOL sgemm)
501 set(_LIBRARIES BLAS_LIBRARIES)
503 list(APPEND BLAS_SEARCH_LIBS
504 "mkl_c_dll mkl_intel_thread_dll mkl_core_dll libguide40")
506 if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
507 list(APPEND BLAS_SEARCH_LIBS
508 "mkl_intel mkl_intel_thread mkl_core guide")
510 if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
513 list(APPEND BLAS_SEARCH_LIBS
514 "mkl_intel_lp64 mkl_intel_thread mkl_core guide")
517 if (CMAKE_C_COMPILER MATCHES ".+gcc.*")
518 list(APPEND BLAS_SEARCH_LIBS
519 "mkl_intel_lp64 mkl_gnu_thread mkl_core")
520 set(LM "${LM};-lgomp")
522 list(APPEND BLAS_SEARCH_LIBS
523 "mkl_intel_lp64 mkl_intel_thread mkl_core iomp5")
527 #older vesions of intel mkl libs
528 if (BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All")
529 list(APPEND BLAS_SEARCH_LIBS
531 list(APPEND BLAS_SEARCH_LIBS
533 list(APPEND BLAS_SEARCH_LIBS
537 if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
538 list(APPEND BLAS_SEARCH_LIBS
539 "mkl_intel_lp64 mkl_sequential mkl_core")
543 foreach (IT ${BLAS_SEARCH_LIBS})
544 string(REPLACE " " ";" SEARCH_LIBS ${IT})
547 check_fortran_libraries(
550 ${BLAS_mkl_SEARCH_SYMBOL}
553 "${CMAKE_THREAD_LIBS_INIT};${LM}"
558 endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
559 endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
564 set(BLAS95_FOUND TRUE)
565 else(BLAS95_LIBRARIES)
566 set(BLAS95_FOUND FALSE)
567 endif(BLAS95_LIBRARIES)
569 if(NOT BLAS_FIND_QUIETLY)
571 message(STATUS "A library with BLAS95 API found.")
573 if(BLAS_FIND_REQUIRED)
575 "A required library with BLAS95 API not found. Please specify library location.")
576 else(BLAS_FIND_REQUIRED)
578 "A library with BLAS95 API not found. Please specify library location.")
579 endif(BLAS_FIND_REQUIRED)
581 endif(NOT BLAS_FIND_QUIETLY)
583 set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
588 set(BLAS_FOUND FALSE)
589 endif(BLAS_LIBRARIES)
591 if(NOT BLAS_FIND_QUIETLY)
593 message(STATUS "A library with BLAS API found.")
595 if(BLAS_FIND_REQUIRED)
597 "A required library with BLAS API not found. Please specify library location."
599 else(BLAS_FIND_REQUIRED)
601 "A library with BLAS API not found. Please specify library location."
603 endif(BLAS_FIND_REQUIRED)
605 endif(NOT BLAS_FIND_QUIETLY)
608 set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})