1 ############################################################################## 3 # @brief Find BLAS library. 5 # This module finds an installed fortran library that implements the BLAS 6 # linear-algebra interface (see http://www.netlib.org/blas/). 7 # The list of libraries searched for is taken 8 # from the autoconf macro file, acx_blas.m4 (distributed at 9 # http://ac-archive.sourceforge.net/ac-archive/acx_blas.html). 11 # Modified by Andreas Schuh to enable the use at SBIA, where an ATLAS C library 12 # is installed which contains the symbols without trailing _ character, i.e., 13 # instead of checking the existence of the cblas_dgemm_ function, the 14 # existence of the cblas_dgemm function has to be checked. Moreover, added 15 # code to mark variable as advanced and only show them to the user if 16 # no required library was found. If the found library is cblas, the corresponding 17 # header file cblas.h is searched as well. Therefore, added the BLAS_INCLUDE_DIR 18 # variable which is only defined if required. 20 # This module sets the following variables: 21 # BLAS_FOUND - set to true if a library implementing the BLAS interface 23 # BLAS_LINKER_FLAGS - uncached list of required linker flags (excluding -l 25 # BLAS_LIBRARIES - uncached list of libraries (using full path name) to 26 # link against to use BLAS 27 # BLAS_INCLUDE_DIR - uncached list of include directories for C libraries 28 # BLAS95_LIBRARIES - uncached list of libraries (using full path name) 29 # to link against to use BLAS95 interface 30 # BLAS95_FOUND - set to true if a library implementing the BLAS f95 interface 32 # BLA_STATIC if set on this determines what kind of linkage we do (static) 33 # BLA_VENDOR if set checks only the specified vendor, if not set checks 34 # all the possibilities 35 # BLA_F95 if set on tries to find the f95 interfaces for BLAS/LAPACK 37 # List of vendors (BLA_VENDOR) valid in this module 38 # 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), 39 # Intel( older versions of mkl 32 and 64 bit), ACML,ACML_MP,Apple, NAS, Generic 40 # C/CXX should be enabled to use Intel mkl 42 # @ingroup CMakeFindModules 43 ############################################################################## 45 # ============================================================================ 46 # Copyright 2007-2009 Kitware, Inc. 47 # All rights reserved. 49 # Distributed under the OSI-approved BSD License (the "License"); 50 # see accompanying file Copyright.txt for details. 52 # This software is distributed WITHOUT ANY WARRANTY; without even the 53 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 54 # See the License for more information. 55 #============================================================================= 56 # (To distribute this file outside of CMake, substitute the full 57 # License text for the above reference.) 59 set(BLAS_LIBRARIES_VARS) #
set by check_fortran_libraries() to a list of
60 # variable names of each searched library such 61 # that these libraries can be made non-advanced 62 # in case no library was found 64 include(CheckFunctionExists)
65 include(CheckFortranFunctionExists)
67 # Check the language being used 68 get_property( _LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES )
69 if( _LANGUAGES_ MATCHES Fortran )
71 elseif( (_LANGUAGES_ MATCHES C) OR (_LANGUAGES_ MATCHES
CXX) )
74 if(BLAS_FIND_REQUIRED)
75 message(FATAL_ERROR
"FindBLAS requires Fortran, C, or C++ to be enabled.")
76 else(BLAS_FIND_REQUIRED)
77 message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)")
79 endif(BLAS_FIND_REQUIRED)
83 # This macro checks for the existence of the combination of fortran libraries 84 # given by _list. If the combination is found, this macro checks (using the 85 # Check_Fortran_Function_Exists macro) whether can link against that library 86 # combination using the name of a routine given by _name using the linker 87 # flags given by _flags. If the combination of libraries is found and passes 88 # the link test, LIBRARIES is set to the list of complete library paths that 89 # have been found. Otherwise, LIBRARIES is set to FALSE. 91 # N.B. _prefix is the prefix applied to the names of all cached variables that 92 # are generated internally and marked advanced by this macro. 94 set(_libraries_work TRUE)
97 foreach(_library ${_list})
98 set(_combined_name ${_combined_name}_${_library})
105 find_library(${
_prefix}_${_library}_LIBRARY
115 find_library(${
_prefix}_${_library}_LIBRARY
117 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
124 find_library(${
_prefix}_${_library}_LIBRARY
126 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
129 mark_as_advanced(${
_prefix}_${_library}_LIBRARY)
130 list (APPEND BLAS_LIBRARIES_VARS ${
_prefix}_${_library}_LIBRARY)
131 set(${LIBRARIES} ${${LIBRARIES}} ${${
_prefix}_${_library}_LIBRARY})
132 set(_libraries_work ${${
_prefix}_${_library}_LIBRARY})
133 endif(_libraries_work)
134 endforeach(_library ${_list})
136 # Test this combination of libraries. 137 set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_threads})
138 # message(
"DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
140 check_fortran_function_exists(
"${_name}" ${
_prefix}${_combined_name}_WORKS)
142 check_function_exists(
"${_name}" ${
_prefix}${_combined_name}_WORKS)
143 if (NOT ${
_prefix}${_combined_name}_WORKS)
144 check_function_exists(
"${_name}_" ${
_prefix}${_combined_name}_WORKS)
147 set(CMAKE_REQUIRED_LIBRARIES)
148 mark_as_advanced(${
_prefix}${_combined_name}_WORKS)
149 set(_libraries_work ${${
_prefix}${_combined_name}_WORKS})
150 endif(_libraries_work)
151 if(NOT _libraries_work)
152 set(${LIBRARIES} FALSE)
153 endif(NOT _libraries_work)
154 #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}") 159 set(BLAS95_LIBRARIES)
164 set(BLA_VENDOR
"All")
165 endif(NOT BLA_VENDOR)
166 endif ($ENV{BLA_VENDOR} MATCHES
".+")
168 if (BLA_VENDOR STREQUAL
"ATLAS" OR BLA_VENDOR STREQUAL
"All")
170 # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/) 171 check_fortran_libraries(
176 "cblas;f77blas;atlas" 179 if (BLAS_LIBRARIES_VARS MATCHES
"cblas")
180 find_path (BLAS_INCLUDE_DIR NAMES cblas.h DOC
"Include directory of the cblas.h header file.")
182 endif(NOT BLAS_LIBRARIES)
183 endif (BLA_VENDOR STREQUAL
"ATLAS" OR BLA_VENDOR STREQUAL
"All")
185 # BLAS in PhiPACK libraries? (requires generic BLAS lib, too) 186 if (BLA_VENDOR STREQUAL
"PhiPACK" OR BLA_VENDOR STREQUAL
"All")
187 if(NOT BLAS_LIBRARIES)
188 check_fortran_libraries(
196 endif(NOT BLAS_LIBRARIES)
197 endif (BLA_VENDOR STREQUAL
"PhiPACK" OR BLA_VENDOR STREQUAL
"All")
199 # BLAS in Alpha CXML library? 200 if (BLA_VENDOR STREQUAL
"CXML" OR BLA_VENDOR STREQUAL
"All")
201 if(NOT BLAS_LIBRARIES)
202 check_fortran_libraries(
210 endif(NOT BLAS_LIBRARIES)
211 endif (BLA_VENDOR STREQUAL
"CXML" OR BLA_VENDOR STREQUAL
"All")
213 # BLAS in Alpha DXML library? (now called CXML, see above) 214 if (BLA_VENDOR STREQUAL
"DXML" OR BLA_VENDOR STREQUAL
"All")
215 if(NOT BLAS_LIBRARIES)
216 check_fortran_libraries(
224 endif(NOT BLAS_LIBRARIES)
225 endif (BLA_VENDOR STREQUAL
"DXML" OR BLA_VENDOR STREQUAL
"All")
227 # BLAS in Sun Performance library? 228 if (BLA_VENDOR STREQUAL
"SunPerf" OR BLA_VENDOR STREQUAL
"All")
229 if(NOT BLAS_LIBRARIES)
230 check_fortran_libraries(
240 endif(BLAS_LIBRARIES)
241 endif(NOT BLAS_LIBRARIES)
242 endif (BLA_VENDOR STREQUAL
"SunPerf" OR BLA_VENDOR STREQUAL
"All")
244 # BLAS in SCSL library? (SGI/Cray Scientific Library) 245 if (BLA_VENDOR STREQUAL
"SCSL" OR BLA_VENDOR STREQUAL
"All")
246 if(NOT BLAS_LIBRARIES)
247 check_fortran_libraries(
255 endif(NOT BLAS_LIBRARIES)
256 endif (BLA_VENDOR STREQUAL
"SCSL" OR BLA_VENDOR STREQUAL
"All")
258 # BLAS in SGIMATH library? 259 if (BLA_VENDOR STREQUAL
"SGIMATH" OR BLA_VENDOR STREQUAL
"All")
260 if(NOT BLAS_LIBRARIES)
261 check_fortran_libraries(
269 endif(NOT BLAS_LIBRARIES)
270 endif (BLA_VENDOR STREQUAL
"SGIMATH" OR BLA_VENDOR STREQUAL
"All")
272 # BLAS in IBM ESSL library? (requires generic BLAS lib, too) 273 if (BLA_VENDOR STREQUAL
"IBMESSL" OR BLA_VENDOR STREQUAL
"All")
274 if(NOT BLAS_LIBRARIES)
275 check_fortran_libraries(
283 endif(NOT BLAS_LIBRARIES)
284 endif (BLA_VENDOR STREQUAL
"IBMESSL" OR BLA_VENDOR STREQUAL
"All")
286 #BLAS in acml library? 287 if (BLA_VENDOR STREQUAL
"ACML" OR BLA_VENDOR STREQUAL
"ACML_MP" OR BLA_VENDOR STREQUAL
"All")
288 # the patch from Chuck Atkins: 289 if( ((_BLAS_VENDOR STREQUAL
"ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
290 ((_BLAS_VENDOR STREQUAL
"ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) )
292 file( GLOB _ACML_ROOT
"C:/AMD/acml*/ACML-EULA.txt" )
294 file( GLOB _ACML_ROOT
"/opt/acml*/ACML-EULA.txt" )
298 if( SIZEOF_INTEGER EQUAL 8 )
303 if( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
306 elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
309 elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" )
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 321 elseif( CMAKE_Fortran_COMPILER_ID STREQUAL
"NAG" )
324 else() #
if( CMAKE_Fortran_COMPILER_ID STREQUAL
"GNU" )
329 if( _BLAS_VENDOR STREQUAL "ACML_MP" )
330 set(_ACML_MP_LIB_DIRS
333 else() #if( _BLAS_VENDOR STREQUAL "ACML
" ) 341 if( _BLAS_VENDOR STREQUAL "ACML_MP
" ) 342 foreach( BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS} ) 343 _BLAS_LOCATE_AND_TEST( ${_BLAS_VENDOR} "acml_mp;acml_mv
" "" ) 344 if( BLAS_${_BLAS_VENDOR}_FOUND ) 348 else() #if( _BLAS_VENDOR STREQUAL "ACML
" ) 349 foreach( BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS} ) 350 _BLAS_LOCATE_AND_TEST( ${_BLAS_VENDOR} "acml;acml_mv
" "" ) 351 if( BLAS_${_BLAS_VENDOR}_FOUND ) 357 # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both 358 if(NOT BLAS_LIBRARIES) 359 check_fortran_libraries( 367 endif(NOT BLAS_LIBRARIES) 368 if(NOT BLAS_LIBRARIES) 369 check_fortran_libraries( 377 endif(NOT BLAS_LIBRARIES) 380 # Apple BLAS library? 381 if (BLA_VENDOR STREQUAL "Apple
" OR BLA_VENDOR STREQUAL "All
") 382 if(NOT BLAS_LIBRARIES) 383 check_fortran_libraries( 391 endif(NOT BLAS_LIBRARIES) 392 endif (BLA_VENDOR STREQUAL "Apple
" OR BLA_VENDOR STREQUAL "All
") 394 if (BLA_VENDOR STREQUAL "NAS
" OR BLA_VENDOR STREQUAL "All
") 395 if ( NOT BLAS_LIBRARIES ) 396 check_fortran_libraries( 404 endif ( NOT BLAS_LIBRARIES ) 405 endif (BLA_VENDOR STREQUAL "NAS
" OR BLA_VENDOR STREQUAL "All
") 406 # Generic BLAS library? 407 if (BLA_VENDOR STREQUAL "Generic
" OR BLA_VENDOR STREQUAL "All
") 408 if(NOT BLAS_LIBRARIES) 409 check_fortran_libraries( 417 endif(NOT BLAS_LIBRARIES) 418 endif (BLA_VENDOR STREQUAL "Generic
" OR BLA_VENDOR STREQUAL "All
") 420 #BLAS in intel mkl 10 library? (em64t 64bit) 421 if (BLA_VENDOR MATCHES "Intel*
" OR BLA_VENDOR STREQUAL "All
") 425 if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX) 426 if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED) 427 find_package(Threads) 428 else(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED) 429 find_package(Threads REQUIRED) 430 endif(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED) 433 if(NOT BLAS95_LIBRARIES) 434 check_fortran_libraries( 439 "mkl_blas95;mkl_intel_c;mkl_intel_thread;mkl_core;libguide40
" 442 endif(NOT BLAS95_LIBRARIES) 444 if(NOT BLAS_LIBRARIES) 445 check_fortran_libraries( 450 "mkl_c_dll;mkl_intel_thread_dll;mkl_core_dll;libguide40
" 453 endif(NOT BLAS_LIBRARIES) 456 if (BLA_VENDOR STREQUAL "Intel10_32
" OR BLA_VENDOR STREQUAL "All
") 458 if(NOT BLAS95_LIBRARIES) 459 check_fortran_libraries( 464 "mkl_blas95;mkl_intel;mkl_intel_thread;mkl_core;guide
" 465 "${CMAKE_THREAD_LIBS_INIT};${
LM}
" 467 endif(NOT BLAS95_LIBRARIES) 469 if(NOT BLAS_LIBRARIES) 470 check_fortran_libraries( 475 "mkl_intel;mkl_intel_thread;mkl_core;guide
" 476 "${CMAKE_THREAD_LIBS_INIT}
" 479 endif(NOT BLAS_LIBRARIES) 481 endif (BLA_VENDOR STREQUAL "Intel10_32
" OR BLA_VENDOR STREQUAL "All
") 482 if (BLA_VENDOR STREQUAL "Intel10_64lp
" OR BLA_VENDOR STREQUAL "All
") 484 if(NOT BLAS95_LIBRARIES) 485 check_fortran_libraries( 490 "mkl_blas95;mkl_intel_lp64;mkl_intel_thread;mkl_core;guide
" 491 "${CMAKE_THREAD_LIBS_INIT};${
LM}
" 493 endif(NOT BLAS95_LIBRARIES) 495 if(NOT BLAS_LIBRARIES) 496 check_fortran_libraries( 501 "mkl_intel_lp64;mkl_intel_thread;mkl_core;guide
" 502 "${CMAKE_THREAD_LIBS_INIT};${
LM}
" 504 endif(NOT BLAS_LIBRARIES) 506 endif (BLA_VENDOR STREQUAL "Intel10_64lp
" OR BLA_VENDOR STREQUAL "All
") 508 #older vesions of intel mkl libs 509 # BLAS in intel mkl library? (shared) 510 if(NOT BLAS_LIBRARIES) 511 check_fortran_libraries( 517 "${CMAKE_THREAD_LIBS_INIT};${
LM}
" 519 endif(NOT BLAS_LIBRARIES) 520 #BLAS in intel mkl library? (static, 32bit) 521 if(NOT BLAS_LIBRARIES) 522 check_fortran_libraries( 528 "${CMAKE_THREAD_LIBS_INIT};${
LM}
" 530 endif(NOT BLAS_LIBRARIES) 531 #BLAS in intel mkl library? (static, em64t 64bit) 532 if(NOT BLAS_LIBRARIES) 533 check_fortran_libraries( 539 "${CMAKE_THREAD_LIBS_INIT};${
LM}
" 541 endif(NOT BLAS_LIBRARIES) 542 endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX) 543 endif (BLA_VENDOR MATCHES "Intel*
" OR BLA_VENDOR STREQUAL "All
") 545 if (BLAS_LIBRARIES_VARS) 546 mark_as_advanced (FORCE ${BLAS_LIBRARIES_VARS}) 548 if (BLAS95_LIBRARIES) 549 mark_as_advanced (FORCE ${BLAS95_LIBRARIES}) 551 if (BLAS_INCLUDE_DIR) 552 mark_as_advanced (FORCE BLAS_INCLUDE_DIR) 557 set(BLAS95_FOUND TRUE) 558 else(BLAS95_LIBRARIES) 559 set(BLAS95_FOUND FALSE) 560 endif(BLAS95_LIBRARIES) 562 if(NOT BLAS_FIND_QUIETLY) 564 mark_as_advanced (${BLAS95_LIBRARIES}) 565 message(STATUS "A library with BLAS95 API found.
") 567 if(BLAS_FIND_REQUIRED) 568 mark_as_advanced (CLEAR ${BLAS95_LIBRARIES}) 570 "A required library with BLAS95 API not found. Please specify library location.
") 571 else(BLAS_FIND_REQUIRED) 573 "A library with BLAS95 API not found. Please specify library location.
") 574 endif(BLAS_FIND_REQUIRED) 576 endif(NOT BLAS_FIND_QUIETLY) 578 set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}
") 581 if(BLAS_LIBRARIES_VARS MATCHES "cblas
" AND NOT BLAS_INCLUDE_DIR) 582 set(BLAS_FOUND FALSE) 587 set(BLAS_FOUND FALSE) 588 endif(BLAS_LIBRARIES) 590 if(NOT BLAS_FIND_QUIETLY) 592 message(STATUS "A library with BLAS API found.
") 594 if(BLAS_LIBRARIES AND BLAS_cblas_LIBRARY AND NOT BLAS_INCLUDE_DIR) 595 if(BLAS_FIND_REQUIRED) 596 mark_as_advanced (CLEAR BLAS_INCLUDE_DIR) 598 "Location of cblas.h header file
for C BLAS library not found!
" 599 " Please specify the directory containing
this file
for library ${BLAS_cblas_LIBRARY}
" 600 " using the BLAS_INCLUDE_DIR variable.
" 602 else(BLAS_FIND_REQUIRED) 604 "Location of cblas.h header file
for C BLAS library not found! Please specify header location.
" 606 endif(BLAS_FIND_REQUIRED) 608 if(BLAS_FIND_REQUIRED) 609 mark_as_advanced (CLEAR ${BLAS_LIBRARIES_VARS}) 611 "A required library with BLAS API not found. Please specify library location
" 612 " by setting the following variables: [${BLAS_LIBRARIES_VARS}].
" 614 else(BLAS_FIND_REQUIRED) 616 "A library with BLAS API not found. Please specify library location.
" 618 endif(BLAS_FIND_REQUIRED) 621 endif(NOT BLAS_FIND_QUIETLY) 624 unset(BLAS_LIBRARIES_VARS)
cmake CMAKE_FIND_LIBRARY_SUFFIXES
macro Check_Fortran_Libraries(in LIBRARIES, in _prefix, in _name, in _flags, in _list, in _threads)
function get_filename_component(inout ARGN)
Fixes CMake's get_filename_component() command.