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