FindBLAS.cmake 43.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
###
#
# @copyright (c) 2009-2014 The University of Tennessee and The University
#                          of Tennessee Research Foundation.
#                          All rights reserved.
# @copyright (c) 2012-2014 Inria. All rights reserved.
# @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
#  BLAS_LINKER_FLAGS - uncached list of required linker flags (excluding -l
#    and -L).
23
#  BLAS_COMPILER_FLAGS - uncached list of required compiler flags (including -I for mkl headers).
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#  BLAS_LIBRARIES - uncached list of libraries (using full path name) to
#    link against to use BLAS
#  BLAS95_LIBRARIES - uncached list of libraries (using full path name)
#    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
#  BLA_F95     if set on tries to find the f95 interfaces for BLAS/LAPACK
# 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
39 40
# The module can also look for the following environment variables if paths
# are not given as cmake variable: BLAS_DIR, BLAS_INCDIR, BLAS_LIBDIR
41 42
# For MKL case and if no paths are given as hints, we will try to use the MKLROOT
# environment variable
43 44 45
##########
### List of vendors (BLA_VENDOR) valid in this module
########## List of vendors (BLA_VENDOR) valid in this module
46 47 48
##  Open (for OpenBlas), Eigen (for EigenBlas), Goto, ATLAS PhiPACK,
##  CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL,
##  Intel10_32 (intel mkl v10 32 bit), Intel10_64lp (intel mkl v10 64 bit,lp thread model, lp64 model),
49
##  Intel10_64lp_seq (intel mkl v10 64 bit,sequential code, lp64 model),
50 51
##  Intel( older versions of mkl 32 and 64 bit),
##  ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic
52
# C/CXX should be enabled to use Intel mkl
53 54 55 56 57 58 59
###
# 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
60
#     2) we look in environment variable BLAS_LIBDIR or BLAS_DIR (we guess the libdirs) if defined
61 62 63 64 65
#     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
#
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

#=============================================================================
# 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.)


# Set some colors
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
#if(NOT WIN32)
#    string(ASCII 27 Esc)
#    set(ColourReset "${Esc}[m")
#    set(ColourBold  "${Esc}[1m")
#    set(Red         "${Esc}[31m")
#    set(Green       "${Esc}[32m")
#    set(Yellow      "${Esc}[33m")
#    set(Blue        "${Esc}[34m")
#    set(Magenta     "${Esc}[35m")
#    set(Cyan        "${Esc}[36m")
#    set(White       "${Esc}[37m")
#    set(BoldRed     "${Esc}[1;31m")
#    set(BoldGreen   "${Esc}[1;32m")
#    set(BoldYellow  "${Esc}[1;33m")
#    set(BoldBlue    "${Esc}[1;34m")
#    set(BoldMagenta "${Esc}[1;35m")
#    set(BoldCyan    "${Esc}[1;36m")
#    set(BoldWhite   "${Esc}[1;37m")
#endif()
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

## 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}"
                    "has not been found in ${ARGN}${ColourReset}")
        else()
            message("${Yellow}${_lib_to_find} not found."
                    "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}")
            if(_lib_env)
                message("${Yellow}${_lib_to_find} has not been found in"
                        "${_lib_env}${ColourReset}")
            endif()
        endif()
    endif()
    message("${BoldYellow}Please indicate where to find ${_lib_to_find}. You have three options:\n"
134
            "- Option 1: Provide the Installation directory of BLAS library with cmake option: -D${LIBNAME}_DIR=your/path/to/${libname}/\n"
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
            "- 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)
159
    set(BLAS_DIR "" CACHE PATH "Installation directory of BLAS library")
160 161 162 163 164
    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()

165
option(BLAS_VERBOSE "Print some additional information during BLAS libraries detection" OFF)
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

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)
202
    set(${LIBRARIES})
203
    set(_combined_name)
204 205 206
    set(ENV_MKLROOT "$ENV{MKLROOT}")
    set(ENV_BLAS_DIR "$ENV{BLAS_DIR}")
    set(ENV_BLAS_LIBDIR "$ENV{BLAS_LIBDIR}")
207
    if (NOT _libdir)
208 209 210
        if (BLAS_LIBDIR)
            list(APPEND _libdir "${BLAS_LIBDIR}")
        elseif (BLAS_DIR)
211 212 213 214 215 216 217 218 219
            list(APPEND _libdir "${BLAS_DIR}")
            list(APPEND _libdir "${BLAS_DIR}/lib")
            if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
                list(APPEND _libdir "${BLAS_DIR}/lib64")
                list(APPEND _libdir "${BLAS_DIR}/lib/intel64")
            else()
                list(APPEND _libdir "${BLAS_DIR}/lib32")
                list(APPEND _libdir "${BLAS_DIR}/lib/ia32")
            endif()
220 221
        elseif(ENV_BLAS_LIBDIR)
            list(APPEND _libdir "${ENV_BLAS_LIBDIR}")
222 223 224 225 226 227 228 229 230 231
        elseif(ENV_BLAS_DIR)
            list(APPEND _libdir "${ENV_BLAS_DIR}")
            list(APPEND _libdir "${ENV_BLAS_DIR}/lib")
            if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
                list(APPEND _libdir "${ENV_BLAS_DIR}/lib64")
                list(APPEND _libdir "${ENV_BLAS_DIR}/lib/intel64")
            else()
                list(APPEND _libdir "${ENV_BLAS_DIR}/lib32")
                list(APPEND _libdir "${ENV_BLAS_DIR}/lib/ia32")
            endif()
232
        else()
233
            if (ENV_MKLROOT)
234
                list(APPEND _libdir "${ENV_MKLROOT}/lib")
235 236 237 238 239 240 241 242
                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()
            endif()
243 244 245 246 247 248 249 250 251 252 253
            if (WIN32)
                string(REPLACE ":" ";" _libdir2 "$ENV{LIB}")
            elseif (APPLE)
                string(REPLACE ":" ";" _libdir2 "$ENV{DYLD_LIBRARY_PATH}")
            else ()
                string(REPLACE ":" ";" _libdir2 "$ENV{LD_LIBRARY_PATH}")
            endif ()
            list(APPEND _libdir "${_libdir2}")
            list(APPEND _libdir "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
            list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
        endif()
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
    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)
                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 ()
            else ()
                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 ()
            endif ()
            find_library(${_prefix}_${_library}_LIBRARY
                NAMES ${_library}
                HINTS ${_libdir}
              )
            mark_as_advanced(${_prefix}_${_library}_LIBRARY)
            # Print status if not found
            # -------------------------
            if (NOT ${_prefix}_${_library}_LIBRARY AND NOT BLAS_FIND_QUIETLY AND BLAS_VERBOSE)
                Print_Find_Library_Blas_Status(blas ${_library} ${_libdir})
            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.
296 297
        set(CMAKE_REQUIRED_LIBRARIES "${_flags};${${LIBRARIES}};${_thread}")
        set(CMAKE_REQUIRED_FLAGS "${BLAS_COMPILER_FLAGS}")
298
        if (BLAS_VERBOSE)
299 300 301
            message("${Cyan}BLAS libs found for BLA_VENDOR ${BLA_VENDOR}."
                    "Try to compile symbol ${_name} with following libraries:"
                    "${CMAKE_REQUIRED_LIBRARIES}")
302 303 304 305 306
        endif ()
        if(NOT BLAS_FOUND)
            unset(${_prefix}${_combined_name}_WORKS CACHE)
        endif()
        if (_CHECK_FORTRAN)
307 308 309 310
            if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
                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}")
            endif()
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
            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)
326 327
      set(${LIBRARIES} ${${LIBRARIES}} ${_thread})
    else(_libraries_work)
328
        set(${LIBRARIES} FALSE)
329
    endif(_libraries_work)
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349

# message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")

endmacro(Check_Fortran_Libraries)


set(BLAS_LINKER_FLAGS)
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 ()

#BLAS in intel mkl 10 library? (em64t 64bit)
if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")

350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
    # Looking for include
    # -------------------

    # 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")
    else()
        if (ENV_MKLROOT)
            list(APPEND _inc_env "${ENV_MKLROOT}/include")
        endif()
        # 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}")
        endif()
    endif()
    list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
    list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
    list(REMOVE_DUPLICATES _inc_env)

    # set paths where to look for
    set(PATH_TO_LOOK_FOR "${_inc_env}")

    # 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")
        else()
            set(BLAS_mkl.h_DIRS "BLAS_mkl.h_DIRS-NOTFOUND")
            find_path(BLAS_mkl.h_DIRS
                      NAMES mkl.h
                      HINTS ${PATH_TO_LOOK_FOR})
        endif()
    endif()
    mark_as_advanced(BLAS_mkl.h_DIRS)

    # 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")
        endif()
    endif()

    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}")
434 435
    # libiomp5
    # --------
436 437 438 439 440 441 442
    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 "")
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
    # 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
    if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
        if (OMP_gomp_LIBRARY)
            set(OMP_LIB "${OMP_gomp_LIBRARY}")
        endif()
    else(CMAKE_C_COMPILER_ID STREQUAL "Intel")
        if (OMP_iomp5_LIBRARY)
            set(OMP_LIB "${OMP_iomp5_LIBRARY}")
        endif()
460 461
    endif()

462
    if (UNIX AND NOT WIN32)
Florent Pruvost's avatar
Florent Pruvost committed
463
        # m
464 465 466
        find_library(M_LIBRARY
            NAMES m
            HINTS ${_libdir})
Florent Pruvost's avatar
Florent Pruvost committed
467 468 469 470 471
        if(M_LIBRARY)
            set(LM "-lm")
        else()
            set(LM "")
        endif()
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
        # 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
Florent Pruvost's avatar
Florent Pruvost committed
488
                HINTS ${_libdir}
489 490 491 492 493 494
                )
            mark_as_advanced(FORTRAN_ifcore_LIBRARY)
            if (FORTRAN_ifcore_LIBRARY)
                set(LGFORTRAN "{FORTRAN_ifcore_LIBRARY}")
            endif()
        endif()
495
        set(BLAS_COMPILER_FLAGS "")
496 497 498 499 500 501 502
        if (NOT BLA_VENDOR STREQUAL "Intel10_64lp_seq")
            if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
                list(APPEND BLAS_COMPILER_FLAGS "-openmp")
            endif()
            if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
                list(APPEND BLAS_COMPILER_FLAGS "-fopenmp")
            endif()
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
        endif()
        if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
            if (BLA_VENDOR STREQUAL "Intel10_32")
                #list(APPEND BLAS_COMPILER_FLAGS "-m32")
            else()
                #list(APPEND BLAS_COMPILER_FLAGS "-m64")
            endif()
            if (NOT BLA_VENDOR STREQUAL "Intel10_64lp_seq")
                list(APPEND OMP_LIB "-ldl")
            endif()
        endif()

        set(additional_flags "")
        if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
            set(additional_flags "-Wl,--no-as-needed")
        endif()
519
    endif ()
520

521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 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 578 579 580 581 582 583
    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()

        set(BLAS_SEARCH_LIBS "")

        if(BLA_F95)

            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()

                # 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 ()

                # 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()

                # 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()
                endforeach()
            else (WIN32)
                if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
                    list(APPEND BLAS_SEARCH_LIBS
                    "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
584 585 586 587 588 589 590 591
                    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()
592 593 594 595
                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")
596 597 598
                    if (BLA_VENDOR STREQUAL "Intel10_64lp_seq")
                        set(OMP_LIB "")
                    endif()
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
                endif ()
            endif (WIN32)

        else (BLA_F95)

            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")
                endif()

                # 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}")
                endif()
                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 ()

                # 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()

                # 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()
                endforeach()
            else (WIN32)
                if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
                    list(APPEND BLAS_SEARCH_LIBS
                    "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_intel_lp64 mkl_intel_thread mkl_core guide")
                    # mkl >= 10.3
656 657 658 659 660 661 662 663
                    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()
664 665 666 667
                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")
668 669 670
                    if (BLA_VENDOR STREQUAL "Intel10_64lp_seq")
                        set(OMP_LIB "")
                    endif()
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
                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)

        endif (BLA_F95)

        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}"
695
                "${OMP_LIB};${CMAKE_THREAD_LIBS_INIT};${LM}"
696
                )
697 698 699
                if(_LIBRARIES)
                    set(BLAS_LINKER_FLAGS "${additional_flags}")
                endif()
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
            endif()
        endforeach ()

    endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)

endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")


if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")

    if(NOT BLAS_LIBRARIES)
        # gotoblas (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "goto2"
        ""
        )
    endif()

endif (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")


725
# OpenBlas
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
if (BLA_VENDOR STREQUAL "Open" OR BLA_VENDOR STREQUAL "All")

    if(NOT BLAS_LIBRARIES)
        # openblas (http://www.openblas.net/)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "openblas"
        ""
        )
    endif()

endif (BLA_VENDOR STREQUAL "Open" OR BLA_VENDOR STREQUAL "All")


743 744 745 746 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
# EigenBlas
if (BLA_VENDOR STREQUAL "Eigen" OR BLA_VENDOR STREQUAL "All")

    if(NOT BLAS_LIBRARIES)
        # eigenblas (http://eigen.tuxfamily.org/index.php?title=Main_Page)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "eigen_blas"
        ""
        )
    endif()

    if(NOT BLAS_LIBRARIES)
        # eigenblas (http://eigen.tuxfamily.org/index.php?title=Main_Page)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "eigen_blas_static"
        ""
        )
    endif()

endif (BLA_VENDOR STREQUAL "Eigen" OR BLA_VENDOR STREQUAL "All")


773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")

    if(NOT BLAS_LIBRARIES)
        # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        dgemm
        ""
        "f77blas;atlas"
        ""
        )
    endif()

endif (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")


# BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")

    if(NOT BLAS_LIBRARIES)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "sgemm;dgemm;blas"
        ""
        )
    endif()

endif (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")


# BLAS in Alpha CXML library?
if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")

    if(NOT BLAS_LIBRARIES)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "cxml"
        ""
        )
    endif()

endif (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")


# BLAS in Alpha DXML library? (now called CXML, see above)
if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")

    if(NOT BLAS_LIBRARIES)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "dxml"
        ""
        )
    endif()

endif (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")


# BLAS in Sun Performance library?
if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")

    if(NOT BLAS_LIBRARIES)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        "-xlic_lib=sunperf"
        "sunperf;sunmath"
        ""
        )
        if(BLAS_LIBRARIES)
            set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
        endif()
    endif()

endif ()


# BLAS in SCSL library?  (SGI/Cray Scientific Library)
if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")

    if(NOT BLAS_LIBRARIES)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "scsl"
        ""
        )
    endif()

endif ()


# BLAS in SGIMATH library?
if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")

    if(NOT BLAS_LIBRARIES)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "complib.sgimath"
        ""
        )
    endif()

endif ()


# BLAS in IBM ESSL library? (requires generic BLAS lib, too)
if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")

    if(NOT BLAS_LIBRARIES)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "essl;blas"
        ""
        )
    endif()

endif ()


#BLAS in acml library?
if (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All")

    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)))

        # try to find acml in "standard" paths
        if( WIN32 )
            file( GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt" )
        else()
            file( GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt" )
        endif()
        if( WIN32 )
            file( GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples" )
        else()
            file( GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples" )
        endif()
        list(GET _ACML_ROOT 0 _ACML_ROOT)
        list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)

        if( _ACML_ROOT )

            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()

            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()

        endif(_ACML_ROOT)

    elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)

        set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})

    endif()

    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()

    # 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"
        ""
        )
    endif()

    if(NOT BLAS_LIBRARIES)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "acml_mp;acml_mv"
        ""
        )
    endif()

    if(NOT BLAS_LIBRARIES)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        sgemm
        ""
        "acml;acml_mv;CALBLAS"
        ""
        )
    endif()

endif (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All") # ACML


# Apple BLAS library?
if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")

    if(NOT BLAS_LIBRARIES)
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        dgemm
        ""
        "Accelerate"
        ""
        )
    endif()

endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")


if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")

    if ( NOT BLAS_LIBRARIES )
        check_fortran_libraries(
        BLAS_LIBRARIES
        BLAS
        dgemm
        ""
        "vecLib"
        ""
        )
    endif ()

endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")


# Generic BLAS library?
if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")

1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
    set(BLAS_SEARCH_LIBS "blas;blas_LINUX;blas_MAC;blas_WINDOWS")
    foreach (SEARCH_LIB ${BLAS_SEARCH_LIBS})
        if (BLAS_LIBRARIES)
        else ()
            check_fortran_libraries(
            BLAS_LIBRARIES
            BLAS
            sgemm
            ""
            "${SEARCH_LIB}"
1106
            "${LGFORTRAN}"
1107 1108 1109
            )
        endif()
    endforeach ()
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128

endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")


if(BLA_F95)

    if(BLAS95_LIBRARIES)
       set(BLAS95_FOUND TRUE)
    else()
       set(BLAS95_FOUND FALSE)
    endif()

    if(NOT BLAS_FIND_QUIETLY)
        if(BLAS95_FOUND)
            message(STATUS "A library with BLAS95 API found.")
            message(STATUS "BLAS_LIBRARIES ${BLAS_LIBRARIES}")
        else(BLAS95_FOUND)
            message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but blas 95 libraries could not be found or check of symbols failed."
                        "\nPlease indicate where to find blas libraries. You have three options:\n"
1129
                        "- Option 1: Provide the installation directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
                        "- Option 2: Provide the directory where to find BLAS libraries with cmake option: -DBLAS_LIBDIR=your/path/to/blas/libs\n"
                        "- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
                        "\nTo follow libraries detection more precisely you can activate a verbose mode with -DBLAS_VERBOSE=ON at cmake configure."
                        "\nYou could also specify a BLAS vendor to look for by setting -DBLA_VENDOR=blas_vendor_name."
                        "\nList of possible BLAS vendor: Goto, ATLAS PhiPACK, CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, Intel10_32 (intel mkl v10 32 bit),"
                        "Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model), 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")
            if(BLAS_FIND_REQUIRED)
                message(FATAL_ERROR
                "A required library with BLAS95 API not found. Please specify library location.")
            else()
                message(STATUS
                "A library with BLAS95 API not found. Please specify library location.")
            endif()
        endif(BLAS95_FOUND)
    endif(NOT BLAS_FIND_QUIETLY)

    set(BLAS_FOUND TRUE)
    set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
1149 1150 1151
    if (NOT BLAS_LIBRARIES_DEP)
        set(BLAS_LIBRARIES_DEP "${BLAS95_LIBRARIES}")
    endif()
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167

else(BLA_F95)

    if(BLAS_LIBRARIES)
        set(BLAS_FOUND TRUE)
    else()
        set(BLAS_FOUND FALSE)
    endif()

    if(NOT BLAS_FIND_QUIETLY)
        if(BLAS_FOUND)
            message(STATUS "A library with BLAS API found.")
            message(STATUS "BLAS_LIBRARIES ${BLAS_LIBRARIES}")
        else(BLAS_FOUND)
            message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but blas libraries could not be found or check of symbols failed."
                        "\nPlease indicate where to find blas libraries. You have three options:\n"
1168
                        "- Option 1: Provide the installation directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
                        "- Option 2: Provide the directory where to find BLAS libraries with cmake option: -DBLAS_LIBDIR=your/path/to/blas/libs\n"
                        "- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
                        "\nTo follow libraries detection more precisely you can activate a verbose mode with -DBLAS_VERBOSE=ON at cmake configure."
                        "\nYou could also specify a BLAS vendor to look for by setting -DBLA_VENDOR=blas_vendor_name."
                        "\nList of possible BLAS vendor: Goto, ATLAS PhiPACK, CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, Intel10_32 (intel mkl v10 32 bit),"
                        "Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model), 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")
            if(BLAS_FIND_REQUIRED)
                message(FATAL_ERROR
                    "A required library with BLAS API not found. Please specify library location.")
            else()
                message(STATUS
                    "A library with BLAS API not found. Please specify library location.")
            endif()
        endif(BLAS_FOUND)
    endif(NOT BLAS_FIND_QUIETLY)

endif(BLA_F95)

set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
1189

1190
if (BLAS_FOUND)
1191 1192 1193 1194
    list(GET BLAS_LIBRARIES 0 first_lib)
    get_filename_component(first_lib_path "${first_lib}" PATH)
    if (${first_lib_path} MATCHES "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)")
        string(REGEX REPLACE "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)" "" not_cached_dir "${first_lib_path}")
1195
        set(BLAS_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of BLAS library" FORCE)
1196
    else()
1197
        set(BLAS_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of BLAS library" FORCE)
1198 1199 1200
    endif()
endif()