• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1###
2#
3# @copyright (c) 2009-2014 The University of Tennessee and The University
4#                          of Tennessee Research Foundation.
5#                          All rights reserved.
6# @copyright (c) 2012-2016 Inria. All rights reserved.
7# @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
8#
9###
10#
11# - Find BLAS library
12# This module finds an installed fortran library that implements the BLAS
13# linear-algebra interface (see http://www.netlib.org/blas/).
14# The list of libraries searched for is taken
15# from the autoconf macro file, acx_blas.m4 (distributed at
16# http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
17#
18# This module sets the following variables:
19#  BLAS_FOUND - set to true if a library implementing the BLAS interface
20#    is found
21#  BLAS_LINKER_FLAGS - uncached list of required linker flags (excluding -l
22#    and -L).
23#  BLAS_COMPILER_FLAGS - uncached list of required compiler flags (including -I for mkl headers).
24#  BLAS_LIBRARIES - uncached list of libraries (using full path name) to
25#    link against to use BLAS
26#  BLAS95_LIBRARIES - uncached list of libraries (using full path name)
27#    to link against to use BLAS95 interface
28#  BLAS95_FOUND - set to true if a library implementing the BLAS f95 interface
29#    is found
30#  BLA_STATIC  if set on this determines what kind of linkage we do (static)
31#  BLA_VENDOR  if set checks only the specified vendor, if not set checks
32#     all the possibilities
33#  BLAS_VENDOR_FOUND stores the BLAS vendor found
34#  BLA_F95     if set on tries to find the f95 interfaces for BLAS/LAPACK
35# The user can give specific paths where to find the libraries adding cmake
36# options at configure (ex: cmake path/to/project -DBLAS_DIR=path/to/blas):
37#  BLAS_DIR            - Where to find the base directory of blas
38#  BLAS_INCDIR         - Where to find the header files
39#  BLAS_LIBDIR         - Where to find the library files
40# The module can also look for the following environment variables if paths
41# are not given as cmake variable: BLAS_DIR, BLAS_INCDIR, BLAS_LIBDIR
42# For MKL case and if no paths are given as hints, we will try to use the MKLROOT
43# environment variable
44#  BLAS_VERBOSE Print some additional information during BLAS libraries detection
45##########
46### List of vendors (BLA_VENDOR) valid in this module
47########## List of vendors (BLA_VENDOR) valid in this module
48##  Open (for OpenBlas), Eigen (for EigenBlas), Goto, ATLAS PhiPACK,
49##  CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, IBMESSLMT
50##  Intel10_32 (intel mkl v10 32 bit), Intel10_64lp (intel mkl v10 64 bit,lp thread model, lp64 model),
51##  Intel10_64lp_seq (intel mkl v10 64 bit,sequential code, lp64 model),
52##  Intel( older versions of mkl 32 and 64 bit),
53##  ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic
54# C/CXX should be enabled to use Intel mkl
55###
56# We handle different modes to find the dependency
57#
58# - Detection if already installed on the system
59#   - BLAS libraries can be detected from different ways
60#     Here is the order of precedence:
61#     1) we look in cmake variable BLAS_LIBDIR or BLAS_DIR (we guess the libdirs) if defined
62#     2) we look in environment variable BLAS_LIBDIR or BLAS_DIR (we guess the libdirs) if defined
63#     3) we look in common environnment variables depending on the system (INCLUDE, C_INCLUDE_PATH, CPATH - LIB, DYLD_LIBRARY_PATH, LD_LIBRARY_PATH)
64#     4) we look in common system paths depending on the system, see for example paths contained in the following cmake variables:
65#       - CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES, CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
66#       - CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES, CMAKE_C_IMPLICIT_LINK_DIRECTORIES
67#
68
69#=============================================================================
70# Copyright 2007-2009 Kitware, Inc.
71#
72# Distributed under the OSI-approved BSD License (the "License");
73# see accompanying file Copyright.txt for details.
74#
75# This software is distributed WITHOUT ANY WARRANTY; without even the
76# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
77# See the License for more information.
78#=============================================================================
79# (To distribute this file outside of CMake, substitute the full
80#  License text for the above reference.)
81
82## Some macros to print status when search for headers and libs
83# This macro informs why the _lib_to_find file has not been found
84macro(Print_Find_Library_Blas_Status _libname _lib_to_find)
85
86  # save _libname upper/lower case
87  string(TOUPPER ${_libname} LIBNAME)
88  string(TOLOWER ${_libname} libname)
89
90  # print status
91  #message(" ")
92  if(${LIBNAME}_LIBDIR)
93    message("${Yellow}${LIBNAME}_LIBDIR is defined but ${_lib_to_find}"
94      "has not been found in ${ARGN}${ColourReset}")
95  else()
96    if(${LIBNAME}_DIR)
97      message("${Yellow}${LIBNAME}_DIR is defined but ${_lib_to_find}"
98	"has not been found in ${ARGN}${ColourReset}")
99    else()
100      message("${Yellow}${_lib_to_find} not found."
101	"Nor ${LIBNAME}_DIR neither ${LIBNAME}_LIBDIR"
102	"are defined so that we look for ${_lib_to_find} in"
103	"system paths (Linux: LD_LIBRARY_PATH, Windows: LIB,"
104	"Mac: DYLD_LIBRARY_PATH,"
105	"CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES,"
106	"CMAKE_C_IMPLICIT_LINK_DIRECTORIES)${ColourReset}")
107      if(_lib_env)
108	message("${Yellow}${_lib_to_find} has not been found in"
109	  "${_lib_env}${ColourReset}")
110      endif()
111    endif()
112  endif()
113  message("${BoldYellow}Please indicate where to find ${_lib_to_find}. You have three options:\n"
114    "- Option 1: Provide the Installation directory of BLAS library with cmake option: -D${LIBNAME}_DIR=your/path/to/${libname}/\n"
115    "- Option 2: Provide the directory where to find the library with cmake option: -D${LIBNAME}_LIBDIR=your/path/to/${libname}/lib/\n"
116    "- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
117    "- Option 4: If your library provides a PkgConfig file, make sure pkg-config finds your library${ColourReset}")
118
119endmacro()
120
121# This macro informs why the _lib_to_find file has not been found
122macro(Print_Find_Library_Blas_CheckFunc_Status _name)
123
124  # save _libname upper/lower case
125  string(TOUPPER ${_name} FUNCNAME)
126  string(TOLOWER ${_name} funcname)
127
128  # print status
129  #message(" ")
130  message("${Red}Libs have been found but check of symbol ${_name} failed "
131    "with following libraries ${ARGN}${ColourReset}")
132  message("${BoldRed}Please open your error file CMakeFiles/CMakeError.log"
133    "to figure out why it fails${ColourReset}")
134  #message(" ")
135
136endmacro()
137
138if (NOT BLAS_FOUND)
139  set(BLAS_DIR "" CACHE PATH "Installation directory of BLAS library")
140  if (NOT BLAS_FIND_QUIETLY)
141    message(STATUS "A cache variable, namely BLAS_DIR, has been set to specify the install directory of BLAS")
142  endif()
143endif()
144
145option(BLAS_VERBOSE "Print some additional information during BLAS libraries detection" OFF)
146mark_as_advanced(BLAS_VERBOSE)
147
148include(CheckFunctionExists)
149include(CheckFortranFunctionExists)
150
151set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
152
153# Check the language being used
154get_property( _LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES )
155if( _LANGUAGES_ MATCHES Fortran )
156  set( _CHECK_FORTRAN TRUE )
157elseif( (_LANGUAGES_ MATCHES C) OR (_LANGUAGES_ MATCHES CXX) )
158  set( _CHECK_FORTRAN FALSE )
159else()
160  if(BLAS_FIND_REQUIRED)
161    message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.")
162  else()
163    message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)")
164    return()
165  endif()
166endif()
167
168macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _thread)
169  # This macro checks for the existence of the combination of fortran libraries
170  # given by _list.  If the combination is found, this macro checks (using the
171  # Check_Fortran_Function_Exists macro) whether can link against that library
172  # combination using the name of a routine given by _name using the linker
173  # flags given by _flags.  If the combination of libraries is found and passes
174  # the link test, LIBRARIES is set to the list of complete library paths that
175  # have been found.  Otherwise, LIBRARIES is set to FALSE.
176
177  # N.B. _prefix is the prefix applied to the names of all cached variables that
178  # are generated internally and marked advanced by this macro.
179
180  set(_libdir ${ARGN})
181
182  set(_libraries_work TRUE)
183  set(${LIBRARIES})
184  set(_combined_name)
185  set(ENV_MKLROOT "$ENV{MKLROOT}")
186  set(ENV_BLAS_DIR "$ENV{BLAS_DIR}")
187  set(ENV_BLAS_LIBDIR "$ENV{BLAS_LIBDIR}")
188  if (NOT _libdir)
189    if (BLAS_LIBDIR)
190      list(APPEND _libdir "${BLAS_LIBDIR}")
191    elseif (BLAS_DIR)
192      list(APPEND _libdir "${BLAS_DIR}")
193      list(APPEND _libdir "${BLAS_DIR}/lib")
194      if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
195	list(APPEND _libdir "${BLAS_DIR}/lib64")
196	list(APPEND _libdir "${BLAS_DIR}/lib/intel64")
197      else()
198	list(APPEND _libdir "${BLAS_DIR}/lib32")
199	list(APPEND _libdir "${BLAS_DIR}/lib/ia32")
200      endif()
201    elseif(ENV_BLAS_LIBDIR)
202      list(APPEND _libdir "${ENV_BLAS_LIBDIR}")
203    elseif(ENV_BLAS_DIR)
204      list(APPEND _libdir "${ENV_BLAS_DIR}")
205      list(APPEND _libdir "${ENV_BLAS_DIR}/lib")
206      if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
207	list(APPEND _libdir "${ENV_BLAS_DIR}/lib64")
208	list(APPEND _libdir "${ENV_BLAS_DIR}/lib/intel64")
209      else()
210	list(APPEND _libdir "${ENV_BLAS_DIR}/lib32")
211	list(APPEND _libdir "${ENV_BLAS_DIR}/lib/ia32")
212      endif()
213    else()
214      if (ENV_MKLROOT)
215	list(APPEND _libdir "${ENV_MKLROOT}/lib")
216	if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
217	  list(APPEND _libdir "${ENV_MKLROOT}/lib64")
218	  list(APPEND _libdir "${ENV_MKLROOT}/lib/intel64")
219	else()
220	  list(APPEND _libdir "${ENV_MKLROOT}/lib32")
221	  list(APPEND _libdir "${ENV_MKLROOT}/lib/ia32")
222	endif()
223      endif()
224      if (WIN32)
225	string(REPLACE ":" ";" _libdir2 "$ENV{LIB}")
226      elseif (APPLE)
227	string(REPLACE ":" ";" _libdir2 "$ENV{DYLD_LIBRARY_PATH}")
228      else ()
229	string(REPLACE ":" ";" _libdir2 "$ENV{LD_LIBRARY_PATH}")
230      endif ()
231      list(APPEND _libdir "${_libdir2}")
232      list(APPEND _libdir "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
233      list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
234    endif()
235  endif ()
236
237  if (BLAS_VERBOSE)
238    message("${Cyan}Try to find BLAS libraries: ${_list}")
239  endif ()
240
241  foreach(_library ${_list})
242    set(_combined_name ${_combined_name}_${_library})
243
244    if(_libraries_work)
245      if (BLA_STATIC)
246	if (WIN32)
247	  set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
248	endif ()
249	if (APPLE)
250	  set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
251	else ()
252	  set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
253	endif ()
254      else ()
255	if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
256	  # for ubuntu's libblas3gf and liblapack3gf packages
257	  set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
258	endif ()
259      endif ()
260      find_library(${_prefix}_${_library}_LIBRARY
261	NAMES ${_library}
262	HINTS ${_libdir}
263	NO_DEFAULT_PATH
264	)
265      mark_as_advanced(${_prefix}_${_library}_LIBRARY)
266      # Print status if not found
267      # -------------------------
268      if (NOT ${_prefix}_${_library}_LIBRARY AND NOT BLAS_FIND_QUIETLY AND BLAS_VERBOSE)
269	Print_Find_Library_Blas_Status(blas ${_library} ${_libdir})
270      endif ()
271      set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
272      set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
273    endif(_libraries_work)
274  endforeach(_library ${_list})
275
276  if(_libraries_work)
277    # Test this combination of libraries.
278    if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND BLA_STATIC)
279      list(INSERT ${LIBRARIES} 0 "-Wl,--start-group")
280      list(APPEND ${LIBRARIES} "-Wl,--end-group")
281    endif()
282    set(CMAKE_REQUIRED_LIBRARIES "${_flags};${${LIBRARIES}};${_thread}")
283    set(CMAKE_REQUIRED_FLAGS "${BLAS_COMPILER_FLAGS}")
284    if (BLAS_VERBOSE)
285      message("${Cyan}BLAS libs found for BLA_VENDOR ${BLA_VENDOR}."
286	"Try to compile symbol ${_name} with following libraries:"
287	"${CMAKE_REQUIRED_LIBRARIES}")
288    endif ()
289    if(NOT BLAS_FOUND)
290      unset(${_prefix}${_combined_name}_WORKS CACHE)
291    endif()
292    if (_CHECK_FORTRAN)
293      if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
294	string(REPLACE "mkl_intel_lp64" "mkl_gf_lp64" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
295	string(REPLACE "mkl_intel_ilp64" "mkl_gf_ilp64" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
296      endif()
297      check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
298    else()
299      check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
300    endif()
301    mark_as_advanced(${_prefix}${_combined_name}_WORKS)
302    set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
303    # Print status if not found
304    # -------------------------
305    if (NOT _libraries_work AND NOT BLAS_FIND_QUIETLY AND BLAS_VERBOSE)
306      Print_Find_Library_Blas_CheckFunc_Status(${_name} ${CMAKE_REQUIRED_LIBRARIES})
307    endif ()
308    set(CMAKE_REQUIRED_LIBRARIES)
309  endif()
310
311  if(_libraries_work)
312    set(${LIBRARIES} ${${LIBRARIES}} ${_thread})
313  else(_libraries_work)
314    set(${LIBRARIES} FALSE)
315  endif(_libraries_work)
316
317endmacro(Check_Fortran_Libraries)
318
319
320set(BLAS_LINKER_FLAGS)
321set(BLAS_LIBRARIES)
322set(BLAS95_LIBRARIES)
323if ($ENV{BLA_VENDOR} MATCHES ".+")
324  set(BLA_VENDOR $ENV{BLA_VENDOR})
325else ()
326  if(NOT BLA_VENDOR)
327    set(BLA_VENDOR "All")
328  endif()
329endif ()
330
331#BLAS in intel mkl 10 library? (em64t 64bit)
332if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
333
334  if(NOT BLAS_LIBRARIES OR BLA_VENDOR MATCHES "Intel*")
335    # Looking for include
336    # -------------------
337
338    # Add system include paths to search include
339    # ------------------------------------------
340    unset(_inc_env)
341    set(ENV_MKLROOT "$ENV{MKLROOT}")
342    set(ENV_BLAS_DIR "$ENV{BLAS_DIR}")
343    set(ENV_BLAS_INCDIR "$ENV{BLAS_INCDIR}")
344    if(ENV_BLAS_INCDIR)
345      list(APPEND _inc_env "${ENV_BLAS_INCDIR}")
346    elseif(ENV_BLAS_DIR)
347      list(APPEND _inc_env "${ENV_BLAS_DIR}")
348      list(APPEND _inc_env "${ENV_BLAS_DIR}/include")
349    else()
350      if (ENV_MKLROOT)
351	list(APPEND _inc_env "${ENV_MKLROOT}/include")
352      endif()
353      # system variables
354      if(WIN32)
355	string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
356	list(APPEND _inc_env "${_path_env}")
357      else()
358	string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
359	list(APPEND _inc_env "${_path_env}")
360	string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
361	list(APPEND _inc_env "${_path_env}")
362	string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
363	list(APPEND _inc_env "${_path_env}")
364	string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
365	list(APPEND _inc_env "${_path_env}")
366      endif()
367    endif()
368    list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
369    list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
370    list(REMOVE_DUPLICATES _inc_env)
371
372    # set paths where to look for
373    set(PATH_TO_LOOK_FOR "${_inc_env}")
374
375    # Try to find the fftw header in the given paths
376    # -------------------------------------------------
377    # call cmake macro to find the header path
378    if(BLAS_INCDIR)
379      set(BLAS_mkl.h_DIRS "BLAS_mkl.h_DIRS-NOTFOUND")
380      find_path(BLAS_mkl.h_DIRS
381	NAMES mkl.h
382	HINTS ${BLAS_INCDIR})
383    else()
384      if(BLAS_DIR)
385	set(BLAS_mkl.h_DIRS "BLAS_mkl.h_DIRS-NOTFOUND")
386	find_path(BLAS_mkl.h_DIRS
387	  NAMES mkl.h
388	  HINTS ${BLAS_DIR}
389	  PATH_SUFFIXES "include")
390      else()
391	set(BLAS_mkl.h_DIRS "BLAS_mkl.h_DIRS-NOTFOUND")
392	find_path(BLAS_mkl.h_DIRS
393	  NAMES mkl.h
394	  HINTS ${PATH_TO_LOOK_FOR})
395      endif()
396    endif()
397    mark_as_advanced(BLAS_mkl.h_DIRS)
398
399    # If found, add path to cmake variable
400    # ------------------------------------
401    if (BLAS_mkl.h_DIRS)
402      set(BLAS_INCLUDE_DIRS "${BLAS_mkl.h_DIRS}")
403    else ()
404      set(BLAS_INCLUDE_DIRS "BLAS_INCLUDE_DIRS-NOTFOUND")
405      if(NOT BLAS_FIND_QUIETLY)
406	message(STATUS "Looking for BLAS -- mkl.h not found")
407      endif()
408    endif()
409
410    if (WIN32)
411      string(REPLACE ":" ";" _libdir "$ENV{LIB}")
412    elseif (APPLE)
413      string(REPLACE ":" ";" _libdir "$ENV{DYLD_LIBRARY_PATH}")
414    else ()
415      string(REPLACE ":" ";" _libdir "$ENV{LD_LIBRARY_PATH}")
416    endif ()
417    list(APPEND _libdir "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
418    list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
419    # libiomp5
420    # --------
421    set(OMP_iomp5_LIBRARY "OMP_iomp5_LIBRARY-NOTFOUND")
422    find_library(OMP_iomp5_LIBRARY
423      NAMES iomp5
424      HINTS ${_libdir}
425      )
426    mark_as_advanced(OMP_iomp5_LIBRARY)
427    set(OMP_LIB "")
428    # libgomp
429    # -------
430    set(OMP_gomp_LIBRARY "OMP_gomp_LIBRARY-NOTFOUND")
431    find_library(OMP_gomp_LIBRARY
432      NAMES gomp
433      HINTS ${_libdir}
434      )
435    mark_as_advanced(OMP_gomp_LIBRARY)
436    # choose one or another depending on the compilo
437    if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
438      if (OMP_gomp_LIBRARY)
439	set(OMP_LIB "${OMP_gomp_LIBRARY}")
440      endif()
441    else(CMAKE_C_COMPILER_ID STREQUAL "Intel")
442      if (OMP_iomp5_LIBRARY)
443	set(OMP_LIB "${OMP_iomp5_LIBRARY}")
444      endif()
445    endif()
446
447    if (UNIX AND NOT WIN32)
448      # m
449      find_library(M_LIBRARY
450	NAMES m
451	HINTS ${_libdir})
452      mark_as_advanced(M_LIBRARY)
453      if(M_LIBRARY)
454	set(LM "-lm")
455      else()
456	set(LM "")
457      endif()
458      # Fortran
459      set(LGFORTRAN "")
460      if (CMAKE_C_COMPILER_ID MATCHES "GNU")
461	find_library(
462	  FORTRAN_gfortran_LIBRARY
463	  NAMES gfortran
464	  HINTS ${_libdir}
465	  )
466	mark_as_advanced(FORTRAN_gfortran_LIBRARY)
467	if (FORTRAN_gfortran_LIBRARY)
468	  set(LGFORTRAN "${FORTRAN_gfortran_LIBRARY}")
469	endif()
470      elseif (CMAKE_C_COMPILER_ID MATCHES "Intel")
471	find_library(
472	  FORTRAN_ifcore_LIBRARY
473	  NAMES ifcore
474	  HINTS ${_libdir}
475	  )
476	mark_as_advanced(FORTRAN_ifcore_LIBRARY)
477	if (FORTRAN_ifcore_LIBRARY)
478	  set(LGFORTRAN "{FORTRAN_ifcore_LIBRARY}")
479	endif()
480      endif()
481      set(BLAS_COMPILER_FLAGS "")
482      if (NOT BLA_VENDOR STREQUAL "Intel10_64lp_seq")
483	if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
484	  list(APPEND BLAS_COMPILER_FLAGS "-openmp")
485	endif()
486	if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
487	  list(APPEND BLAS_COMPILER_FLAGS "-fopenmp")
488	endif()
489      endif()
490      if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
491	if (BLA_VENDOR STREQUAL "Intel10_32")
492	  list(APPEND BLAS_COMPILER_FLAGS "-m32")
493	else()
494	  list(APPEND BLAS_COMPILER_FLAGS "-m64")
495	endif()
496	if (NOT BLA_VENDOR STREQUAL "Intel10_64lp_seq")
497	  list(APPEND OMP_LIB "-ldl")
498	endif()
499	if (ENV_MKLROOT)
500	  list(APPEND BLAS_COMPILER_FLAGS "-I${ENV_MKLROOT}/include")
501	endif()
502      endif()
503
504      set(additional_flags "")
505      if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
506	set(additional_flags "-Wl,--no-as-needed")
507      endif()
508    endif ()
509
510    if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
511      if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
512	find_package(Threads)
513      else()
514	find_package(Threads REQUIRED)
515      endif()
516
517      set(BLAS_SEARCH_LIBS "")
518
519      if(BLA_F95)
520
521	set(BLAS_mkl_SEARCH_SYMBOL SGEMM)
522	set(_LIBRARIES BLAS95_LIBRARIES)
523	if (WIN32)
524	  if (BLA_STATIC)
525	    set(BLAS_mkl_DLL_SUFFIX "")
526	  else()
527	    set(BLAS_mkl_DLL_SUFFIX "_dll")
528	  endif()
529
530	  # Find the main file (32-bit or 64-bit)
531	  set(BLAS_SEARCH_LIBS_WIN_MAIN "")
532	  if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
533	    list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
534	      "mkl_blas95${BLAS_mkl_DLL_SUFFIX} mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
535	  endif()
536	  if (BLA_VENDOR STREQUAL "Intel10_64lp*" OR BLA_VENDOR STREQUAL "All")
537	    list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
538	      "mkl_blas95_lp64${BLAS_mkl_DLL_SUFFIX} mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}")
539	  endif ()
540
541	  # Add threading/sequential libs
542	  set(BLAS_SEARCH_LIBS_WIN_THREAD "")
543	  if (BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
544	    list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
545	      "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
546	  endif()
547	  if (NOT BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
548	    # old version
549	    list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
550	      "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
551	    # mkl >= 10.3
552	    list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
553	      "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
554	  endif()
555
556	  # Cartesian product of the above
557	  foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
558	    foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
559	      list(APPEND BLAS_SEARCH_LIBS
560		"${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
561	    endforeach()
562	  endforeach()
563	else (WIN32)
564	  if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
565	    list(APPEND BLAS_SEARCH_LIBS
566	      "mkl_blas95 mkl_intel mkl_intel_thread mkl_core guide")
567	  endif ()
568	  if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
569	    # old version
570	    list(APPEND BLAS_SEARCH_LIBS
571	      "mkl_blas95 mkl_intel_lp64 mkl_intel_thread mkl_core guide")
572	    # mkl >= 10.3
573	    if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
574	      list(APPEND BLAS_SEARCH_LIBS
575		"mkl_blas95_lp64 mkl_intel_lp64 mkl_intel_thread mkl_core")
576	    endif()
577	    if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
578	      list(APPEND BLAS_SEARCH_LIBS
579		"mkl_blas95_lp64 mkl_intel_lp64 mkl_gnu_thread mkl_core")
580	    endif()
581	  endif ()
582	  if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
583	    list(APPEND BLAS_SEARCH_LIBS
584	      "mkl_intel_lp64 mkl_sequential mkl_core")
585	    if (BLA_VENDOR STREQUAL "Intel10_64lp_seq")
586	      set(OMP_LIB "")
587	    endif()
588	  endif ()
589	endif (WIN32)
590
591      else (BLA_F95)
592
593	set(BLAS_mkl_SEARCH_SYMBOL sgemm)
594	set(_LIBRARIES BLAS_LIBRARIES)
595	if (WIN32)
596	  if (BLA_STATIC)
597	    set(BLAS_mkl_DLL_SUFFIX "")
598	  else()
599	    set(BLAS_mkl_DLL_SUFFIX "_dll")
600	  endif()
601
602	  # Find the main file (32-bit or 64-bit)
603	  set(BLAS_SEARCH_LIBS_WIN_MAIN "")
604	  if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
605	    list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
606	      "mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
607	  endif()
608	  if (BLA_VENDOR STREQUAL "Intel10_64lp*" OR BLA_VENDOR STREQUAL "All")
609	    list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
610	      "mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}")
611	  endif ()
612
613	  # Add threading/sequential libs
614	  set(BLAS_SEARCH_LIBS_WIN_THREAD "")
615	  if (NOT BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
616	    # old version
617	    list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
618	      "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
619	    # mkl >= 10.3
620	    list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
621	      "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
622	  endif()
623	  if (BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
624	    list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
625	      "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
626	  endif()
627
628	  # Cartesian product of the above
629	  foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
630	    foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
631	      list(APPEND BLAS_SEARCH_LIBS
632		"${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
633	    endforeach()
634	  endforeach()
635	else (WIN32)
636	  if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
637	    list(APPEND BLAS_SEARCH_LIBS
638	      "mkl_intel mkl_intel_thread mkl_core guide")
639	  endif ()
640	  if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
641	    # old version
642	    list(APPEND BLAS_SEARCH_LIBS
643	      "mkl_intel_lp64 mkl_intel_thread mkl_core guide")
644	    # mkl >= 10.3
645	    if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
646	      list(APPEND BLAS_SEARCH_LIBS
647		"mkl_intel_lp64 mkl_intel_thread mkl_core")
648	    endif()
649	    if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
650	      list(APPEND BLAS_SEARCH_LIBS
651		"mkl_intel_lp64 mkl_gnu_thread mkl_core")
652	    endif()
653	  endif ()
654	  if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
655	    list(APPEND BLAS_SEARCH_LIBS
656	      "mkl_intel_lp64 mkl_sequential mkl_core")
657	    if (BLA_VENDOR STREQUAL "Intel10_64lp_seq")
658	      set(OMP_LIB "")
659	    endif()
660	  endif ()
661	  #older vesions of intel mkl libs
662	  if (BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All")
663	    list(APPEND BLAS_SEARCH_LIBS
664	      "mkl")
665	    list(APPEND BLAS_SEARCH_LIBS
666	      "mkl_ia32")
667	    list(APPEND BLAS_SEARCH_LIBS
668	      "mkl_em64t")
669	  endif ()
670	endif (WIN32)
671
672      endif (BLA_F95)
673
674      foreach (IT ${BLAS_SEARCH_LIBS})
675	string(REPLACE " " ";" SEARCH_LIBS ${IT})
676	if (${_LIBRARIES})
677	else ()
678	  check_fortran_libraries(
679	    ${_LIBRARIES}
680	    BLAS
681	    ${BLAS_mkl_SEARCH_SYMBOL}
682	    "${additional_flags}"
683	    "${SEARCH_LIBS}"
684	    "${OMP_LIB};${CMAKE_THREAD_LIBS_INIT};${LM}"
685	    )
686	  if(_LIBRARIES)
687	    set(BLAS_LINKER_FLAGS "${additional_flags}")
688	  endif()
689	endif()
690      endforeach ()
691      if(NOT BLAS_FIND_QUIETLY)
692        if(${_LIBRARIES})
693          message(STATUS "Looking for MKL BLAS: found")
694        else()
695          message(STATUS "Looking for MKL BLAS: not found")
696        endif()
697      endif()
698      if (${_LIBRARIES} AND NOT BLAS_VENDOR_FOUND)
699          set (BLAS_VENDOR_FOUND "Intel MKL")
700      endif()
701    endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
702  endif(NOT BLAS_LIBRARIES OR BLA_VENDOR MATCHES "Intel*")
703endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
704
705
706if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
707
708  if(NOT BLAS_LIBRARIES)
709    # gotoblas (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
710    check_fortran_libraries(
711      BLAS_LIBRARIES
712      BLAS
713      sgemm
714      ""
715      "goto2"
716      ""
717      )
718    if(NOT BLAS_FIND_QUIETLY)
719      if(BLAS_LIBRARIES)
720	message(STATUS "Looking for Goto BLAS: found")
721      else()
722	message(STATUS "Looking for Goto BLAS: not found")
723      endif()
724    endif()
725  endif()
726  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
727      set (BLAS_VENDOR_FOUND "Goto")
728  endif()
729
730endif (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
731
732
733# OpenBlas
734if (BLA_VENDOR STREQUAL "Open" OR BLA_VENDOR STREQUAL "All")
735
736  if(NOT BLAS_LIBRARIES)
737    # openblas (http://www.openblas.net/)
738    check_fortran_libraries(
739      BLAS_LIBRARIES
740      BLAS
741      sgemm
742      ""
743      "openblas"
744      ""
745      )
746    if(NOT BLAS_FIND_QUIETLY)
747      if(BLAS_LIBRARIES)
748	message(STATUS "Looking for Open BLAS: found")
749      else()
750	message(STATUS "Looking for Open BLAS: not found")
751      endif()
752    endif()
753  endif()
754  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
755      set (BLAS_VENDOR_FOUND "Openblas")
756  endif()
757
758endif (BLA_VENDOR STREQUAL "Open" OR BLA_VENDOR STREQUAL "All")
759
760
761# EigenBlas
762if (BLA_VENDOR STREQUAL "Eigen" OR BLA_VENDOR STREQUAL "All")
763
764  if(NOT BLAS_LIBRARIES)
765    # eigenblas (http://eigen.tuxfamily.org/index.php?title=Main_Page)
766    check_fortran_libraries(
767      BLAS_LIBRARIES
768      BLAS
769      sgemm
770      ""
771      "eigen_blas"
772      ""
773      )
774    if(NOT BLAS_FIND_QUIETLY)
775      if(BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
776	message(STATUS "Looking for Eigen BLAS: found")
777      else()
778	message(STATUS "Looking for Eigen BLAS: not found")
779      endif()
780    endif()
781  endif()
782
783  if(NOT BLAS_LIBRARIES)
784    # eigenblas (http://eigen.tuxfamily.org/index.php?title=Main_Page)
785    check_fortran_libraries(
786      BLAS_LIBRARIES
787      BLAS
788      sgemm
789      ""
790      "eigen_blas_static"
791      ""
792      )
793    if(NOT BLAS_FIND_QUIETLY)
794      if(BLAS_LIBRARIES)
795	message(STATUS "Looking for Eigen BLAS: found")
796      else()
797	message(STATUS "Looking for Eigen BLAS: not found")
798      endif()
799    endif()
800  endif()
801  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
802      set (BLAS_VENDOR_FOUND "Eigen")
803  endif()
804
805endif (BLA_VENDOR STREQUAL "Eigen" OR BLA_VENDOR STREQUAL "All")
806
807
808if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
809
810  if(NOT BLAS_LIBRARIES)
811    # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
812    check_fortran_libraries(
813      BLAS_LIBRARIES
814      BLAS
815      dgemm
816      ""
817      "f77blas;atlas"
818      ""
819      )
820    if(NOT BLAS_FIND_QUIETLY)
821      if(BLAS_LIBRARIES)
822	message(STATUS "Looking for Atlas BLAS: found")
823      else()
824	message(STATUS "Looking for Atlas BLAS: not found")
825      endif()
826    endif()
827  endif()
828
829  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
830      set (BLAS_VENDOR_FOUND "Atlas")
831  endif()
832
833endif (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
834
835
836# BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
837if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
838
839  if(NOT BLAS_LIBRARIES)
840    check_fortran_libraries(
841      BLAS_LIBRARIES
842      BLAS
843      sgemm
844      ""
845      "sgemm;dgemm;blas"
846      ""
847      )
848    if(NOT BLAS_FIND_QUIETLY)
849      if(BLAS_LIBRARIES)
850	message(STATUS "Looking for PhiPACK BLAS: found")
851      else()
852	message(STATUS "Looking for PhiPACK BLAS: not found")
853      endif()
854    endif()
855  endif()
856
857  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
858      set (BLAS_VENDOR_FOUND "PhiPACK")
859  endif()
860
861endif (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
862
863
864# BLAS in Alpha CXML library?
865if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
866
867  if(NOT BLAS_LIBRARIES)
868    check_fortran_libraries(
869      BLAS_LIBRARIES
870      BLAS
871      sgemm
872      ""
873      "cxml"
874      ""
875      )
876    if(NOT BLAS_FIND_QUIETLY)
877      if(BLAS_LIBRARIES)
878	message(STATUS "Looking for CXML BLAS: found")
879      else()
880	message(STATUS "Looking for CXML BLAS: not found")
881      endif()
882    endif()
883  endif()
884
885  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
886      set (BLAS_VENDOR_FOUND "CXML")
887  endif()
888
889endif (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
890
891
892# BLAS in Alpha DXML library? (now called CXML, see above)
893if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
894
895  if(NOT BLAS_LIBRARIES)
896    check_fortran_libraries(
897      BLAS_LIBRARIES
898      BLAS
899      sgemm
900      ""
901      "dxml"
902      ""
903      )
904    if(NOT BLAS_FIND_QUIETLY)
905      if(BLAS_LIBRARIES)
906	message(STATUS "Looking for DXML BLAS: found")
907      else()
908	message(STATUS "Looking for DXML BLAS: not found")
909      endif()
910    endif()
911  endif()
912
913  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
914      set (BLAS_VENDOR_FOUND "DXML")
915  endif()
916
917endif (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
918
919
920# BLAS in Sun Performance library?
921if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
922
923  if(NOT BLAS_LIBRARIES)
924    check_fortran_libraries(
925      BLAS_LIBRARIES
926      BLAS
927      sgemm
928      "-xlic_lib=sunperf"
929      "sunperf;sunmath"
930      ""
931      )
932    if(BLAS_LIBRARIES)
933      set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
934    endif()
935    if(NOT BLAS_FIND_QUIETLY)
936      if(BLAS_LIBRARIES)
937	message(STATUS "Looking for SunPerf BLAS: found")
938      else()
939	message(STATUS "Looking for SunPerf BLAS: not found")
940      endif()
941    endif()
942  endif()
943
944  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
945      set (BLAS_VENDOR_FOUND "SunPerf")
946  endif()
947
948endif ()
949
950
951# BLAS in SCSL library?  (SGI/Cray Scientific Library)
952if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
953
954  if(NOT BLAS_LIBRARIES)
955    check_fortran_libraries(
956      BLAS_LIBRARIES
957      BLAS
958      sgemm
959      ""
960      "scsl"
961      ""
962      )
963    if(NOT BLAS_FIND_QUIETLY)
964      if(BLAS_LIBRARIES)
965	message(STATUS "Looking for SCSL BLAS: found")
966      else()
967	message(STATUS "Looking for SCSL BLAS: not found")
968      endif()
969    endif()
970  endif()
971
972  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
973      set (BLAS_VENDOR_FOUND "SunPerf")
974  endif()
975
976endif ()
977
978
979# BLAS in SGIMATH library?
980if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
981
982  if(NOT BLAS_LIBRARIES)
983    check_fortran_libraries(
984      BLAS_LIBRARIES
985      BLAS
986      sgemm
987      ""
988      "complib.sgimath"
989      ""
990      )
991    if(NOT BLAS_FIND_QUIETLY)
992      if(BLAS_LIBRARIES)
993	message(STATUS "Looking for SGIMATH BLAS: found")
994      else()
995	message(STATUS "Looking for SGIMATH BLAS: not found")
996      endif()
997    endif()
998  endif()
999
1000  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
1001      set (BLAS_VENDOR_FOUND "SGIMATH")
1002  endif()
1003
1004endif ()
1005
1006
1007# BLAS in IBM ESSL library (requires generic BLAS lib, too)
1008if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
1009
1010  if(NOT BLAS_LIBRARIES)
1011    check_fortran_libraries(
1012      BLAS_LIBRARIES
1013      BLAS
1014      sgemm
1015      ""
1016      "essl;xlfmath;xlf90_r;blas"
1017      ""
1018      )
1019    if(NOT BLAS_FIND_QUIETLY)
1020      if(BLAS_LIBRARIES)
1021	message(STATUS "Looking for IBM ESSL BLAS: found")
1022      else()
1023	message(STATUS "Looking for IBM ESSL BLAS: not found")
1024      endif()
1025    endif()
1026  endif()
1027
1028  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
1029      set (BLAS_VENDOR_FOUND "IBM ESSL")
1030  endif()
1031
1032endif ()
1033
1034# BLAS in IBM ESSL_MT library (requires generic BLAS lib, too)
1035if (BLA_VENDOR STREQUAL "IBMESSLMT" OR BLA_VENDOR STREQUAL "All")
1036
1037  if(NOT BLAS_LIBRARIES)
1038    check_fortran_libraries(
1039      BLAS_LIBRARIES
1040      BLAS
1041      sgemm
1042      ""
1043      "esslsmp;xlsmp;xlfmath;xlf90_r;blas"
1044      ""
1045      )
1046    if(NOT BLAS_FIND_QUIETLY)
1047      if(BLAS_LIBRARIES)
1048	message(STATUS "Looking for IBM ESSL MT BLAS: found")
1049      else()
1050	message(STATUS "Looking for IBM ESSL MT BLAS: not found")
1051      endif()
1052    endif()
1053  endif()
1054
1055  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
1056      set (BLAS_VENDOR_FOUND "IBM ESSL MT")
1057  endif()
1058
1059endif ()
1060
1061
1062#BLAS in acml library?
1063if (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All")
1064
1065  if( ((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
1066      ((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR
1067      ((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS)))
1068
1069    # try to find acml in "standard" paths
1070    if( WIN32 )
1071      file( GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt" )
1072    else()
1073      file( GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt" )
1074    endif()
1075    if( WIN32 )
1076      file( GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples" )
1077    else()
1078      file( GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples" )
1079    endif()
1080    list(GET _ACML_ROOT 0 _ACML_ROOT)
1081    list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)
1082
1083    if( _ACML_ROOT )
1084
1085      get_filename_component( _ACML_ROOT ${_ACML_ROOT} PATH )
1086      if( SIZEOF_INTEGER EQUAL 8 )
1087	set( _ACML_PATH_SUFFIX "_int64" )
1088      else()
1089	set( _ACML_PATH_SUFFIX "" )
1090      endif()
1091      if( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
1092	set( _ACML_COMPILER32 "ifort32" )
1093	set( _ACML_COMPILER64 "ifort64" )
1094      elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
1095	set( _ACML_COMPILER32 "sun32" )
1096	set( _ACML_COMPILER64 "sun64" )
1097      elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" )
1098	set( _ACML_COMPILER32 "pgi32" )
1099	if( WIN32 )
1100	  set( _ACML_COMPILER64 "win64" )
1101	else()
1102	  set( _ACML_COMPILER64 "pgi64" )
1103	endif()
1104      elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Open64" )
1105	# 32 bit builds not supported on Open64 but for code simplicity
1106	# We'll just use the same directory twice
1107	set( _ACML_COMPILER32 "open64_64" )
1108	set( _ACML_COMPILER64 "open64_64" )
1109      elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" )
1110	set( _ACML_COMPILER32 "nag32" )
1111	set( _ACML_COMPILER64 "nag64" )
1112      else()
1113	set( _ACML_COMPILER32 "gfortran32" )
1114	set( _ACML_COMPILER64 "gfortran64" )
1115      endif()
1116
1117      if( BLA_VENDOR STREQUAL "ACML_MP" )
1118	set(_ACML_MP_LIB_DIRS
1119	  "${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib"
1120	  "${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib" )
1121      else()
1122	set(_ACML_LIB_DIRS
1123	  "${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib"
1124	  "${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib" )
1125      endif()
1126
1127    endif(_ACML_ROOT)
1128
1129  elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)
1130
1131    set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})
1132
1133  endif()
1134
1135  if( BLA_VENDOR STREQUAL "ACML_MP" )
1136    foreach( BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS})
1137      check_fortran_libraries (
1138	BLAS_LIBRARIES
1139	BLAS
1140	sgemm
1141	"" "acml_mp;acml_mv" "" ${BLAS_ACML_MP_LIB_DIRS}
1142	)
1143      if( BLAS_LIBRARIES )
1144	break()
1145      endif()
1146    endforeach()
1147  elseif( BLA_VENDOR STREQUAL "ACML_GPU" )
1148    foreach( BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS})
1149      check_fortran_libraries (
1150	BLAS_LIBRARIES
1151	BLAS
1152	sgemm
1153	"" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS}
1154	)
1155      if( BLAS_LIBRARIES )
1156	break()
1157      endif()
1158    endforeach()
1159  else()
1160    foreach( BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS} )
1161      check_fortran_libraries (
1162	BLAS_LIBRARIES
1163	BLAS
1164	sgemm
1165	"" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS}
1166	)
1167      if( BLAS_LIBRARIES )
1168	break()
1169      endif()
1170    endforeach()
1171  endif()
1172
1173  # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
1174  if(NOT BLAS_LIBRARIES)
1175    check_fortran_libraries(
1176      BLAS_LIBRARIES
1177      BLAS
1178      sgemm
1179      ""
1180      "acml;acml_mv"
1181      ""
1182      )
1183    if(NOT BLAS_FIND_QUIETLY)
1184      if(BLAS_LIBRARIES)
1185	message(STATUS "Looking for ACML BLAS: found")
1186      else()
1187	message(STATUS "Looking for ACML BLAS: not found")
1188      endif()
1189    endif()
1190  endif()
1191
1192  if(NOT BLAS_LIBRARIES)
1193    check_fortran_libraries(
1194      BLAS_LIBRARIES
1195      BLAS
1196      sgemm
1197      ""
1198      "acml_mp;acml_mv"
1199      ""
1200      )
1201    if(NOT BLAS_FIND_QUIETLY)
1202      if(BLAS_LIBRARIES)
1203	message(STATUS "Looking for ACML BLAS: found")
1204      else()
1205	message(STATUS "Looking for ACML BLAS: not found")
1206      endif()
1207    endif()
1208  endif()
1209
1210  if(NOT BLAS_LIBRARIES)
1211    check_fortran_libraries(
1212      BLAS_LIBRARIES
1213      BLAS
1214      sgemm
1215      ""
1216      "acml;acml_mv;CALBLAS"
1217      ""
1218      )
1219    if(NOT BLAS_FIND_QUIETLY)
1220      if(BLAS_LIBRARIES)
1221	message(STATUS "Looking for ACML BLAS: found")
1222      else()
1223	message(STATUS "Looking for ACML BLAS: not found")
1224      endif()
1225    endif()
1226  endif()
1227
1228  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
1229      set (BLAS_VENDOR_FOUND "ACML")
1230  endif()
1231
1232endif (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All") # ACML
1233
1234
1235# Apple BLAS library?
1236if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
1237
1238  if(NOT BLAS_LIBRARIES)
1239    check_fortran_libraries(
1240      BLAS_LIBRARIES
1241      BLAS
1242      dgemm
1243      ""
1244      "Accelerate"
1245      ""
1246      )
1247    if(NOT BLAS_FIND_QUIETLY)
1248      if(BLAS_LIBRARIES)
1249	message(STATUS "Looking for Apple BLAS: found")
1250      else()
1251	message(STATUS "Looking for Apple BLAS: not found")
1252      endif()
1253    endif()
1254  endif()
1255
1256  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
1257      set (BLAS_VENDOR_FOUND "Apple Accelerate")
1258  endif()
1259
1260endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
1261
1262
1263if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
1264
1265  if ( NOT BLAS_LIBRARIES )
1266    check_fortran_libraries(
1267      BLAS_LIBRARIES
1268      BLAS
1269      dgemm
1270      ""
1271      "vecLib"
1272      ""
1273      )
1274    if(NOT BLAS_FIND_QUIETLY)
1275      if(BLAS_LIBRARIES)
1276	message(STATUS "Looking for NAS BLAS: found")
1277      else()
1278	message(STATUS "Looking for NAS BLAS: not found")
1279      endif()
1280    endif()
1281  endif ()
1282
1283  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
1284      set (BLAS_VENDOR_FOUND "NAS")
1285  endif()
1286
1287endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
1288
1289
1290# Generic BLAS library?
1291if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
1292
1293  set(BLAS_SEARCH_LIBS "blas;blas_LINUX;blas_MAC;blas_WINDOWS;refblas")
1294  foreach (SEARCH_LIB ${BLAS_SEARCH_LIBS})
1295    if (BLAS_LIBRARIES)
1296    else ()
1297      check_fortran_libraries(
1298	BLAS_LIBRARIES
1299	BLAS
1300	sgemm
1301	""
1302	"${SEARCH_LIB}"
1303	"${LGFORTRAN}"
1304	)
1305      if(NOT BLAS_FIND_QUIETLY)
1306	if(BLAS_LIBRARIES)
1307	  message(STATUS "Looking for Generic BLAS: found")
1308	else()
1309	  message(STATUS "Looking for Generic BLAS: not found")
1310	endif()
1311      endif()
1312    endif()
1313  endforeach ()
1314
1315  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
1316      set (BLAS_VENDOR_FOUND "Netlib or other Generic libblas")
1317  endif()
1318
1319endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
1320
1321
1322if(BLA_F95)
1323
1324  if(BLAS95_LIBRARIES)
1325    set(BLAS95_FOUND TRUE)
1326  else()
1327    set(BLAS95_FOUND FALSE)
1328  endif()
1329
1330  if(NOT BLAS_FIND_QUIETLY)
1331    if(BLAS95_FOUND)
1332      message(STATUS "A library with BLAS95 API found.")
1333      message(STATUS "BLAS_LIBRARIES ${BLAS_LIBRARIES}")
1334    else(BLAS95_FOUND)
1335      message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but blas 95 libraries could not be found or check of symbols failed."
1336	"\nPlease indicate where to find blas libraries. You have three options:\n"
1337	"- Option 1: Provide the installation directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
1338	"- Option 2: Provide the directory where to find BLAS libraries with cmake option: -DBLAS_LIBDIR=your/path/to/blas/libs\n"
1339	"- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
1340	"\nTo follow libraries detection more precisely you can activate a verbose mode with -DBLAS_VERBOSE=ON at cmake configure."
1341	"\nYou could also specify a BLAS vendor to look for by setting -DBLA_VENDOR=blas_vendor_name."
1342	"\nList of possible BLAS vendor: Goto, ATLAS PhiPACK, CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, Intel10_32 (intel mkl v10 32 bit),"
1343	"Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model), Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),"
1344	"Intel( older versions of mkl 32 and 64 bit), ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
1345      if(BLAS_FIND_REQUIRED)
1346	message(FATAL_ERROR
1347	  "A required library with BLAS95 API not found. Please specify library location.")
1348      else()
1349	message(STATUS
1350	  "A library with BLAS95 API not found. Please specify library location.")
1351      endif()
1352    endif(BLAS95_FOUND)
1353  endif(NOT BLAS_FIND_QUIETLY)
1354
1355  set(BLAS_FOUND TRUE)
1356  set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
1357
1358else(BLA_F95)
1359
1360  if(BLAS_LIBRARIES)
1361    set(BLAS_FOUND TRUE)
1362  else()
1363    set(BLAS_FOUND FALSE)
1364  endif()
1365
1366  if(NOT BLAS_FIND_QUIETLY)
1367    if(BLAS_FOUND)
1368      message(STATUS "A library with BLAS API found.")
1369      message(STATUS "BLAS_LIBRARIES ${BLAS_LIBRARIES}")
1370    else(BLAS_FOUND)
1371      message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but blas libraries could not be found or check of symbols failed."
1372	"\nPlease indicate where to find blas libraries. You have three options:\n"
1373	"- Option 1: Provide the installation directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
1374	"- Option 2: Provide the directory where to find BLAS libraries with cmake option: -DBLAS_LIBDIR=your/path/to/blas/libs\n"
1375	"- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
1376	"\nTo follow libraries detection more precisely you can activate a verbose mode with -DBLAS_VERBOSE=ON at cmake configure."
1377	"\nYou could also specify a BLAS vendor to look for by setting -DBLA_VENDOR=blas_vendor_name."
1378	"\nList of possible BLAS vendor: Goto, ATLAS PhiPACK, CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, Intel10_32 (intel mkl v10 32 bit),"
1379	"Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model), Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),"
1380	"Intel( older versions of mkl 32 and 64 bit), ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
1381      if(BLAS_FIND_REQUIRED)
1382	message(FATAL_ERROR
1383	  "A required library with BLAS API not found. Please specify library location.")
1384      else()
1385	message(STATUS
1386	  "A library with BLAS API not found. Please specify library location.")
1387      endif()
1388    endif(BLAS_FOUND)
1389  endif(NOT BLAS_FIND_QUIETLY)
1390
1391endif(BLA_F95)
1392
1393set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
1394
1395if (BLAS_FOUND)
1396  list(GET BLAS_LIBRARIES 0 first_lib)
1397  get_filename_component(first_lib_path "${first_lib}" PATH)
1398  if (${first_lib_path} MATCHES "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)")
1399    string(REGEX REPLACE "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)" "" not_cached_dir "${first_lib_path}")
1400    set(BLAS_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of BLAS library" FORCE)
1401  else()
1402    set(BLAS_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of BLAS library" FORCE)
1403  endif()
1404endif()
1405mark_as_advanced(BLAS_DIR)
1406mark_as_advanced(BLAS_DIR_FOUND)
1407