1# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2# file Copyright.txt or https://cmake.org/licensing for details.
3
4#[=======================================================================[.rst:
5FindBLAS
6--------
7
8Find Basic Linear Algebra Subprograms (BLAS) library
9
10This module finds an installed Fortran library that implements the
11`BLAS linear-algebra interface`_.
12
13At least one of the ``C``, ``CXX``, or ``Fortran`` languages must be enabled.
14
15.. _`BLAS linear-algebra interface`: http://www.netlib.org/blas/
16
17Input Variables
18^^^^^^^^^^^^^^^
19
20The following variables may be set to influence this module's behavior:
21
22``BLA_STATIC``
23  if ``ON`` use static linkage
24
25``BLA_VENDOR``
26  Set to one of the :ref:`BLAS/LAPACK Vendors` to search for BLAS only
27  from the specified vendor.  If not set, all vendors are considered.
28
29``BLA_F95``
30  if ``ON`` tries to find the BLAS95 interfaces
31
32``BLA_PREFER_PKGCONFIG``
33  .. versionadded:: 3.11
34
35  if set ``pkg-config`` will be used to search for a BLAS library first
36  and if one is found that is preferred
37
38``BLA_SIZEOF_INTEGER``
39  .. versionadded:: 3.22
40
41  Specify the BLAS/LAPACK library integer size:
42
43  ``4``
44    Search for a BLAS/LAPACK with 32-bit integer interfaces.
45  ``8``
46    Search for a BLAS/LAPACK with 64-bit integer interfaces.
47  ``ANY``
48    Search for any BLAS/LAPACK.
49    Most likely, a BLAS/LAPACK with 32-bit integer interfaces will be found.
50
51Imported targets
52^^^^^^^^^^^^^^^^
53
54This module defines the following :prop_tgt:`IMPORTED` targets:
55
56``BLAS::BLAS``
57  .. versionadded:: 3.18
58
59  The libraries to use for BLAS, if found.
60
61Result Variables
62^^^^^^^^^^^^^^^^
63
64This module defines the following variables:
65
66``BLAS_FOUND``
67  library implementing the BLAS interface is found
68``BLAS_LINKER_FLAGS``
69  uncached list of required linker flags (excluding ``-l`` and ``-L``).
70``BLAS_LIBRARIES``
71  uncached list of libraries (using full path name) to link against
72  to use BLAS (may be empty if compiler implicitly links BLAS)
73``BLAS95_LIBRARIES``
74  uncached list of libraries (using full path name) to link against
75  to use BLAS95 interface
76``BLAS95_FOUND``
77  library implementing the BLAS95 interface is found
78
79.. _`BLAS/LAPACK Vendors`:
80
81BLAS/LAPACK Vendors
82^^^^^^^^^^^^^^^^^^^
83
84``Generic``
85  Generic reference implementation
86
87``ACML``, ``ACML_MP``, ``ACML_GPU``
88  AMD Core Math Library
89
90``Apple``, ``NAS``
91  Apple BLAS (Accelerate), and Apple NAS (vecLib)
92
93``Arm``, ``Arm_mp``, ``Arm_ilp64``, ``Arm_ilp64_mp``
94  .. versionadded:: 3.18
95
96  Arm Performance Libraries
97
98``ATLAS``
99  Automatically Tuned Linear Algebra Software
100
101``CXML``, ``DXML``
102  Compaq/Digital Extended Math Library
103
104``EML``, ``EML_mt``
105  .. versionadded:: 3.20
106
107  Elbrus Math Library
108
109``FLAME``
110  .. versionadded:: 3.11
111
112  BLIS Framework
113
114``FlexiBLAS``
115  .. versionadded:: 3.19
116
117``Fujitsu_SSL2``, ``Fujitsu_SSL2BLAMP``, ``Fujitsu_SSL2SVE``, ``Fujitsu_SSL2BLAMPSVE``
118  .. versionadded:: 3.20
119
120  Fujitsu SSL2 serial and parallel blas/lapack with SVE instructions
121
122``Goto``
123  GotoBLAS
124
125``IBMESSL``, ``IBMESSL_SMP``
126
127  IBM Engineering and Scientific Subroutine Library
128
129``Intel``
130  Intel MKL 32 bit and 64 bit obsolete versions
131
132``Intel10_32``
133  Intel MKL v10 32 bit, threaded code
134
135``Intel10_64lp``
136  Intel MKL v10+ 64 bit, threaded code, lp64 model
137
138``Intel10_64lp_seq``
139  Intel MKL v10+ 64 bit, sequential code, lp64 model
140
141``Intel10_64ilp``
142  .. versionadded:: 3.13
143
144  Intel MKL v10+ 64 bit, threaded code, ilp64 model
145
146``Intel10_64ilp_seq``
147  .. versionadded:: 3.13
148
149  Intel MKL v10+ 64 bit, sequential code, ilp64 model
150
151``Intel10_64_dyn``
152  .. versionadded:: 3.17
153
154  Intel MKL v10+ 64 bit, single dynamic library
155
156``NVHPC``
157  .. versionadded:: 3.21
158
159  NVIDIA HPC SDK
160
161``OpenBLAS``
162  .. versionadded:: 3.6
163
164``PhiPACK``
165  Portable High Performance ANSI C (PHiPAC)
166
167``SCSL``, ``SCSL_mp``
168  Scientific Computing Software Library
169
170``SGIMATH``
171  SGI Scientific Mathematical Library
172
173``SunPerf``
174  Sun Performance Library
175
176.. _`Intel MKL`:
177
178Intel MKL
179^^^^^^^^^
180
181To use the Intel MKL implementation of BLAS, a project must enable at least
182one of the ``C`` or ``CXX`` languages.  Set ``BLA_VENDOR`` to an Intel MKL
183variant either on the command-line as ``-DBLA_VENDOR=Intel10_64lp`` or in
184project code:
185
186.. code-block:: cmake
187
188  set(BLA_VENDOR Intel10_64lp)
189  find_package(BLAS)
190
191In order to build a project using Intel MKL, and end user must first
192establish an Intel MKL environment:
193
194Intel oneAPI
195  Source the full Intel environment script:
196
197  .. code-block:: shell
198
199    . /opt/intel/oneapi/setvars.sh
200
201  Or, source the MKL component environment script:
202
203  .. code-block:: shell
204
205    . /opt/intel/oneapi/mkl/latest/env/vars.sh
206
207Intel Classic
208  Source the full Intel environment script:
209
210  .. code-block:: shell
211
212    . /opt/intel/bin/compilervars.sh intel64
213
214  Or, source the MKL component environment script:
215
216  .. code-block:: shell
217
218    . /opt/intel/mkl/bin/mklvars.sh intel64
219
220The above environment scripts set the ``MKLROOT`` environment variable
221to the top of the MKL installation.  They also add the location of the
222runtime libraries to the dynamic library loader environment variable for
223your platform (e.g. ``LD_LIBRARY_PATH``).  This is necessary for programs
224linked against MKL to run.
225
226.. note::
227
228  As of Intel oneAPI 2021.2, loading only the MKL component does not
229  make all of its dependencies available.  In particular, the ``iomp5``
230  library must be available separately, or provided by also loading
231  the compiler component environment:
232
233  .. code-block:: shell
234
235    . /opt/intel/oneapi/compiler/latest/env/vars.sh
236
237#]=======================================================================]
238
239# The approach follows that of the ``autoconf`` macro file, ``acx_blas.m4``
240# (distributed at http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
241
242# Check the language being used
243if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_COMPILER_LOADED))
244  if(BLAS_FIND_REQUIRED)
245    message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.")
246  else()
247    message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)")
248    return()
249  endif()
250endif()
251
252function(_add_blas_target)
253  if(BLAS_FOUND AND NOT TARGET BLAS::BLAS)
254    add_library(BLAS::BLAS INTERFACE IMPORTED)
255    if(BLAS_LIBRARIES)
256      set_target_properties(BLAS::BLAS PROPERTIES
257        INTERFACE_LINK_LIBRARIES "${BLAS_LIBRARIES}"
258      )
259    endif()
260    if(BLAS_LINKER_FLAGS)
261      set_target_properties(BLAS::BLAS PROPERTIES
262        INTERFACE_LINK_OPTIONS "${BLAS_LINKER_FLAGS}"
263      )
264    endif()
265  endif()
266endfunction()
267
268if(CMAKE_Fortran_COMPILER_LOADED)
269  include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake)
270else()
271  include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
272endif()
273include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
274
275if(BLA_PREFER_PKGCONFIG)
276  find_package(PkgConfig)
277  pkg_check_modules(PKGC_BLAS blas)
278  if(PKGC_BLAS_FOUND)
279    set(BLAS_FOUND ${PKGC_BLAS_FOUND})
280    set(BLAS_LIBRARIES "${PKGC_BLAS_LINK_LIBRARIES}")
281    _add_blas_target()
282    return()
283  endif()
284endif()
285
286# TODO: move this stuff to a separate module
287
288function(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibdir _subdirs)
289  # This function checks for the existence of the combination of libraries
290  # given by _list.  If the combination is found, this checks whether can link
291  # against that library combination using the name of a routine given by _name
292  # using the linker flags given by _flags.  If the combination of libraries is
293  # found and passes the link test, ${LIBRARIES} is set to the list of complete
294  # library paths that have been found.  Otherwise, ${LIBRARIES} is set to FALSE.
295
296  set(_libraries_work TRUE)
297  set(_libraries)
298  set(_combined_name)
299
300  if(BLA_STATIC)
301    if(WIN32)
302      set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
303    else()
304      set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
305    endif()
306  else()
307    if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
308      # for ubuntu's libblas3gf and liblapack3gf packages
309      set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
310    endif()
311  endif()
312
313  set(_extaddlibdir "${_addlibdir}")
314  if(WIN32)
315    list(APPEND _extaddlibdir ENV LIB)
316  elseif(APPLE)
317    list(APPEND _extaddlibdir ENV DYLD_LIBRARY_PATH)
318  else()
319    list(APPEND _extaddlibdir ENV LD_LIBRARY_PATH)
320  endif()
321  list(APPEND _extaddlibdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
322
323  foreach(_library ${_list})
324    if(_library MATCHES "^-")
325      # Respect linker flags as-is (required by MKL)
326      list(APPEND _libraries "${_library}")
327    else()
328      string(REGEX REPLACE "[^A-Za-z0-9]" "_" _lib_var "${_library}")
329      string(APPEND _combined_name "_${_lib_var}")
330      if(NOT "${_deps}" STREQUAL "")
331        string(APPEND _combined_name "_deps")
332      endif()
333      if(_libraries_work)
334        find_library(${_prefix}_${_lib_var}_LIBRARY
335          NAMES ${_library}
336          NAMES_PER_DIR
337          PATHS ${_extaddlibdir}
338          PATH_SUFFIXES ${_subdirs}
339        )
340        mark_as_advanced(${_prefix}_${_lib_var}_LIBRARY)
341        list(APPEND _libraries ${${_prefix}_${_lib_var}_LIBRARY})
342        set(_libraries_work ${${_prefix}_${_lib_var}_LIBRARY})
343      endif()
344    endif()
345  endforeach()
346
347  foreach(_flag ${_flags})
348    string(REGEX REPLACE "[^A-Za-z0-9]" "_" _flag_var "${_flag}")
349    string(APPEND _combined_name "_${_flag_var}")
350  endforeach()
351  if(_libraries_work)
352    # Test this combination of libraries.
353    set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${_libraries} ${_deps})
354    set(CMAKE_REQUIRED_QUIET ${BLAS_FIND_QUIETLY})
355    if(CMAKE_Fortran_COMPILER_LOADED)
356      check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
357    else()
358      check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
359    endif()
360    set(CMAKE_REQUIRED_LIBRARIES)
361    set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
362  endif()
363
364  if(_libraries_work)
365    if("${_list}" STREQUAL "")
366      set(_libraries "${LIBRARIES}-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
367    else()
368      list(APPEND _libraries ${_deps})
369    endif()
370  else()
371    set(_libraries FALSE)
372  endif()
373  set(${LIBRARIES} "${_libraries}" PARENT_SCOPE)
374endfunction()
375
376set(BLAS_LINKER_FLAGS)
377set(BLAS_LIBRARIES)
378set(BLAS95_LIBRARIES)
379set(_blas_fphsa_req_var BLAS_LIBRARIES)
380if(NOT $ENV{BLA_VENDOR} STREQUAL "")
381  set(BLA_VENDOR $ENV{BLA_VENDOR})
382else()
383  if(NOT BLA_VENDOR)
384    set(BLA_VENDOR "All")
385  endif()
386endif()
387
388if(NOT BLA_SIZEOF_INTEGER)
389  # in the reality we do not know which API of BLAS/LAPACK is masked in library
390  set(_blas_sizeof_integer "ANY")
391elseif((BLA_SIZEOF_INTEGER STREQUAL "ANY") OR
392       (BLA_SIZEOF_INTEGER STREQUAL "4") OR
393       (BLA_SIZEOF_INTEGER STREQUAL "8"))
394  set(_blas_sizeof_integer ${BLA_SIZEOF_INTEGER})
395else()
396  message(FATAL_ERROR "BLA_SIZEOF_INTEGER can have only <no value>, ANY, 4, or 8 values")
397endif()
398
399# Implicitly linked BLAS libraries?
400if(BLA_VENDOR STREQUAL "All")
401  if(NOT BLAS_LIBRARIES)
402    check_blas_libraries(
403      BLAS_LIBRARIES
404      BLAS
405      sgemm
406      ""
407      ""
408      ""
409      ""
410      ""
411      )
412  endif()
413  if(BLAS_WORKS)
414    # Give a more helpful "found" message
415    set(BLAS_WORKS "implicitly linked")
416    set(_blas_fphsa_req_var BLAS_WORKS)
417  endif()
418endif()
419
420# BLAS in the Intel MKL 10+ library?
421if(BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
422  if(NOT BLAS_LIBRARIES)
423    if(CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)
424      # System-specific settings
425      if(WIN32)
426        if(BLA_STATIC)
427          set(BLAS_mkl_DLL_SUFFIX "")
428        else()
429          set(BLAS_mkl_DLL_SUFFIX "_dll")
430        endif()
431      else()
432        if(BLA_STATIC)
433          set(BLAS_mkl_START_GROUP "-Wl,--start-group")
434          set(BLAS_mkl_END_GROUP "-Wl,--end-group")
435        else()
436          set(BLAS_mkl_START_GROUP "")
437          set(BLAS_mkl_END_GROUP "")
438        endif()
439        # Switch to GNU Fortran support layer if needed (but not on Apple, where MKL does not provide it)
440        if(CMAKE_Fortran_COMPILER_LOADED AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND NOT APPLE)
441            set(BLAS_mkl_INTFACE "gf")
442            set(BLAS_mkl_THREADING "gnu")
443            set(BLAS_mkl_OMP "gomp")
444        else()
445            set(BLAS_mkl_INTFACE "intel")
446            set(BLAS_mkl_THREADING "intel")
447            set(BLAS_mkl_OMP "iomp5")
448        endif()
449        set(BLAS_mkl_LM "-lm")
450        set(BLAS_mkl_LDL "-ldl")
451      endif()
452
453      if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
454        find_package(Threads)
455      else()
456        find_package(Threads REQUIRED)
457      endif()
458
459      if(_blas_sizeof_integer EQUAL 8)
460        set(BLAS_mkl_ILP_MODE "ilp64")
461      elseif(_blas_sizeof_integer EQUAL 4)
462        set(BLAS_mkl_ILP_MODE "lp64")
463      else()
464        if(BLA_VENDOR MATCHES "_64ilp")
465          set(BLAS_mkl_ILP_MODE "ilp64")
466        else()
467          set(BLAS_mkl_ILP_MODE "lp64")
468        endif()
469      endif()
470
471      set(BLAS_SEARCH_LIBS "")
472
473      if(BLA_F95)
474        set(BLAS_mkl_SEARCH_SYMBOL "sgemm_f95")
475        set(_BLAS_LIBRARIES BLAS95_LIBRARIES)
476        if(WIN32)
477          # Find the main file (32-bit or 64-bit)
478          set(BLAS_SEARCH_LIBS_WIN_MAIN "")
479          if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
480            list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
481              "mkl_blas95${BLAS_mkl_DLL_SUFFIX} mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
482          endif()
483
484          if(BLA_VENDOR MATCHES "^Intel10_64i?lp" OR BLA_VENDOR STREQUAL "All")
485            list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
486              "mkl_blas95_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX} mkl_intel_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX}")
487          endif()
488
489          # Add threading/sequential libs
490          set(BLAS_SEARCH_LIBS_WIN_THREAD "")
491          if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
492            # old version
493            list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
494              "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
495            # mkl >= 10.3
496            list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
497              "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
498          endif()
499          if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
500            list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
501              "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
502          endif()
503
504          # Cartesian product of the above
505          foreach(MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
506            foreach(THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
507              list(APPEND BLAS_SEARCH_LIBS
508                "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
509            endforeach()
510          endforeach()
511        else()
512          if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
513            # old version
514            list(APPEND BLAS_SEARCH_LIBS
515              "mkl_blas95 mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
516
517            # mkl >= 10.3
518            list(APPEND BLAS_SEARCH_LIBS
519              "${BLAS_mkl_START_GROUP} mkl_blas95 mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_END_GROUP} ${BLAS_mkl_OMP}")
520          endif()
521          if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
522            # old version
523            list(APPEND BLAS_SEARCH_LIBS
524              "mkl_blas95 mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
525
526            # mkl >= 10.3
527            list(APPEND BLAS_SEARCH_LIBS
528              "${BLAS_mkl_START_GROUP} mkl_blas95_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_END_GROUP} ${BLAS_mkl_OMP}")
529          endif()
530          if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
531            list(APPEND BLAS_SEARCH_LIBS
532              "${BLAS_mkl_START_GROUP} mkl_blas95_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_sequential mkl_core ${BLAS_mkl_END_GROUP}")
533          endif()
534        endif()
535      else()
536        set(BLAS_mkl_SEARCH_SYMBOL sgemm)
537        set(_BLAS_LIBRARIES BLAS_LIBRARIES)
538        if(WIN32)
539          # Find the main file (32-bit or 64-bit)
540          set(BLAS_SEARCH_LIBS_WIN_MAIN "")
541          if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
542            list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
543              "mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
544          endif()
545          if(BLA_VENDOR MATCHES "^Intel10_64i?lp" OR BLA_VENDOR STREQUAL "All")
546            list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
547              "mkl_intel_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX}")
548          endif()
549
550          # Add threading/sequential libs
551          set(BLAS_SEARCH_LIBS_WIN_THREAD "")
552          if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
553            list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
554              "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
555          endif()
556          if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
557            # old version
558            list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
559              "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
560            # mkl >= 10.3
561            list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
562              "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
563          endif()
564          if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
565            list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
566              "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
567          endif()
568
569          # Cartesian product of the above
570          foreach(MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
571            foreach(THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
572              list(APPEND BLAS_SEARCH_LIBS
573                "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
574            endforeach()
575          endforeach()
576        else()
577          if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
578            # old version
579            list(APPEND BLAS_SEARCH_LIBS
580              "mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
581
582            # mkl >= 10.3
583            list(APPEND BLAS_SEARCH_LIBS
584              "${BLAS_mkl_START_GROUP} mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_END_GROUP} ${BLAS_mkl_OMP}")
585          endif()
586          if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
587            # old version
588            list(APPEND BLAS_SEARCH_LIBS
589              "mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
590
591            # mkl >= 10.3
592            list(APPEND BLAS_SEARCH_LIBS
593              "${BLAS_mkl_START_GROUP} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_END_GROUP} ${BLAS_mkl_OMP}")
594          endif()
595          if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
596            list(APPEND BLAS_SEARCH_LIBS
597              "${BLAS_mkl_START_GROUP} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_sequential mkl_core ${BLAS_mkl_END_GROUP}")
598          endif()
599
600          #older versions of intel mkl libs
601          if(BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All")
602            list(APPEND BLAS_SEARCH_LIBS
603              "mkl")
604            list(APPEND BLAS_SEARCH_LIBS
605              "mkl_ia32")
606            list(APPEND BLAS_SEARCH_LIBS
607              "mkl_em64t")
608          endif()
609        endif()
610      endif()
611
612      if(BLA_VENDOR MATCHES "^Intel10_64_dyn$" OR BLA_VENDOR STREQUAL "All")
613        # mkl >= 10.3 with single dynamic library
614        list(APPEND BLAS_SEARCH_LIBS
615          "mkl_rt")
616      endif()
617
618      # MKL uses a multitude of partially platform-specific subdirectories:
619      if(BLA_VENDOR STREQUAL "Intel10_32")
620        set(BLAS_mkl_ARCH_NAME "ia32")
621      else()
622        set(BLAS_mkl_ARCH_NAME "intel64")
623      endif()
624      if(WIN32)
625        set(BLAS_mkl_OS_NAME "win")
626      elseif(APPLE)
627        set(BLAS_mkl_OS_NAME "mac")
628      else()
629        set(BLAS_mkl_OS_NAME "lin")
630      endif()
631      if(DEFINED ENV{MKLROOT})
632        file(TO_CMAKE_PATH "$ENV{MKLROOT}" BLAS_mkl_MKLROOT)
633        # If MKLROOT points to the subdirectory 'mkl', use the parent directory instead
634        # so we can better detect other relevant libraries in 'compiler' or 'tbb':
635        get_filename_component(BLAS_mkl_MKLROOT_LAST_DIR "${BLAS_mkl_MKLROOT}" NAME)
636        if(BLAS_mkl_MKLROOT_LAST_DIR STREQUAL "mkl")
637            get_filename_component(BLAS_mkl_MKLROOT "${BLAS_mkl_MKLROOT}" DIRECTORY)
638        endif()
639      endif()
640      set(BLAS_mkl_LIB_PATH_SUFFIXES
641          "compiler/lib" "compiler/lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}"
642          "compiler/lib/${BLAS_mkl_ARCH_NAME}"
643          "mkl/lib" "mkl/lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}"
644          "mkl/lib/${BLAS_mkl_ARCH_NAME}"
645          "lib" "lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}"
646          "lib/${BLAS_mkl_ARCH_NAME}"
647          )
648
649      foreach(_search ${BLAS_SEARCH_LIBS})
650        string(REPLACE " " ";" _search ${_search})
651        if(NOT ${_BLAS_LIBRARIES})
652          check_blas_libraries(
653            ${_BLAS_LIBRARIES}
654            BLAS
655            ${BLAS_mkl_SEARCH_SYMBOL}
656            ""
657            "${_search}"
658            "${CMAKE_THREAD_LIBS_INIT};${BLAS_mkl_LM};${BLAS_mkl_LDL}"
659            "${BLAS_mkl_MKLROOT}"
660            "${BLAS_mkl_LIB_PATH_SUFFIXES}"
661            )
662        endif()
663      endforeach()
664
665      unset(_search)
666      unset(BLAS_mkl_ILP_MODE)
667      unset(BLAS_mkl_INTFACE)
668      unset(BLAS_mkl_THREADING)
669      unset(BLAS_mkl_OMP)
670      unset(BLAS_mkl_DLL_SUFFIX)
671      unset(BLAS_mkl_LM)
672      unset(BLAS_mkl_LDL)
673      unset(BLAS_mkl_MKLROOT)
674      unset(BLAS_mkl_MKLROOT_LAST_DIR)
675      unset(BLAS_mkl_ARCH_NAME)
676      unset(BLAS_mkl_OS_NAME)
677      unset(BLAS_mkl_LIB_PATH_SUFFIXES)
678    endif()
679  endif()
680endif()
681
682if(BLA_F95)
683  find_package_handle_standard_args(BLAS REQUIRED_VARS BLAS95_LIBRARIES)
684  set(BLAS95_FOUND ${BLAS_FOUND})
685  if(BLAS_FOUND)
686    set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
687  endif()
688endif()
689
690# gotoblas? (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
691if(BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
692  if(NOT BLAS_LIBRARIES)
693    check_blas_libraries(
694      BLAS_LIBRARIES
695      BLAS
696      sgemm
697      ""
698      "goto2"
699      ""
700      ""
701      ""
702      )
703  endif()
704endif()
705
706# FlexiBLAS? (http://www.mpi-magdeburg.mpg.de/mpcsc/software/FlexiBLAS/)
707if(BLA_VENDOR STREQUAL "FlexiBLAS" OR BLA_VENDOR STREQUAL "All")
708  set(_blas_flexiblas_lib "flexiblas")
709
710  if(_blas_sizeof_integer EQUAL 8)
711    string(APPEND _blas_flexiblas_lib "64")
712  endif()
713
714  if(NOT BLAS_LIBRARIES)
715    check_blas_libraries(
716      BLAS_LIBRARIES
717      BLAS
718      sgemm
719      ""
720      "${_blas_flexiblas_lib}"
721      ""
722      ""
723      ""
724      )
725  endif()
726
727  unset(_blas_flexiblas_lib)
728endif()
729
730# OpenBLAS? (http://www.openblas.net)
731if(BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All")
732  set(_blas_openblas_lib "openblas")
733
734  if(_blas_sizeof_integer EQUAL 8)
735    string(APPEND _blas_openblas_lib "64")
736  endif()
737
738  if(NOT BLAS_LIBRARIES)
739    check_blas_libraries(
740      BLAS_LIBRARIES
741      BLAS
742      sgemm
743      ""
744      "${_blas_openblas_lib}"
745      ""
746      ""
747      ""
748      )
749  endif()
750  if(NOT BLAS_LIBRARIES AND (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED))
751    if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
752      find_package(Threads)
753    else()
754      find_package(Threads REQUIRED)
755    endif()
756    set(_threadlibs "${CMAKE_THREAD_LIBS_INIT}")
757    if(BLA_STATIC)
758      if (CMAKE_C_COMPILER_LOADED)
759        find_package(OpenMP COMPONENTS C)
760        list(PREPEND _threadlibs "${OpenMP_C_LIBRARIES}")
761      elseif(CMAKE_CXX_COMPILER_LOADED)
762        find_package(OpenMP COMPONENTS CXX)
763        list(PREPEND _threadlibs "${OpenMP_CXX_LIBRARIES}")
764      endif()
765    endif()
766    check_blas_libraries(
767      BLAS_LIBRARIES
768      BLAS
769      sgemm
770      ""
771      "${_blas_openblas_lib}"
772      "${_threadlibs}"
773      ""
774      ""
775      )
776    unset(_threadlibs)
777  endif()
778
779  unset(_blas_openblas_lib)
780endif()
781
782# ArmPL blas library? (https://developer.arm.com/tools-and-software/server-and-hpc/compile/arm-compiler-for-linux/arm-performance-libraries)
783if(BLA_VENDOR MATCHES "Arm" OR BLA_VENDOR STREQUAL "All")
784
785   # Check for 64bit Integer support
786  if(_blas_sizeof_integer EQUAL 8)
787    set(_blas_armpl_lib "armpl_ilp64")
788  elseif(_blas_sizeof_integer EQUAL 4)
789    set(_blas_armpl_lib "armpl_lp64")
790  else()
791    if(BLA_VENDOR MATCHES "_ilp64")
792      set(_blas_armpl_lib "armpl_ilp64")
793    else()
794      set(_blas_armpl_lib "armpl_lp64")
795    endif()
796  endif()
797
798   # Check for OpenMP support, VIA BLA_VENDOR of Arm_mp or Arm_ipl64_mp
799   if(BLA_VENDOR MATCHES "_mp")
800     string(APPEND _blas_armpl_lib "_mp")
801   endif()
802
803   if(NOT BLAS_LIBRARIES)
804     check_blas_libraries(
805       BLAS_LIBRARIES
806       BLAS
807       sgemm
808       ""
809       "${_blas_armpl_lib}"
810       ""
811       ""
812       ""
813       )
814  endif()
815  unset(_blas_armpl_lib)
816endif()
817
818# FLAME's blis library? (https://github.com/flame/blis)
819if(BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All")
820  set(_blas_flame_lib "blis")
821
822  if(_blas_sizeof_integer EQUAL 8)
823    string(APPEND _blas_flame_lib "64")
824  endif()
825
826  if(NOT BLAS_LIBRARIES)
827    check_blas_libraries(
828      BLAS_LIBRARIES
829      BLAS
830      sgemm
831      ""
832      "${_blas_flame_lib}"
833      ""
834      ""
835      ""
836      )
837  endif()
838
839  unset(_blas_flame_lib)
840endif()
841
842# BLAS in the ATLAS library? (http://math-atlas.sourceforge.net/)
843if(BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
844  if(NOT BLAS_LIBRARIES)
845    check_blas_libraries(
846      BLAS_LIBRARIES
847      BLAS
848      dgemm
849      ""
850      "blas;f77blas;atlas"
851      ""
852      ""
853      ""
854      )
855  endif()
856endif()
857
858# BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
859if(BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
860  if(NOT BLAS_LIBRARIES)
861    check_blas_libraries(
862      BLAS_LIBRARIES
863      BLAS
864      sgemm
865      ""
866      "sgemm;dgemm;blas"
867      ""
868      ""
869      ""
870      )
871  endif()
872endif()
873
874# BLAS in Alpha CXML library?
875if(BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
876  if(_blas_sizeof_integer EQUAL 8)
877    if(BLA_VENDOR STREQUAL "CXML")
878      message(FATAL_ERROR "CXML does not support Int64 type")
879    endif()
880  else()
881    if(NOT BLAS_LIBRARIES)
882      check_blas_libraries(
883        BLAS_LIBRARIES
884        BLAS
885        sgemm
886        ""
887        "cxml"
888        ""
889        ""
890        ""
891        )
892    endif()
893  endif()
894endif()
895
896# BLAS in Alpha DXML library? (now called CXML, see above)
897if(BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
898  if(_blas_sizeof_integer EQUAL 8)
899    if(BLA_VENDOR STREQUAL "DXML")
900      message(FATAL_ERROR "DXML does not support Int64 type")
901    endif()
902  else()
903    if(NOT BLAS_LIBRARIES)
904      check_blas_libraries(
905        BLAS_LIBRARIES
906        BLAS
907        sgemm
908        ""
909        "dxml"
910        ""
911        ""
912        ""
913        )
914    endif()
915  endif()
916endif()
917
918# BLAS in Sun Performance library?
919if(BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
920  if(NOT BLAS_LIBRARIES)
921    check_blas_libraries(
922      BLAS_LIBRARIES
923      BLAS
924      sgemm
925      "-xlic_lib=sunperf"
926      "sunperf;sunmath"
927      ""
928      ""
929      ""
930      )
931    if(BLAS_LIBRARIES)
932      set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
933    endif()
934  endif()
935endif()
936
937# BLAS in SCSL library?  (SGI/Cray Scientific Library)
938if(BLA_VENDOR MATCHES "SCSL" OR BLA_VENDOR STREQUAL "All")
939  set(_blas_scsl_lib "scs")
940
941  if(_blas_sizeof_integer EQUAL 8)
942    string(APPEND _blas_scsl_lib "_i8")
943  endif()
944  if(BLA_VENDOR MATCHES "_mp")
945    string(APPEND _blas_scsl_lib "_mp")
946  endif()
947
948  if(NOT BLAS_LIBRARIES)
949    check_blas_libraries(
950      BLAS_LIBRARIES
951      BLAS
952      sgemm
953      ""
954      "${_blas_scsl_lib}"
955      ""
956      ""
957      ""
958      )
959  endif()
960
961  unset(_blas_scsl_lib)
962endif()
963
964# BLAS in SGIMATH library?
965if(BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
966  if(NOT BLAS_LIBRARIES)
967    check_blas_libraries(
968      BLAS_LIBRARIES
969      BLAS
970      sgemm
971      ""
972      "complib.sgimath"
973      ""
974      ""
975      ""
976      )
977  endif()
978endif()
979
980# BLAS in IBM ESSL library?
981if(BLA_VENDOR MATCHES "IBMESSL" OR BLA_VENDOR STREQUAL "All")
982  set(_blas_essl_lib "essl")
983
984  if(BLA_VENDOR MATCHES "_SMP")
985    string(APPEND _blas_essl_lib "smp")
986  endif()
987  if(_blas_sizeof_integer EQUAL 8)
988    string(APPEND _blas_essl_lib "6464")
989  endif()
990
991  if(NOT BLAS_LIBRARIES)
992    check_blas_libraries(
993      BLAS_LIBRARIES
994      BLAS
995      sgemm
996      ""
997      "${_blas_essl_lib}"
998      ""
999      ""
1000      ""
1001      )
1002  endif()
1003
1004  unset(_blas_essl_lib)
1005endif()
1006
1007# BLAS in acml library?
1008if(BLA_VENDOR MATCHES "ACML" OR BLA_VENDOR STREQUAL "All")
1009  if(((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
1010    ((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR
1011    ((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS))
1012    )
1013  # try to find acml in "standard" paths
1014  if(WIN32)
1015    file(GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt")
1016  else()
1017    file(GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt")
1018  endif()
1019  if(WIN32)
1020    file(GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples")
1021  else()
1022    file(GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples")
1023  endif()
1024  list(GET _ACML_ROOT 0 _ACML_ROOT)
1025  list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)
1026  if(_ACML_ROOT)
1027    get_filename_component(_ACML_ROOT ${_ACML_ROOT} PATH)
1028    if(_blas_sizeof_integer EQUAL 8)
1029      set(_ACML_PATH_SUFFIX "_int64")
1030    else()
1031      set(_ACML_PATH_SUFFIX "")
1032    endif()
1033    if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
1034      set(_ACML_COMPILER32 "ifort32")
1035      set(_ACML_COMPILER64 "ifort64")
1036    elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
1037      # 32-bit not supported
1038      set(_ACML_COMPILER64 "ifx")
1039    elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro")
1040      set(_ACML_COMPILER32 "sun32")
1041      set(_ACML_COMPILER64 "sun64")
1042    elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")
1043      set(_ACML_COMPILER32 "pgi32")
1044      if(WIN32)
1045        set(_ACML_COMPILER64 "win64")
1046      else()
1047        set(_ACML_COMPILER64 "pgi64")
1048      endif()
1049    elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Open64")
1050      # 32 bit builds not supported on Open64 but for code simplicity
1051      # We'll just use the same directory twice
1052      set(_ACML_COMPILER32 "open64_64")
1053      set(_ACML_COMPILER64 "open64_64")
1054    elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "NAG")
1055      set(_ACML_COMPILER32 "nag32")
1056      set(_ACML_COMPILER64 "nag64")
1057    else()
1058      set(_ACML_COMPILER32 "gfortran32")
1059      set(_ACML_COMPILER64 "gfortran64")
1060    endif()
1061
1062    if(BLA_VENDOR STREQUAL "ACML_MP")
1063      set(_ACML_MP_LIB_DIRS
1064        "${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib"
1065        "${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib")
1066    else()
1067      set(_ACML_LIB_DIRS
1068        "${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib"
1069        "${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib")
1070    endif()
1071  endif()
1072elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)
1073  set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})
1074endif()
1075
1076if(BLA_VENDOR STREQUAL "ACML_MP")
1077  foreach(BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS})
1078    check_blas_libraries(
1079      BLAS_LIBRARIES
1080      BLAS
1081      sgemm
1082      "" "acml_mp;acml_mv" "" ${BLAS_ACML_MP_LIB_DIRS} ""
1083      )
1084    if(BLAS_LIBRARIES)
1085      break()
1086    endif()
1087  endforeach()
1088elseif(BLA_VENDOR STREQUAL "ACML_GPU")
1089  foreach(BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS})
1090    check_blas_libraries(
1091      BLAS_LIBRARIES
1092      BLAS
1093      sgemm
1094      "" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS} ""
1095      )
1096    if(BLAS_LIBRARIES)
1097      break()
1098    endif()
1099  endforeach()
1100else()
1101  foreach(BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS})
1102    check_blas_libraries(
1103      BLAS_LIBRARIES
1104      BLAS
1105      sgemm
1106      "" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS} ""
1107      )
1108    if(BLAS_LIBRARIES)
1109      break()
1110    endif()
1111  endforeach()
1112endif()
1113
1114# Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
1115if(NOT BLAS_LIBRARIES)
1116  check_blas_libraries(
1117    BLAS_LIBRARIES
1118    BLAS
1119    sgemm
1120    ""
1121    "acml;acml_mv"
1122    ""
1123    ""
1124    ""
1125    )
1126endif()
1127if(NOT BLAS_LIBRARIES)
1128  check_blas_libraries(
1129    BLAS_LIBRARIES
1130    BLAS
1131    sgemm
1132    ""
1133    "acml_mp;acml_mv"
1134    ""
1135    ""
1136    ""
1137    )
1138endif()
1139if(NOT BLAS_LIBRARIES)
1140  check_blas_libraries(
1141    BLAS_LIBRARIES
1142    BLAS
1143    sgemm
1144    ""
1145    "acml;acml_mv;CALBLAS"
1146    ""
1147    ""
1148    ""
1149    )
1150endif()
1151endif() # ACML
1152
1153# Apple BLAS library?
1154if(BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
1155  if(_blas_sizeof_integer EQUAL 8)
1156    if(BLA_VENDOR STREQUAL "Apple")
1157      message(FATAL_ERROR "Accelerate Framework does not support Int64 type")
1158    endif()
1159  else()
1160    if(NOT BLAS_LIBRARIES)
1161      check_blas_libraries(
1162        BLAS_LIBRARIES
1163        BLAS
1164        dgemm
1165        ""
1166        "Accelerate"
1167        ""
1168        ""
1169        ""
1170        )
1171    endif()
1172  endif()
1173endif()
1174
1175# Apple NAS (vecLib) library?
1176if(BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
1177  if(_blas_sizeof_integer EQUAL 8)
1178    if(BLA_VENDOR STREQUAL "NAS")
1179      message(FATAL_ERROR "Accelerate Framework does not support Int64 type")
1180    endif()
1181  else()
1182    if(NOT BLAS_LIBRARIES)
1183      check_blas_libraries(
1184        BLAS_LIBRARIES
1185        BLAS
1186        dgemm
1187        ""
1188        "vecLib"
1189        ""
1190        ""
1191        ""
1192        )
1193    endif()
1194  endif()
1195endif()
1196
1197# Elbrus Math Library?
1198if(BLA_VENDOR MATCHES "EML" OR BLA_VENDOR STREQUAL "All")
1199
1200  set(_blas_eml_lib "eml")
1201
1202  if(_blas_sizeof_integer EQUAL 8)
1203    string(APPEND _blas_eml_lib "_ilp64")
1204  endif()
1205  # Check for OpenMP support, VIA BLA_VENDOR of eml_mt
1206  if(BLA_VENDOR MATCHES "_mt")
1207    string(APPEND _blas_eml_lib "_mt")
1208  endif()
1209
1210  if(NOT BLAS_LIBRARIES)
1211    check_blas_libraries(
1212      BLAS_LIBRARIES
1213      BLAS
1214      sgemm
1215      ""
1216      "${_blas_eml_lib}"
1217      ""
1218      ""
1219      ""
1220      )
1221  endif()
1222  unset(_blas_eml_lib)
1223endif()
1224
1225# Fujitsu SSL2 Library?
1226if(NOT BLAS_LIBRARIES
1227    AND (BLA_VENDOR MATCHES "^Fujitsu_SSL2" OR BLA_VENDOR STREQUAL "All"))
1228  set(_blas_fjlapack_lib "fjlapack")
1229  set(_blas_fjlapack_flags "-Kopenmp")
1230
1231  if(BLA_VENDOR MATCHES "BLAMP")
1232    string(APPEND _blas_fjlapack_lib "ex")
1233  endif()
1234  if(BLA_VENDOR MATCHES "SVE")
1235    string(APPEND _blas_fjlapack_lib "sve")
1236  endif()
1237  if(_blas_sizeof_integer EQUAL 8)
1238    string(APPEND _blas_fjlapack_lib "_ilp64")
1239  endif()
1240
1241  if(NOT BLAS_LIBRARIES)
1242    check_blas_libraries(
1243      BLAS_LIBRARIES
1244      BLAS
1245      sgemm
1246      "${_blas_fjlapack_flags}"
1247      "${_blas_fjlapack_lib}"
1248      ""
1249      ""
1250      ""
1251      )
1252    if(BLAS_LIBRARIES)
1253      set(BLAS_LINKER_FLAGS ${_blas_fjlapack_flags})
1254    endif()
1255  endif()
1256
1257  unset(_blas_fjlapack_flags)
1258  unset(_blas_fjlapack_lib)
1259endif()
1260
1261# BLAS in nVidia HPC SDK? (https://developer.nvidia.com/hpc-sdk)
1262if(BLA_VENDOR STREQUAL "NVHPC" OR BLA_VENDOR STREQUAL "All")
1263  set(_blas_nvhpc_lib "blas")
1264
1265  if(_blas_sizeof_integer EQUAL 8)
1266    string(APPEND _blas_nvhpc_lib "_ilp64")
1267  elseif(_blas_sizeof_integer EQUAL 4)
1268    string(APPEND _blas_nvhpc_lib "_lp64")
1269  endif()
1270
1271  if(NOT BLAS_LIBRARIES)
1272    check_blas_libraries(
1273      BLAS_LIBRARIES
1274      BLAS
1275      sgemm
1276      ""
1277      "${_blas_nvhpc_lib}"
1278      ""
1279      ""
1280      ""
1281      )
1282  endif()
1283
1284  # an additional check for NVHPC 2020
1285  # which does not have differentiation
1286  # between lp64 and ilp64 modes
1287  if(NOT BLAS_LIBRARIES AND NOT _blas_sizeof_integer EQUAL 8)
1288    set(_blas_nvhpc_lib "blas")
1289
1290    check_blas_libraries(
1291      BLAS_LIBRARIES
1292      BLAS
1293      sgemm
1294      ""
1295      "${_blas_nvhpc_lib}"
1296      ""
1297      ""
1298      ""
1299      )
1300  endif()
1301
1302  unset(_blas_nvhpc_lib)
1303endif()
1304
1305# Generic BLAS library?
1306if(BLA_VENDOR STREQUAL "Generic" OR
1307   BLA_VENDOR STREQUAL "All")
1308  set(_blas_generic_lib "blas")
1309
1310  if(_blas_sizeof_integer EQUAL 8)
1311    string(APPEND _blas_generic_lib "64")
1312  endif()
1313
1314  if(NOT BLAS_LIBRARIES)
1315    check_blas_libraries(
1316      BLAS_LIBRARIES
1317      BLAS
1318      sgemm
1319      ""
1320      "${_blas_generic_lib}"
1321      ""
1322      ""
1323      ""
1324      )
1325  endif()
1326
1327  unset(_blas_generic_lib)
1328endif()
1329
1330# On compilers that implicitly link BLAS (i.e. CrayPrgEnv) we used a
1331# placeholder for empty BLAS_LIBRARIES to get through our logic above.
1332if(BLAS_LIBRARIES STREQUAL "BLAS_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
1333  set(BLAS_LIBRARIES "")
1334endif()
1335
1336if(NOT BLA_F95)
1337  find_package_handle_standard_args(BLAS REQUIRED_VARS ${_blas_fphsa_req_var})
1338endif()
1339
1340_add_blas_target()
1341unset(_blas_fphsa_req_var)
1342unset(_blas_sizeof_integer)
1343unset(_BLAS_LIBRARIES)
1344