FindBLAS.cmake 51 KB
Newer Older
PRUVOST Florent's avatar
PRUVOST Florent committed
1
2
3
4
5
###
#
# @copyright (c) 2009-2014 The University of Tennessee and The University
#                          of Tennessee Research Foundation.
#                          All rights reserved.
6
# @copyright (c) 2012-2018 Inria. All rights reserved.
PRUVOST Florent's avatar
PRUVOST Florent committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
#
###
#
# - Find BLAS library
# This module finds an installed fortran library that implements the BLAS
# linear-algebra interface (see http://www.netlib.org/blas/).
# The list of libraries searched for is taken
# from the autoconf macro file, acx_blas.m4 (distributed at
# http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
#
# This module sets the following variables:
#  BLAS_FOUND - set to true if a library implementing the BLAS interface
#    is found
21
#  BLAS_LDFLAGS_OTHER - list of required linker flags (excluding -l
PRUVOST Florent's avatar
PRUVOST Florent committed
22
#    and -L).
23
24
25
#  BLAS_CFLAGS_OTHER - list of required compiler flags (excluding -I).
#  BLAS_INCLUDE_DIRS - include directories
#  BLAS_LIBRARIES - list of libraries (using full path name) to
PRUVOST Florent's avatar
PRUVOST Florent committed
26
#    link against to use BLAS
27
#  BLAS95_LIBRARIES - list of libraries (using full path name)
PRUVOST Florent's avatar
PRUVOST Florent committed
28
29
30
31
32
33
#    to link against to use BLAS95 interface
#  BLAS95_FOUND - set to true if a library implementing the BLAS f95 interface
#    is found
#  BLA_STATIC  if set on this determines what kind of linkage we do (static)
#  BLA_VENDOR  if set checks only the specified vendor, if not set checks
#     all the possibilities
34
#  BLAS_VENDOR_FOUND stores the BLAS vendor found
PRUVOST Florent's avatar
PRUVOST Florent committed
35
#  BLA_F95     if set on tries to find the f95 interfaces for BLAS/LAPACK
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#
#  BLAS_FOUND_WITH_PKGCONFIG - True if found with pkg-config
#  if found with pkg-config the following variables are set
#  <PREFIX>  = BLAS
#  <XPREFIX> = <PREFIX>        for common case
#  <XPREFIX> = <PREFIX>_STATIC for static linking
#  <XPREFIX>_FOUND          ... set to 1 if module(s) exist
#  <XPREFIX>_LIBRARIES      ... only the libraries (w/o the '-l')
#  <XPREFIX>_LIBRARY_DIRS   ... the paths of the libraries (w/o the '-L')
#  <XPREFIX>_LDFLAGS        ... all required linker flags
#  <XPREFIX>_LDFLAGS_OTHER  ... all other linker flags
#  <XPREFIX>_INCLUDE_DIRS   ... the '-I' preprocessor flags (w/o the '-I')
#  <XPREFIX>_CFLAGS         ... all required cflags
#  <XPREFIX>_CFLAGS_OTHER   ... the other compiler flags
#
PRUVOST Florent's avatar
PRUVOST Florent committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# The user can give specific paths where to find the libraries adding cmake
# options at configure (ex: cmake path/to/project -DBLAS_DIR=path/to/blas):
#  BLAS_DIR            - Where to find the base directory of blas
#  BLAS_INCDIR         - Where to find the header files
#  BLAS_LIBDIR         - Where to find the library files
# The module can also look for the following environment variables if paths
# are not given as cmake variable: BLAS_DIR, BLAS_INCDIR, BLAS_LIBDIR
# For MKL case and if no paths are given as hints, we will try to use the MKLROOT
# environment variable
#  BLAS_VERBOSE Print some additional information during BLAS libraries detection
##########
### List of vendors (BLA_VENDOR) valid in this module
########## List of vendors (BLA_VENDOR) valid in this module
##  Open (for OpenBlas), Eigen (for EigenBlas), Goto, ATLAS PhiPACK,
##  CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, IBMESSLMT
##  Intel10_32 (intel mkl v10 32 bit), Intel10_64lp (intel mkl v10 64 bit,lp thread model, lp64 model),
##  Intel10_64lp_seq (intel mkl v10 64 bit,sequential code, lp64 model),
##  Intel( older versions of mkl 32 and 64 bit),
##  ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic
# C/CXX should be enabled to use Intel mkl
###
# We handle different modes to find the dependency
#
# - Detection if already installed on the system
#   - BLAS libraries can be detected from different ways
#     Here is the order of precedence:
#     1) we look in cmake variable BLAS_LIBDIR or BLAS_DIR (we guess the libdirs) if defined
#     2) we look in environment variable BLAS_LIBDIR or BLAS_DIR (we guess the libdirs) if defined
#     3) we look in common environnment variables depending on the system (INCLUDE, C_INCLUDE_PATH, CPATH - LIB, DYLD_LIBRARY_PATH, LD_LIBRARY_PATH)
#     4) we look in common system paths depending on the system, see for example paths contained in the following cmake variables:
#       - CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES, CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
#       - CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES, CMAKE_C_IMPLICIT_LINK_DIRECTORIES
#

#=============================================================================
# Copyright 2007-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
#  License text for the above reference.)

## Some macros to print status when search for headers and libs
# This macro informs why the _lib_to_find file has not been found
macro(Print_Find_Library_Blas_Status _libname _lib_to_find)

  # save _libname upper/lower case
  string(TOUPPER ${_libname} LIBNAME)
  string(TOLOWER ${_libname} libname)

  # print status
  #message(" ")
  if(${LIBNAME}_LIBDIR)
    message("${Yellow}${LIBNAME}_LIBDIR is defined but ${_lib_to_find}"
      "has not been found in ${ARGN}${ColourReset}")
  else()
    if(${LIBNAME}_DIR)
      message("${Yellow}${LIBNAME}_DIR is defined but ${_lib_to_find}"
114
        "has not been found in ${ARGN}${ColourReset}")
PRUVOST Florent's avatar
PRUVOST Florent committed
115
116
    else()
      message("${Yellow}${_lib_to_find} not found."
117
118
119
120
121
122
        "Nor ${LIBNAME}_DIR neither ${LIBNAME}_LIBDIR"
        "are defined so that we look for ${_lib_to_find} in"
        "system paths (Linux: LD_LIBRARY_PATH, Windows: LIB,"
        "Mac: DYLD_LIBRARY_PATH,"
        "CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES,"
        "CMAKE_C_IMPLICIT_LINK_DIRECTORIES)${ColourReset}")
PRUVOST Florent's avatar
PRUVOST Florent committed
123
      if(_lib_env)
124
125
        message("${Yellow}${_lib_to_find} has not been found in"
          "${_lib_env}${ColourReset}")
PRUVOST Florent's avatar
PRUVOST Florent committed
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
      endif()
    endif()
  endif()
  message("${BoldYellow}Please indicate where to find ${_lib_to_find}. You have three options:\n"
    "- Option 1: Provide the Installation directory of BLAS library with cmake option: -D${LIBNAME}_DIR=your/path/to/${libname}/\n"
    "- Option 2: Provide the directory where to find the library with cmake option: -D${LIBNAME}_LIBDIR=your/path/to/${libname}/lib/\n"
    "- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
    "- Option 4: If your library provides a PkgConfig file, make sure pkg-config finds your library${ColourReset}")

endmacro()

# This macro informs why the _lib_to_find file has not been found
macro(Print_Find_Library_Blas_CheckFunc_Status _name)

  # save _libname upper/lower case
  string(TOUPPER ${_name} FUNCNAME)
  string(TOLOWER ${_name} funcname)

  # print status
  #message(" ")
  message("${Red}Libs have been found but check of symbol ${_name} failed "
    "with following libraries ${ARGN}${ColourReset}")
  message("${BoldRed}Please open your error file CMakeFiles/CMakeError.log"
    "to figure out why it fails${ColourReset}")
  #message(" ")

endmacro()

if (NOT BLAS_FOUND)
  set(BLAS_DIR "" CACHE PATH "Installation directory of BLAS library")
  if (NOT BLAS_FIND_QUIETLY)
    message(STATUS "A cache variable, namely BLAS_DIR, has been set to specify the install directory of BLAS")
  endif()
endif()

option(BLAS_VERBOSE "Print some additional information during BLAS libraries detection" OFF)
mark_as_advanced(BLAS_VERBOSE)

include(CheckFunctionExists)
include(CheckFortranFunctionExists)

set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})

# Check the language being used
get_property( _LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES )
if( _LANGUAGES_ MATCHES Fortran )
  set( _CHECK_FORTRAN TRUE )
elseif( (_LANGUAGES_ MATCHES C) OR (_LANGUAGES_ MATCHES CXX) )
  set( _CHECK_FORTRAN FALSE )
else()
  if(BLAS_FIND_REQUIRED)
    message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.")
  else()
    message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)")
    return()
  endif()
endif()

macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _thread)
  # This macro checks for the existence of the combination of fortran libraries
  # given by _list.  If the combination is found, this macro checks (using the
  # Check_Fortran_Function_Exists macro) whether can link against that library
  # combination using the name of a routine given by _name using the linker
  # flags given by _flags.  If the combination of libraries is found and passes
  # the link test, LIBRARIES is set to the list of complete library paths that
  # have been found.  Otherwise, LIBRARIES is set to FALSE.

  # N.B. _prefix is the prefix applied to the names of all cached variables that
  # are generated internally and marked advanced by this macro.

  set(_libdir ${ARGN})

  set(_libraries_work TRUE)
  set(${LIBRARIES})
  set(_combined_name)
  set(ENV_MKLROOT "$ENV{MKLROOT}")
  set(ENV_BLAS_DIR "$ENV{BLAS_DIR}")
  set(ENV_BLAS_LIBDIR "$ENV{BLAS_LIBDIR}")
  if (NOT _libdir)
    if (BLAS_LIBDIR)
      list(APPEND _libdir "${BLAS_LIBDIR}")
    elseif (BLAS_DIR)
      list(APPEND _libdir "${BLAS_DIR}")
      list(APPEND _libdir "${BLAS_DIR}/lib")
      if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
211
212
        list(APPEND _libdir "${BLAS_DIR}/lib64")
        list(APPEND _libdir "${BLAS_DIR}/lib/intel64")
PRUVOST Florent's avatar
PRUVOST Florent committed
213
      else()
214
215
        list(APPEND _libdir "${BLAS_DIR}/lib32")
        list(APPEND _libdir "${BLAS_DIR}/lib/ia32")
PRUVOST Florent's avatar
PRUVOST Florent committed
216
217
218
219
220
221
222
      endif()
    elseif(ENV_BLAS_LIBDIR)
      list(APPEND _libdir "${ENV_BLAS_LIBDIR}")
    elseif(ENV_BLAS_DIR)
      list(APPEND _libdir "${ENV_BLAS_DIR}")
      list(APPEND _libdir "${ENV_BLAS_DIR}/lib")
      if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
223
224
        list(APPEND _libdir "${ENV_BLAS_DIR}/lib64")
        list(APPEND _libdir "${ENV_BLAS_DIR}/lib/intel64")
PRUVOST Florent's avatar
PRUVOST Florent committed
225
      else()
226
227
        list(APPEND _libdir "${ENV_BLAS_DIR}/lib32")
        list(APPEND _libdir "${ENV_BLAS_DIR}/lib/ia32")
PRUVOST Florent's avatar
PRUVOST Florent committed
228
229
230
      endif()
    else()
      if (ENV_MKLROOT)
231
232
233
234
235
236
237
238
        list(APPEND _libdir "${ENV_MKLROOT}/lib")
        if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
          list(APPEND _libdir "${ENV_MKLROOT}/lib64")
          list(APPEND _libdir "${ENV_MKLROOT}/lib/intel64")
        else()
          list(APPEND _libdir "${ENV_MKLROOT}/lib32")
          list(APPEND _libdir "${ENV_MKLROOT}/lib/ia32")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
239
240
      endif()
      if (WIN32)
241
        string(REPLACE ":" ";" _libdir2 "$ENV{LIB}")
PRUVOST Florent's avatar
PRUVOST Florent committed
242
      elseif (APPLE)
243
        string(REPLACE ":" ";" _libdir2 "$ENV{DYLD_LIBRARY_PATH}")
PRUVOST Florent's avatar
PRUVOST Florent committed
244
      else ()
245
        string(REPLACE ":" ";" _libdir2 "$ENV{LD_LIBRARY_PATH}")
PRUVOST Florent's avatar
PRUVOST Florent committed
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
      endif ()
      list(APPEND _libdir "${_libdir2}")
      list(APPEND _libdir "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
      list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
    endif()
  endif ()

  if (BLAS_VERBOSE)
    message("${Cyan}Try to find BLAS libraries: ${_list}")
  endif ()

  foreach(_library ${_list})
    set(_combined_name ${_combined_name}_${_library})

    if(_libraries_work)
      if (BLA_STATIC)
262
263
264
265
266
267
268
269
        if (WIN32)
          set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
        endif ()
        if (APPLE)
          set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
        else ()
          set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
        endif ()
PRUVOST Florent's avatar
PRUVOST Florent committed
270
      else ()
271
272
273
274
        if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
          # for ubuntu's libblas3gf and liblapack3gf packages
          set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
        endif ()
PRUVOST Florent's avatar
PRUVOST Florent committed
275
276
      endif ()
      find_library(${_prefix}_${_library}_LIBRARY
277
278
279
        NAMES ${_library}
        HINTS ${_libdir}
        )
PRUVOST Florent's avatar
PRUVOST Florent committed
280
281
282
283
      mark_as_advanced(${_prefix}_${_library}_LIBRARY)
      # Print status if not found
      # -------------------------
      if (NOT ${_prefix}_${_library}_LIBRARY AND NOT BLAS_FIND_QUIETLY AND BLAS_VERBOSE)
284
        Print_Find_Library_Blas_Status(blas ${_library} ${_libdir})
PRUVOST Florent's avatar
PRUVOST Florent committed
285
286
287
288
289
290
291
292
293
294
295
296
297
      endif ()
      set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
      set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
    endif(_libraries_work)
  endforeach(_library ${_list})

  if(_libraries_work)
    # Test this combination of libraries.
    if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND BLA_STATIC)
      list(INSERT ${LIBRARIES} 0 "-Wl,--start-group")
      list(APPEND ${LIBRARIES} "-Wl,--end-group")
    endif()
    set(CMAKE_REQUIRED_LIBRARIES "${_flags};${${LIBRARIES}};${_thread}")
298
299
    set(CMAKE_REQUIRED_INCLUDES "${BLAS_INCLUDE_DIRS}")
    set(CMAKE_REQUIRED_FLAGS "${BLAS_CFLAGS_OTHER}")
PRUVOST Florent's avatar
PRUVOST Florent committed
300
301
    if (BLAS_VERBOSE)
      message("${Cyan}BLAS libs found for BLA_VENDOR ${BLA_VENDOR}."
302
303
        "Try to compile symbol ${_name} with following libraries:"
        "${CMAKE_REQUIRED_LIBRARIES}")
PRUVOST Florent's avatar
PRUVOST Florent committed
304
305
306
307
308
309
    endif ()
    if(NOT BLAS_FOUND)
      unset(${_prefix}${_combined_name}_WORKS CACHE)
    endif()
    if (_CHECK_FORTRAN)
      if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
310
311
        string(REPLACE "mkl_intel_lp64" "mkl_gf_lp64" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
        string(REPLACE "mkl_intel_ilp64" "mkl_gf_ilp64" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
PRUVOST Florent's avatar
PRUVOST Florent committed
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
      endif()
      check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
    else()
      check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
    endif()
    mark_as_advanced(${_prefix}${_combined_name}_WORKS)
    set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
    # Print status if not found
    # -------------------------
    if (NOT _libraries_work AND NOT BLAS_FIND_QUIETLY AND BLAS_VERBOSE)
      Print_Find_Library_Blas_CheckFunc_Status(${_name} ${CMAKE_REQUIRED_LIBRARIES})
    endif ()
    set(CMAKE_REQUIRED_LIBRARIES)
  endif()

  if(_libraries_work)
    set(${LIBRARIES} ${${LIBRARIES}} ${_thread})
  else(_libraries_work)
    set(${LIBRARIES} FALSE)
  endif(_libraries_work)

endmacro(Check_Fortran_Libraries)


336
set(BLAS_LDFLAGS_OTHER)
PRUVOST Florent's avatar
PRUVOST Florent committed
337
338
339
340
341
342
343
344
345
346
set(BLAS_LIBRARIES)
set(BLAS95_LIBRARIES)
if ($ENV{BLA_VENDOR} MATCHES ".+")
  set(BLA_VENDOR $ENV{BLA_VENDOR})
else ()
  if(NOT BLA_VENDOR)
    set(BLA_VENDOR "All")
  endif()
endif ()

PRUVOST Florent's avatar
PRUVOST Florent committed
347
348
349
350
351
352
353
set(ENV_BLAS_DIR "$ENV{BLAS_DIR}")
set(ENV_BLAS_INCDIR "$ENV{BLAS_INCDIR}")
set(ENV_BLAS_LIBDIR "$ENV{BLAS_LIBDIR}")
set(BLAS_GIVEN_BY_USER "FALSE")
if ( BLAS_DIR OR ( BLAS_INCDIR AND BLAS_LIBDIR) OR ENV_BLAS_DIR OR (ENV_BLAS_INCDIR AND ENV_BLAS_LIBDIR) )
  set(BLAS_GIVEN_BY_USER "TRUE")
endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
354

PRUVOST Florent's avatar
PRUVOST Florent committed
355
356
357
358
# Optionally use pkg-config to detect include/library dirs (if pkg-config is available)
# -------------------------------------------------------------------------------------
include(FindPkgConfig)
find_package(PkgConfig QUIET)
359
if( PKG_CONFIG_EXECUTABLE AND NOT BLAS_GIVEN_BY_USER )
PRUVOST Florent's avatar
PRUVOST Florent committed
360

361
362
363
364
365
366
367
368
  if (BLA_STATIC)
    set(MKL_STR_BLA_STATIC "static")
  else()
    set(MKL_STR_BLA_STATIC "dynamic")
  endif()
  # try different blas
  if (BLA_VENDOR STREQUAL "Intel10_64lp")
    pkg_search_module(BLAS mkl-${MKL_STR_BLA_STATIC}-lp64-iomp)
369
370
371
    if (BLAS_FOUND)
      set (BLAS_VENDOR_FOUND "Intel MKL")
    endif()
372
373
  elseif(BLA_VENDOR STREQUAL "Intel10_64lp_seq")
    pkg_search_module(BLAS mkl-${MKL_STR_BLA_STATIC}-lp64-seq)
374
375
376
    if (BLAS_FOUND)
      set (BLAS_VENDOR_FOUND "Intel MKL")
    endif()
377
378
  elseif(BLA_VENDOR STREQUAL "Open")
    pkg_search_module(BLAS openblas)
379
380
381
    if (BLAS_FOUND)
      set (BLAS_VENDOR_FOUND "Openblas")
    endif()
382
383
  elseif(BLA_VENDOR STREQUAL "Generic")
    pkg_search_module(BLAS blas)
384
385
386
    if (BLAS_FOUND)
      set (BLAS_VENDOR_FOUND "Netlib or other Generic libblas")
    endif()
387
  else()
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
    if (NOT BLAS_FOUND)
      pkg_search_module(BLAS mkl-${MKL_STR_BLA_STATIC}-lp64-seq)
      if (BLAS_FOUND)
        set (BLAS_VENDOR_FOUND "Intel MKL")
      endif()
    endif()
    if (NOT BLAS_FOUND)
      pkg_search_module(BLAS openblas)
      if (BLAS_FOUND)
        set (BLAS_VENDOR_FOUND "Openblas")
      endif()
    endif()
    if (NOT BLAS_FOUND)
      pkg_search_module(BLAS blas)
      if (BLAS_FOUND)
        set (BLAS_VENDOR_FOUND "Netlib or other Generic libblas")
      endif()
    endif()
406
  endif()
407

PRUVOST Florent's avatar
PRUVOST Florent committed
408
409
410
  if (NOT BLAS_FIND_QUIETLY)
    if (BLAS_FOUND AND BLAS_LIBRARIES)
      message(STATUS "Looking for BLAS - found using PkgConfig")
PRUVOST Florent's avatar
PRUVOST Florent committed
411
    else()
PRUVOST Florent's avatar
PRUVOST Florent committed
412
413
414
      message(STATUS "${Magenta}Looking for BLAS - not found using PkgConfig."
        "\n   Perhaps you should add the directory containing blas.pc to"
        "\n   the PKG_CONFIG_PATH environment variable.${ColourReset}")
PRUVOST Florent's avatar
PRUVOST Florent committed
415
    endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
416
  endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
417

PRUVOST Florent's avatar
PRUVOST Florent committed
418
419
  if (BLAS_FOUND AND BLAS_LIBRARIES)
    set(BLAS_FOUND_WITH_PKGCONFIG "TRUE")
420
    find_pkgconfig_libraries_absolute_path(BLAS)
PRUVOST Florent's avatar
PRUVOST Florent committed
421
422
423
  else()
    set(BLAS_FOUND_WITH_PKGCONFIG "FALSE")
  endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
424

PRUVOST Florent's avatar
PRUVOST Florent committed
425
endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
426

PRUVOST Florent's avatar
PRUVOST Florent committed
427
428
429
if( (NOT BLAS_FOUND_WITH_PKGCONFIG) OR BLAS_GIVEN_BY_USER )
  #BLAS in intel mkl 10 library? (em64t 64bit)
  if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
430

PRUVOST Florent's avatar
PRUVOST Florent committed
431
432
433
    if(NOT BLAS_LIBRARIES OR BLA_VENDOR MATCHES "Intel*")
      # Looking for include
      # -------------------
434

PRUVOST Florent's avatar
PRUVOST Florent committed
435
436
437
438
439
440
441
442
443
444
445
      # Add system include paths to search include
      # ------------------------------------------
      unset(_inc_env)
      set(ENV_MKLROOT "$ENV{MKLROOT}")
      set(ENV_BLAS_DIR "$ENV{BLAS_DIR}")
      set(ENV_BLAS_INCDIR "$ENV{BLAS_INCDIR}")
      if(ENV_BLAS_INCDIR)
        list(APPEND _inc_env "${ENV_BLAS_INCDIR}")
      elseif(ENV_BLAS_DIR)
        list(APPEND _inc_env "${ENV_BLAS_DIR}")
        list(APPEND _inc_env "${ENV_BLAS_DIR}/include")
PRUVOST Florent's avatar
PRUVOST Florent committed
446
      else()
PRUVOST Florent's avatar
PRUVOST Florent committed
447
448
        if (ENV_MKLROOT)
          list(APPEND _inc_env "${ENV_MKLROOT}/include")
449
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
450
451
452
453
454
455
456
457
458
459
460
461
462
        # system variables
        if(WIN32)
          string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
          list(APPEND _inc_env "${_path_env}")
        else()
          string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
          list(APPEND _inc_env "${_path_env}")
          string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
          list(APPEND _inc_env "${_path_env}")
          string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
          list(APPEND _inc_env "${_path_env}")
          string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
          list(APPEND _inc_env "${_path_env}")
463
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
464
      endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
465
466
467
      list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
      list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
      list(REMOVE_DUPLICATES _inc_env)
468

PRUVOST Florent's avatar
PRUVOST Florent committed
469
470
      # set paths where to look for
      set(PATH_TO_LOOK_FOR "${_inc_env}")
471

PRUVOST Florent's avatar
PRUVOST Florent committed
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
      # Try to find the fftw header in the given paths
      # -------------------------------------------------
      # call cmake macro to find the header path
      if(BLAS_INCDIR)
        set(BLAS_mkl.h_DIRS "BLAS_mkl.h_DIRS-NOTFOUND")
        find_path(BLAS_mkl.h_DIRS
          NAMES mkl.h
          HINTS ${BLAS_INCDIR})
      else()
        if(BLAS_DIR)
          set(BLAS_mkl.h_DIRS "BLAS_mkl.h_DIRS-NOTFOUND")
          find_path(BLAS_mkl.h_DIRS
            NAMES mkl.h
            HINTS ${BLAS_DIR}
            PATH_SUFFIXES "include")
487
        else()
PRUVOST Florent's avatar
PRUVOST Florent committed
488
489
490
491
          set(BLAS_mkl.h_DIRS "BLAS_mkl.h_DIRS-NOTFOUND")
          find_path(BLAS_mkl.h_DIRS
            NAMES mkl.h
            HINTS ${PATH_TO_LOOK_FOR})
492
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
493
494
      endif()
      mark_as_advanced(BLAS_mkl.h_DIRS)
495

PRUVOST Florent's avatar
PRUVOST Florent committed
496
497
498
499
500
501
502
503
      # If found, add path to cmake variable
      # ------------------------------------
      if (BLAS_mkl.h_DIRS)
        set(BLAS_INCLUDE_DIRS "${BLAS_mkl.h_DIRS}")
      else ()
        set(BLAS_INCLUDE_DIRS "BLAS_INCLUDE_DIRS-NOTFOUND")
        if(NOT BLAS_FIND_QUIETLY)
          message(STATUS "Looking for BLAS -- mkl.h not found")
504
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
505
      endif()
506

PRUVOST Florent's avatar
PRUVOST Florent committed
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
      if (WIN32)
        string(REPLACE ":" ";" _libdir "$ENV{LIB}")
      elseif (APPLE)
        string(REPLACE ":" ";" _libdir "$ENV{DYLD_LIBRARY_PATH}")
      else ()
        string(REPLACE ":" ";" _libdir "$ENV{LD_LIBRARY_PATH}")
      endif ()
      list(APPEND _libdir "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
      list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
      # libiomp5
      # --------
      set(OMP_iomp5_LIBRARY "OMP_iomp5_LIBRARY-NOTFOUND")
      find_library(OMP_iomp5_LIBRARY
        NAMES iomp5
        HINTS ${_libdir}
        )
      mark_as_advanced(OMP_iomp5_LIBRARY)
      set(OMP_LIB "")
      # libgomp
      # -------
      set(OMP_gomp_LIBRARY "OMP_gomp_LIBRARY-NOTFOUND")
      find_library(OMP_gomp_LIBRARY
        NAMES gomp
        HINTS ${_libdir}
        )
      mark_as_advanced(OMP_gomp_LIBRARY)
      # choose one or another depending on the compilo
PRUVOST Florent's avatar
PRUVOST Florent committed
534
      if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
PRUVOST Florent's avatar
PRUVOST Florent committed
535
536
        if (OMP_gomp_LIBRARY)
          set(OMP_LIB "${OMP_gomp_LIBRARY}")
537
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
538
539
540
      else(CMAKE_C_COMPILER_ID STREQUAL "Intel")
        if (OMP_iomp5_LIBRARY)
          set(OMP_LIB "${OMP_iomp5_LIBRARY}")
541
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
542
      endif()
543

PRUVOST Florent's avatar
PRUVOST Florent committed
544
545
546
547
548
549
550
      if (UNIX AND NOT WIN32)
        # m
        find_library(M_LIBRARY
          NAMES m
          HINTS ${_libdir})
        mark_as_advanced(M_LIBRARY)
        if(M_LIBRARY)
551
          set(LM "${M_LIBRARY}")
PRUVOST Florent's avatar
PRUVOST Florent committed
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
        else()
          set(LM "")
        endif()
        # Fortran
        set(LGFORTRAN "")
        if (CMAKE_C_COMPILER_ID MATCHES "GNU")
          find_library(
            FORTRAN_gfortran_LIBRARY
            NAMES gfortran
            HINTS ${_libdir}
            )
          mark_as_advanced(FORTRAN_gfortran_LIBRARY)
          if (FORTRAN_gfortran_LIBRARY)
            set(LGFORTRAN "${FORTRAN_gfortran_LIBRARY}")
          endif()
        elseif (CMAKE_C_COMPILER_ID MATCHES "Intel")
          find_library(
            FORTRAN_ifcore_LIBRARY
            NAMES ifcore
            HINTS ${_libdir}
            )
          mark_as_advanced(FORTRAN_ifcore_LIBRARY)
          if (FORTRAN_ifcore_LIBRARY)
            set(LGFORTRAN "{FORTRAN_ifcore_LIBRARY}")
          endif()
        endif()
578
        set(BLAS_CFLAGS_OTHER "")
PRUVOST Florent's avatar
PRUVOST Florent committed
579
580
581
        if (NOT BLA_VENDOR STREQUAL "Intel10_64lp_seq")
          if(BLAS_FIND_REQUIRED)
            find_package(OpenMP REQUIRED)
582
          else()
PRUVOST Florent's avatar
PRUVOST Florent committed
583
            find_package(OpenMP)
584
          endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
585
          if(OPENMP_C_FLAGS)
586
            list(APPEND BLAS_CFLAGS_OTHER "${OPENMP_C_FLAGS}")
587
          endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
588
589
590
        endif()
        if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
          if (BLA_VENDOR STREQUAL "Intel10_32")
591
            list(APPEND BLAS_CFLAGS_OTHER "-m32")
PRUVOST Florent's avatar
PRUVOST Florent committed
592
          else()
593
            list(APPEND BLAS_CFLAGS_OTHER "-m64")
594
          endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
595
          if (NOT BLA_VENDOR STREQUAL "Intel10_64lp_seq")
PRUVOST Florent's avatar
PRUVOST Florent committed
596
597
598
599
600
601
            find_library(
            DL_LIBRARY
            NAMES dl
            HINTS ${_libdir}
            )
            list(APPEND OMP_LIB "${DL_LIBRARY}")
602
          endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
603
        endif()
604

PRUVOST Florent's avatar
PRUVOST Florent committed
605
606
607
608
609
        set(additional_flags "")
        if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
          set(additional_flags "-Wl,--no-as-needed")
        endif()
      endif ()
610

PRUVOST Florent's avatar
PRUVOST Florent committed
611
612
613
614
615
616
      if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
        if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
          find_package(Threads)
        else()
          find_package(Threads REQUIRED)
        endif()
617
        if( THREADS_FOUND )
618
          libraries_absolute_path(CMAKE_THREAD_LIBS_INIT "")
619
        endif ()
620

PRUVOST Florent's avatar
PRUVOST Florent committed
621
        set(BLAS_SEARCH_LIBS "")
622

PRUVOST Florent's avatar
PRUVOST Florent committed
623
        if(BLA_F95)
624

PRUVOST Florent's avatar
PRUVOST Florent committed
625
626
627
628
629
630
631
632
          set(BLAS_mkl_SEARCH_SYMBOL SGEMM)
          set(_LIBRARIES BLAS95_LIBRARIES)
          if (WIN32)
            if (BLA_STATIC)
              set(BLAS_mkl_DLL_SUFFIX "")
            else()
              set(BLAS_mkl_DLL_SUFFIX "_dll")
            endif()
633

PRUVOST Florent's avatar
PRUVOST Florent committed
634
635
636
637
638
639
640
641
642
643
            # Find the main file (32-bit or 64-bit)
            set(BLAS_SEARCH_LIBS_WIN_MAIN "")
            if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
              list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
                "mkl_blas95${BLAS_mkl_DLL_SUFFIX} mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
            endif()
            if (BLA_VENDOR STREQUAL "Intel10_64lp*" OR BLA_VENDOR STREQUAL "All")
              list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
                "mkl_blas95_lp64${BLAS_mkl_DLL_SUFFIX} mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}")
            endif ()
644

PRUVOST Florent's avatar
PRUVOST Florent committed
645
646
647
648
649
650
651
652
653
654
655
656
657
658
            # Add threading/sequential libs
            set(BLAS_SEARCH_LIBS_WIN_THREAD "")
            if (BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
              list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
                "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
            endif()
            if (NOT BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
              # old version
              list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
                "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
              # mkl >= 10.3
              list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
                "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
            endif()
659

PRUVOST Florent's avatar
PRUVOST Florent committed
660
661
662
663
664
665
            # Cartesian product of the above
            foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
              foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
                list(APPEND BLAS_SEARCH_LIBS
                  "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
              endforeach()
666
            endforeach()
PRUVOST Florent's avatar
PRUVOST Florent committed
667
668
          else (WIN32)
            if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
669
              list(APPEND BLAS_SEARCH_LIBS
PRUVOST Florent's avatar
PRUVOST Florent committed
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
                "mkl_blas95 mkl_intel mkl_intel_thread mkl_core guide")
            endif ()
            if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
              # old version
              list(APPEND BLAS_SEARCH_LIBS
                "mkl_blas95 mkl_intel_lp64 mkl_intel_thread mkl_core guide")
              # mkl >= 10.3
              if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
                list(APPEND BLAS_SEARCH_LIBS
                  "mkl_blas95_lp64 mkl_intel_lp64 mkl_intel_thread mkl_core")
              endif()
              if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
                list(APPEND BLAS_SEARCH_LIBS
                  "mkl_blas95_lp64 mkl_intel_lp64 mkl_gnu_thread mkl_core")
              endif()
            endif ()
            if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
687
              list(APPEND BLAS_SEARCH_LIBS
PRUVOST Florent's avatar
PRUVOST Florent committed
688
689
690
691
692
693
                "mkl_intel_lp64 mkl_sequential mkl_core")
              if (BLA_VENDOR STREQUAL "Intel10_64lp_seq")
                set(OMP_LIB "")
              endif()
            endif ()
          endif (WIN32)
694

PRUVOST Florent's avatar
PRUVOST Florent committed
695
        else (BLA_F95)
696

PRUVOST Florent's avatar
PRUVOST Florent committed
697
698
699
700
701
702
703
          set(BLAS_mkl_SEARCH_SYMBOL sgemm)
          set(_LIBRARIES BLAS_LIBRARIES)
          if (WIN32)
            if (BLA_STATIC)
              set(BLAS_mkl_DLL_SUFFIX "")
            else()
              set(BLAS_mkl_DLL_SUFFIX "_dll")
704
            endif()
705

PRUVOST Florent's avatar
PRUVOST Florent committed
706
707
708
709
710
            # Find the main file (32-bit or 64-bit)
            set(BLAS_SEARCH_LIBS_WIN_MAIN "")
            if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
              list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
                "mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
711
            endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
712
713
714
715
            if (BLA_VENDOR STREQUAL "Intel10_64lp*" OR BLA_VENDOR STREQUAL "All")
              list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
                "mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}")
            endif ()
716

PRUVOST Florent's avatar
PRUVOST Florent committed
717
718
719
720
721
722
723
724
725
726
727
728
729
730
            # Add threading/sequential libs
            set(BLAS_SEARCH_LIBS_WIN_THREAD "")
            if (NOT BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
              # old version
              list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
                "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
              # mkl >= 10.3
              list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
                "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
            endif()
            if (BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
              list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
                "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
            endif()
731

PRUVOST Florent's avatar
PRUVOST Florent committed
732
733
734
735
736
737
            # Cartesian product of the above
            foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
              foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
                list(APPEND BLAS_SEARCH_LIBS
                  "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
              endforeach()
738
            endforeach()
PRUVOST Florent's avatar
PRUVOST Florent committed
739
740
          else (WIN32)
            if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
741
              list(APPEND BLAS_SEARCH_LIBS
PRUVOST Florent's avatar
PRUVOST Florent committed
742
743
744
745
                "mkl_intel mkl_intel_thread mkl_core guide")
            endif ()
            if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
              # old version
746
              list(APPEND BLAS_SEARCH_LIBS
PRUVOST Florent's avatar
PRUVOST Florent committed
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
                "mkl_intel_lp64 mkl_intel_thread mkl_core guide")
              # mkl >= 10.3
              if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
                list(APPEND BLAS_SEARCH_LIBS
                  "mkl_intel_lp64 mkl_intel_thread mkl_core")
              endif()
              if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
                list(APPEND BLAS_SEARCH_LIBS
                  "mkl_intel_lp64 mkl_gnu_thread mkl_core")
              endif()
            endif ()
            if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
              list(APPEND BLAS_SEARCH_LIBS
                "mkl_intel_lp64 mkl_sequential mkl_core")
              if (BLA_VENDOR STREQUAL "Intel10_64lp_seq")
                set(OMP_LIB "")
              endif()
            endif ()
            #older vesions of intel mkl libs
            if (BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All")
              list(APPEND BLAS_SEARCH_LIBS
                "mkl")
              list(APPEND BLAS_SEARCH_LIBS
                "mkl_ia32")
              list(APPEND BLAS_SEARCH_LIBS
                "mkl_em64t")
            endif ()
          endif (WIN32)
775

PRUVOST Florent's avatar
PRUVOST Florent committed
776
        endif (BLA_F95)
777

PRUVOST Florent's avatar
PRUVOST Florent committed
778
779
780
781
782
783
784
785
786
787
788
789
790
        foreach (IT ${BLAS_SEARCH_LIBS})
          string(REPLACE " " ";" SEARCH_LIBS ${IT})
          if (${_LIBRARIES})
          else ()
            check_fortran_libraries(
              ${_LIBRARIES}
              BLAS
              ${BLAS_mkl_SEARCH_SYMBOL}
              "${additional_flags}"
              "${SEARCH_LIBS}"
              "${OMP_LIB};${CMAKE_THREAD_LIBS_INIT};${LM}"
              )
            if(_LIBRARIES)
791
              set(BLAS_LDFLAGS_OTHER "${additional_flags}")
792
            endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
793
794
795
796
797
798
799
          endif()
        endforeach ()
        if(NOT BLAS_FIND_QUIETLY)
          if(${_LIBRARIES})
            message(STATUS "Looking for MKL BLAS: found")
          else()
            message(STATUS "Looking for MKL BLAS: not found")
800
801
          endif()
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
802
803
804
805
806
807
        if (${_LIBRARIES} AND NOT BLAS_VENDOR_FOUND)
            set (BLAS_VENDOR_FOUND "Intel MKL")
        endif()
      endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
    endif(NOT BLAS_LIBRARIES OR BLA_VENDOR MATCHES "Intel*")
  endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
808
809


PRUVOST Florent's avatar
PRUVOST Florent committed
810
  if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
811

PRUVOST Florent's avatar
PRUVOST Florent committed
812
813
814
815
816
817
818
819
820
821
    if(NOT BLAS_LIBRARIES)
      # gotoblas (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
      check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "goto2"
        ""
        )
PRUVOST Florent's avatar
PRUVOST Florent committed
822
      if(NOT BLAS_FIND_QUIETLY)
PRUVOST Florent's avatar
PRUVOST Florent committed
823
824
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for Goto BLAS: found")
PRUVOST Florent's avatar
PRUVOST Florent committed
825
        else()
PRUVOST Florent's avatar
PRUVOST Florent committed
826
          message(STATUS "Looking for Goto BLAS: not found")
PRUVOST Florent's avatar
PRUVOST Florent committed
827
828
829
        endif()
      endif()
    endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
830
831
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "Goto")
PRUVOST Florent's avatar
PRUVOST Florent committed
832
    endif()
833

PRUVOST Florent's avatar
PRUVOST Florent committed
834
  endif (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
835
836


PRUVOST Florent's avatar
PRUVOST Florent committed
837
838
  # OpenBlas
  if (BLA_VENDOR STREQUAL "Open" OR BLA_VENDOR STREQUAL "All")
839

PRUVOST Florent's avatar
PRUVOST Florent committed
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
    if(NOT BLAS_LIBRARIES)
      # openblas (http://www.openblas.net/)
      check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "openblas"
        ""
        )
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for Open BLAS: found")
        else()
          message(STATUS "Looking for Open BLAS: not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
856
857
      endif()
    endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
858
859
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "Openblas")
PRUVOST Florent's avatar
PRUVOST Florent committed
860
    endif()
861

PRUVOST Florent's avatar
PRUVOST Florent committed
862
  endif (BLA_VENDOR STREQUAL "Open" OR BLA_VENDOR STREQUAL "All")
863
864


PRUVOST Florent's avatar
PRUVOST Florent committed
865
866
  # EigenBlas
  if (BLA_VENDOR STREQUAL "Eigen" OR BLA_VENDOR STREQUAL "All")
867

PRUVOST Florent's avatar
PRUVOST Florent committed
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
    if(NOT BLAS_LIBRARIES)
      # eigenblas (http://eigen.tuxfamily.org/index.php?title=Main_Page)
      check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "eigen_blas"
        ""
        )
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
          message(STATUS "Looking for Eigen BLAS: found")
        else()
          message(STATUS "Looking for Eigen BLAS: not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
884
885
      endif()
    endif()
886

PRUVOST Florent's avatar
PRUVOST Florent committed
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
    if(NOT BLAS_LIBRARIES)
      # eigenblas (http://eigen.tuxfamily.org/index.php?title=Main_Page)
      check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "eigen_blas_static"
        ""
        )
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for Eigen BLAS: found")
        else()
          message(STATUS "Looking for Eigen BLAS: not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
903
904
      endif()
    endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
905
906
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "Eigen")
PRUVOST Florent's avatar
PRUVOST Florent committed
907
    endif()
908

PRUVOST Florent's avatar
PRUVOST Florent committed
909
  endif (BLA_VENDOR STREQUAL "Eigen" OR BLA_VENDOR STREQUAL "All")
910
911


PRUVOST Florent's avatar
PRUVOST Florent committed
912
  if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
913

PRUVOST Florent's avatar
PRUVOST Florent committed
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
    if(NOT BLAS_LIBRARIES)
      # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
      check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        dgemm
        ""
        "f77blas;atlas"
        ""
        )
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for Atlas BLAS: found")
        else()
          message(STATUS "Looking for Atlas BLAS: not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
930
931
      endif()
    endif()
932

PRUVOST Florent's avatar
PRUVOST Florent committed
933
934
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "Atlas")
PRUVOST Florent's avatar
PRUVOST Florent committed
935
    endif()
936

PRUVOST Florent's avatar
PRUVOST Florent committed
937
  endif (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
938
939


PRUVOST Florent's avatar
PRUVOST Florent committed
940
941
  # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
  if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
942

PRUVOST Florent's avatar
PRUVOST Florent committed
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
    if(NOT BLAS_LIBRARIES)
      check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "sgemm;dgemm;blas"
        ""
        )
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for PhiPACK BLAS: found")
        else()
          message(STATUS "Looking for PhiPACK BLAS: not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
958
959
      endif()
    endif()
960

PRUVOST Florent's avatar
PRUVOST Florent committed
961
962
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "PhiPACK")
PRUVOST Florent's avatar
PRUVOST Florent committed
963
    endif()
964

PRUVOST Florent's avatar
PRUVOST Florent committed
965
  endif (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
966
967


PRUVOST Florent's avatar
PRUVOST Florent committed
968
969
  # BLAS in Alpha CXML library?
  if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
970

PRUVOST Florent's avatar
PRUVOST Florent committed
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
    if(NOT BLAS_LIBRARIES)
      check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "cxml"
        ""
        )
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for CXML BLAS: found")
        else()
          message(STATUS "Looking for CXML BLAS: not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
986
987
      endif()
    endif()
988

PRUVOST Florent's avatar
PRUVOST Florent committed
989
990
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "CXML")
PRUVOST Florent's avatar
PRUVOST Florent committed
991
    endif()
992

PRUVOST Florent's avatar
PRUVOST Florent committed
993
  endif (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
994
995


PRUVOST Florent's avatar
PRUVOST Florent committed
996
997
  # BLAS in Alpha DXML library? (now called CXML, see above)
  if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
998

PRUVOST Florent's avatar
PRUVOST Florent committed
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
    if(NOT BLAS_LIBRARIES)
      check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "dxml"
        ""
        )
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for DXML BLAS: found")
        else()
          message(STATUS "Looking for DXML BLAS: not found")
        endif()
      endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1015
    endif()
1016

PRUVOST Florent's avatar
PRUVOST Florent committed
1017
1018
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "DXML")
PRUVOST Florent's avatar
PRUVOST Florent committed
1019
    endif()
1020

PRUVOST Florent's avatar
PRUVOST Florent committed
1021
  endif (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
1022
1023


PRUVOST Florent's avatar
PRUVOST Florent committed
1024
1025
  # BLAS in Sun Performance library?
  if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
1026

PRUVOST Florent's avatar
PRUVOST Florent committed
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
    if(NOT BLAS_LIBRARIES)
      check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        "-xlic_lib=sunperf"
        "sunperf;sunmath"
        ""
        )
      if(BLAS_LIBRARIES)
1037
        set(BLAS_LDFLAGS_OTHER "-xlic_lib=sunperf")
PRUVOST Florent's avatar
PRUVOST Florent committed
1038
      endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1039
1040
1041
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for SunPerf BLAS: found")
1042
        else()
PRUVOST Florent's avatar
PRUVOST Florent committed
1043
          message(STATUS "Looking for SunPerf BLAS: not found")
1044
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1045
      endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1046
    endif()
1047

PRUVOST Florent's avatar
PRUVOST Florent committed
1048
1049
1050
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "SunPerf")
    endif()
1051

PRUVOST Florent's avatar
PRUVOST Florent committed
1052
  endif ()
1053
1054


PRUVOST Florent's avatar
PRUVOST Florent committed
1055
1056
  # BLAS in SCSL library?  (SGI/Cray Scientific Library)
  if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
1057

PRUVOST Florent's avatar
PRUVOST Florent committed
1058
1059
    if(NOT BLAS_LIBRARIES)
      check_fortran_libraries(
1060
1061
1062
        BLAS_LIBRARIES
        BLAS
        sgemm
PRUVOST Florent's avatar
PRUVOST Florent committed
1063
1064
1065
        ""
        "scsl"
        ""
1066
        )
PRUVOST Florent's avatar
PRUVOST Florent committed
1067
1068
1069
1070
1071
1072
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for SCSL BLAS: found")
        else()
          message(STATUS "Looking for SCSL BLAS: not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1073
      endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1074
    endif()
1075

PRUVOST Florent's avatar
PRUVOST Florent committed
1076
1077
1078
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "SunPerf")
    endif()
1079

PRUVOST Florent's avatar
PRUVOST Florent committed
1080
  endif ()
1081
1082


PRUVOST Florent's avatar
PRUVOST Florent committed
1083
1084
  # BLAS in SGIMATH library?
  if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
1085

PRUVOST Florent's avatar
PRUVOST Florent committed
1086
1087
    if(NOT BLAS_LIBRARIES)
      check_fortran_libraries(
1088
1089
1090
        BLAS_LIBRARIES
        BLAS
        sgemm
PRUVOST Florent's avatar
PRUVOST Florent committed
1091
1092
1093
        ""
        "complib.sgimath"
        ""
1094
        )
PRUVOST Florent's avatar
PRUVOST Florent committed
1095
1096
1097
1098
1099
1100
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for SGIMATH BLAS: found")
        else()
          message(STATUS "Looking for SGIMATH BLAS: not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1101
      endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1102
    endif()
1103

PRUVOST Florent's avatar
PRUVOST Florent committed
1104
1105
1106
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "SGIMATH")
    endif()
1107

PRUVOST Florent's avatar
PRUVOST Florent committed
1108
  endif ()
1109
1110


PRUVOST Florent's avatar
PRUVOST Florent committed
1111
1112
  # BLAS in IBM ESSL library (requires generic BLAS lib, too)
  if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
1113

PRUVOST Florent's avatar
PRUVOST Florent committed
1114
1115
    if(NOT BLAS_LIBRARIES)
      check_fortran_libraries(
1116
1117
1118
        BLAS_LIBRARIES
        BLAS
        sgemm
PRUVOST Florent's avatar
PRUVOST Florent committed
1119
1120
1121
        ""
        "essl"
        ""
1122
        )
PRUVOST Florent's avatar
PRUVOST Florent committed
1123
1124
1125
1126
1127
1128
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for IBM ESSL BLAS: found")
        else()
          message(STATUS "Looking for IBM ESSL BLAS: not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1129
      endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1130
    endif()
1131

PRUVOST Florent's avatar
PRUVOST Florent committed
1132
1133
1134
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "IBM ESSL")
    endif()
1135

PRUVOST Florent's avatar
PRUVOST Florent committed
1136
  endif ()
1137

PRUVOST Florent's avatar
PRUVOST Florent committed
1138
1139
  # BLAS in IBM ESSL_MT library (requires generic BLAS lib, too)
  if (BLA_VENDOR STREQUAL "IBMESSLMT" OR BLA_VENDOR STREQUAL "All")
1140

PRUVOST Florent's avatar
PRUVOST Florent committed
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
    if(NOT BLAS_LIBRARIES)
      check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "esslsmp"
        ""
        )
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for IBM ESSL MT BLAS: found")
        else()
          message(STATUS "Looking for IBM ESSL MT BLAS: not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1156
1157
      endif()
    endif()
1158

PRUVOST Florent's avatar
PRUVOST Florent committed
1159
1160
1161
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "IBM ESSL MT")
    endif()
1162

PRUVOST Florent's avatar
PRUVOST Florent committed
1163
  endif ()
1164
1165


PRUVOST Florent's avatar
PRUVOST Florent committed
1166
1167
  #BLAS in acml library?
  if (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All")
1168

PRUVOST Florent's avatar
PRUVOST Florent committed
1169
1170
1171
    if( ((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
        ((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR
        ((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS)))
1172

PRUVOST Florent's avatar
PRUVOST Florent committed
1173
1174
1175
      # try to find acml in "standard" paths
      if( WIN32 )
        file( GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt" )
PRUVOST Florent's avatar
PRUVOST Florent committed
1176
      else()
PRUVOST Florent's avatar
PRUVOST Florent committed
1177
        file( GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt" )
PRUVOST Florent's avatar
PRUVOST Florent committed
1178
      endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1179
1180
      if( WIN32 )
        file( GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples" )
PRUVOST Florent's avatar
PRUVOST Florent committed
1181
      else()
PRUVOST Florent's avatar
PRUVOST Florent committed
1182
        file( GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples" )
PRUVOST Florent's avatar
PRUVOST Florent committed
1183
      endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1184
1185
      list(GET _ACML_ROOT 0 _ACML_ROOT)
      list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)
1186

PRUVOST Florent's avatar
PRUVOST Florent committed
1187
      if( _ACML_ROOT )
1188

PRUVOST Florent's avatar
PRUVOST Florent committed
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
        get_filename_component( _ACML_ROOT ${_ACML_ROOT} PATH )
        if( SIZEOF_INTEGER EQUAL 8 )
          set( _ACML_PATH_SUFFIX "_int64" )
        else()
          set( _ACML_PATH_SUFFIX "" )
        endif()
        if( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
          set( _ACML_COMPILER32 "ifort32" )
          set( _ACML_COMPILER64 "ifort64" )
        elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
          set( _ACML_COMPILER32 "sun32" )
          set( _ACML_COMPILER64 "sun64" )
        elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" )
          set( _ACML_COMPILER32 "pgi32" )
          if( WIN32 )
            set( _ACML_COMPILER64 "win64" )
          else()
            set( _ACML_COMPILER64 "pgi64" )
          endif()
        elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Open64" )
          # 32 bit builds not supported on Open64 but for code simplicity
          # We'll just use the same directory twice
          set( _ACML_COMPILER32 "open64_64" )
          set( _ACML_COMPILER64 "open64_64" )
        elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" )
          set( _ACML_COMPILER32 "nag32" )
          set( _ACML_COMPILER64 "nag64" )
        else()
          set( _ACML_COMPILER32 "gfortran32" )
          set( _ACML_COMPILER64 "gfortran64" )
        endif()
1220

PRUVOST Florent's avatar
PRUVOST Florent committed
1221
1222
1223
1224
1225
1226
1227
1228
1229
        if( BLA_VENDOR STREQUAL "ACML_MP" )
          set(_ACML_MP_LIB_DIRS
            "${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib"
            "${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib" )
        else()
          set(_ACML_LIB_DIRS
            "${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib"
            "${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib" )
        endif()
1230

PRUVOST Florent's avatar
PRUVOST Florent committed
1231
      endif(_ACML_ROOT)
1232

PRUVOST Florent's avatar
PRUVOST Florent committed
1233
    elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)
1234

PRUVOST Florent's avatar
PRUVOST Florent committed
1235
      set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})
1236

PRUVOST Florent's avatar
PRUVOST Florent committed
1237
    endif()
1238

PRUVOST Florent's avatar
PRUVOST Florent committed
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
    if( BLA_VENDOR STREQUAL "ACML_MP" )
      foreach( BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS})
        check_fortran_libraries (
          BLAS_LIBRARIES
          BLAS
          sgemm
          "" "acml_mp;acml_mv" "" ${BLAS_ACML_MP_LIB_DIRS}
          )
        if( BLAS_LIBRARIES )
          break()
        endif()
      endforeach()
    elseif( BLA_VENDOR STREQUAL "ACML_GPU" )
      foreach( BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS})
        check_fortran_libraries (
          BLAS_LIBRARIES
          BLAS
          sgemm
          "" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS}
          )
        if( BLAS_LIBRARIES )
          break()
        endif()
      endforeach()
    else()
      foreach( BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS} )
        check_fortran_libraries (
          BLAS_LIBRARIES
          BLAS
          sgemm
          "" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS}
          )
        if( BLAS_LIBRARIES )
          break()
        endif()
      endforeach()
    endif()
1276

PRUVOST Florent's avatar
PRUVOST Florent committed
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
    # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
    if(NOT BLAS_LIBRARIES)
      check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "acml;acml_mv"
        ""
        )
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for ACML BLAS: found")
        else()
          message(STATUS "Looking for ACML BLAS: not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1293
1294
      endif()
    endif()
1295

PRUVOST Florent's avatar
PRUVOST Florent committed
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
    if(NOT BLAS_LIBRARIES)
      check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "acml_mp;acml_mv"
        ""
        )
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for ACML BLAS: found")
        else()
          message(STATUS "Looking for ACML BLAS: not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1311
1312
      endif()
    endif()
1313

PRUVOST Florent's avatar
PRUVOST Florent committed
1314
    if(NOT BLAS_LIBRARIES)
PRUVOST Florent's avatar
PRUVOST Florent committed
1315
      check_fortran_libraries(
1316
1317
1318
1319
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
PRUVOST Florent's avatar
PRUVOST Florent committed
1320
1321
        "acml;acml_mv;CALBLAS"
        ""
1322
        )
PRUVOST Florent's avatar
PRUVOST Florent committed
1323
      if(NOT BLAS_FIND_QUIETLY)
1324
        if(BLAS_LIBRARIES)
PRUVOST Florent's avatar
PRUVOST Florent committed
1325
          message(STATUS "Looking for ACML BLAS: found")
1326
        else()
PRUVOST Florent's avatar
PRUVOST Florent committed
1327
          message(STATUS "Looking for ACML BLAS: not found")
1328
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1329
1330
      endif()
    endif()
1331

PRUVOST Florent's avatar
PRUVOST Florent committed
1332
1333
1334
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "ACML")
    endif()
1335

PRUVOST Florent's avatar
PRUVOST Florent committed
1336
  endif (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All") # ACML
1337
1338


PRUVOST Florent's avatar
PRUVOST Florent committed
1339
1340
  # Apple BLAS library?
  if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
1341

PRUVOST Florent's avatar
PRUVOST Florent committed
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
    if(NOT BLAS_LIBRARIES)
      check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        dgemm
        ""
        "Accelerate"
        ""
        )
      if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_LIBRARIES)
          message(STATUS "Looking for Apple BLAS: found")
        else()
          message(STATUS "Looking for Apple BLAS: not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1357
      endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
1358
    endif()
1359

PRUVOST Florent's avatar
PRUVOST Florent committed
1360
1361
1362
    if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
        set (BLAS_VENDOR_FOUND "Apple Accelerate")
    endif()
1363

PRUVOST Florent's avatar
PRUVOST Florent committed
1364
  endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
1365
1366