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.")
58 message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)")
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 ENV DYLD_LIBRARY_PATH)
86 set(_libdir 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})
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})
131 if(NOT _libraries_work)
132 set(${LIBRARIES} FALSE)
134 #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
137 set(BLAS_LINKER_FLAGS)
139 set(BLAS95_LIBRARIES)
140 if ($ENV{BLA_VENDOR} MATCHES ".+")
141 set(BLA_VENDOR $ENV{BLA_VENDOR})
144 set(BLA_VENDOR "All")
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(
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(
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(
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(
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(
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")
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(
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(
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(
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" )
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" )
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}
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(
392 if(NOT BLAS_LIBRARIES)
393 check_fortran_libraries(
402 if(NOT BLAS_LIBRARIES)
403 check_fortran_libraries(
408 "acml;acml_mv;CALBLAS"
414 # Apple BLAS library?
415 if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
416 if(NOT BLAS_LIBRARIES)
417 check_fortran_libraries(
428 if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
429 if ( NOT BLAS_LIBRARIES )
430 check_fortran_libraries(
440 # Generic BLAS library?
441 if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
442 if(NOT BLAS_LIBRARIES)
443 check_fortran_libraries(
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)
463 find_package(Threads 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 gomp")
489 list(APPEND BLAS_SEARCH_LIBS
490 "mkl_blas95_lp64 mkl_intel_lp64 mkl_intel_thread mkl_core iomp5")
494 if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
495 list(APPEND BLAS_SEARCH_LIBS
496 "mkl_blas95_lp64 mkl_intel_lp64 mkl_sequential mkl_core")
499 set(BLAS_mkl_SEARCH_SYMBOL sgemm)
500 set(_LIBRARIES BLAS_LIBRARIES)
502 list(APPEND BLAS_SEARCH_LIBS
503 "mkl_c_dll mkl_intel_thread_dll mkl_core_dll libguide40")
505 if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
506 list(APPEND BLAS_SEARCH_LIBS
507 "mkl_intel mkl_intel_thread mkl_core guide")
509 if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
512 list(APPEND BLAS_SEARCH_LIBS
513 "mkl_intel_lp64 mkl_intel_thread mkl_core guide")
516 if (CMAKE_C_COMPILER MATCHES ".+gcc.*")
517 list(APPEND BLAS_SEARCH_LIBS
518 "mkl_intel_lp64 mkl_gnu_thread mkl_core gomp")
520 list(APPEND BLAS_SEARCH_LIBS
521 "mkl_intel_lp64 mkl_intel_thread mkl_core iomp5")
525 #older vesions of intel mkl libs
526 if (BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All")
527 list(APPEND BLAS_SEARCH_LIBS
529 list(APPEND BLAS_SEARCH_LIBS
531 list(APPEND BLAS_SEARCH_LIBS
535 if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
536 list(APPEND BLAS_SEARCH_LIBS
537 "mkl_intel_lp64 mkl_sequential mkl_core")
541 foreach (IT ${BLAS_SEARCH_LIBS})
542 string(REPLACE " " ";" SEARCH_LIBS ${IT})
545 check_fortran_libraries(
548 ${BLAS_mkl_SEARCH_SYMBOL}
551 "${CMAKE_THREAD_LIBS_INIT};${LM}"
562 set(BLAS95_FOUND TRUE)
564 set(BLAS95_FOUND FALSE)
567 if(NOT BLAS_FIND_QUIETLY)
569 message(STATUS "A library with BLAS95 API found.")
571 if(BLAS_FIND_REQUIRED)
573 "A required library with BLAS95 API not found. Please specify library location.")
576 "A library with BLAS95 API not found. Please specify library location.")
581 set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
586 set(BLAS_FOUND FALSE)
589 if(NOT BLAS_FIND_QUIETLY)
591 message(STATUS "A library with BLAS API found.")
593 if(BLAS_FIND_REQUIRED)
595 "A required library with BLAS API not found. Please specify library location."
599 "A library with BLAS API not found. Please specify library location."
606 set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})