FindCBLAS.cmake 17.8 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 21 22
# @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
#
###
#
# - Find CBLAS include dirs and libraries
# Use this module by invoking find_package with the form:
#  find_package(CBLAS
#               [REQUIRED] # Fail with error if cblas is not found
#               [COMPONENTS <comp1> <comp2> ...] # dependencies
#              )
#
#  CBLAS depends on the following libraries:
#   - BLAS
#
# This module finds headers and cblas library.
# Results are reported in variables:
23 24 25 26 27 28 29 30 31 32 33 34
#  CBLAS_FOUND             - True if headers and requested libraries were found
#  CBLAS_CFLAGS_OTHER      - cblas compiler flags without headers paths
#  CBLAS_LDFLAGS_OTHER     - cblas linker flags without libraries
#  CBLAS_INCLUDE_DIRS      - cblas include directories
#  CBLAS_LIBRARY_DIRS      - cblas link directories
#  CBLAS_LIBRARIES         - cblas libraries to be linked (absolute path)
#  CBLAS_CFLAGS_OTHER_DEP  - cblas + dependencies compiler flags without headers paths
#  CBLAS_LDFLAGS_OTHER_DEP - cblas + dependencies linker flags without libraries
#  CBLAS_INCLUDE_DIRS_DEP  - cblas + dependencies include directories
#  CBLAS_LIBRARY_DIRS_DEP  - cblas + dependencies link directories
#  CBLAS_LIBRARIES_DEP     - cblas + dependencies libraries
#  CBLAS_HAS_ZGEMM3M       - True if cblas contains zgemm3m fast complex mat-mat product
PRUVOST Florent's avatar
PRUVOST Florent committed
35
#
36 37 38 39 40 41 42 43 44 45 46 47 48 49
#  CBLAS_FOUND_WITH_PKGCONFIG - True if found with pkg-config
#  if found with pkg-config the following variables are set
#  <PREFIX>  = CBLAS
#  <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
50 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
# The user can give specific paths where to find the libraries adding cmake
# options at configure (ex: cmake path/to/project -DCBLAS_DIR=path/to/cblas):
#  CBLAS_DIR              - Where to find the base directory of cblas
#  CBLAS_INCDIR           - Where to find the header files
#  CBLAS_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: CBLAS_DIR, CBLAS_INCDIR, CBLAS_LIBDIR
#
# CBLAS could be directly embedded in BLAS library (ex: Intel MKL) so that
# we test a cblas function with the blas libraries found and set CBLAS
# variables to BLAS ones if test is successful. To skip this feature and
# look for a stand alone cblas, please add the following in your
# CMakeLists.txt before to call find_package(CBLAS):
# set(CBLAS_STANDALONE TRUE)
###
# We handle different modes to find the dependency
#
# - Detection if already installed on the system
#   - CBLAS libraries can be detected from different ways
#     Here is the order of precedence:
#     1) we look in cmake variable CBLAS_LIBDIR or CBLAS_DIR (we guess the libdirs) if defined
#     2) we look in environment variable CBLAS_LIBDIR or CBLAS_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
#

#=============================================================================
79
# Copyright 2012-2018 Inria
PRUVOST Florent's avatar
PRUVOST Florent committed
80 81 82
# Copyright 2012-2013 Emmanuel Agullo
# Copyright 2012-2013 Mathieu Faverge
# Copyright 2012      Cedric Castagnede
83
# Copyright 2013-2018 Florent Pruvost
PRUVOST Florent's avatar
PRUVOST Florent committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file MORSE-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 Morse, substitute the full
#  License text for the above reference.)


if (NOT CBLAS_FOUND)
  set(CBLAS_DIR "" CACHE PATH "Installation directory of CBLAS library")
  if (NOT CBLAS_FIND_QUIETLY)
    message(STATUS "A cache variable, namely CBLAS_DIR, has been set to specify the install directory of CBLAS")
  endif()
endif()


# CBLAS depends on BLAS anyway, try to find it
105 106 107 108
if(CBLAS_FIND_REQUIRED)
  find_package(BLAS REQUIRED)
else()
  find_package(BLAS)
PRUVOST Florent's avatar
PRUVOST Florent committed
109 110 111 112 113 114 115 116 117 118
endif()


# find CBLAS
if (BLAS_FOUND)

  if (NOT CBLAS_STANDALONE)
    # check if a cblas function exists in the BLAS lib
    # this can be the case with libs such as MKL, ACML
    include(CheckFunctionExists)
119 120 121
    set(CMAKE_REQUIRED_LIBRARIES "${BLAS_LDFLAGS_OTHER};${BLAS_LIBRARIES}")
    set(CMAKE_REQUIRED_FLAGS "${BLAS_CFLAGS_OTHER}")
    set(CMAKE_REQUIRED_INCLUDES "${BLAS_INCLUDE_DIRS}")
PRUVOST Florent's avatar
PRUVOST Florent committed
122 123 124 125 126 127 128 129 130 131 132
    unset(CBLAS_WORKS CACHE)
    check_function_exists(cblas_dscal CBLAS_WORKS)
    check_function_exists(cblas_zgemm3m CBLAS_ZGEMM3M_FOUND)
    mark_as_advanced(CBLAS_WORKS)
    set(CMAKE_REQUIRED_LIBRARIES)

    if(CBLAS_WORKS)

      # Check for faster complex GEMM routine
      # (only C/Z, no S/D version)
      if ( CBLAS_ZGEMM3M_FOUND )
133
        add_definitions(-DCBLAS_HAS_ZGEMM3M -DCBLAS_HAS_CGEMM3M)
PRUVOST Florent's avatar
PRUVOST Florent committed
134 135 136
      endif()

      if(NOT CBLAS_FIND_QUIETLY)
137
        message(STATUS "Looking for cblas: test with blas succeeds")
PRUVOST Florent's avatar
PRUVOST Florent committed
138 139 140
      endif()
      # test succeeds: CBLAS is in BLAS
      set(CBLAS_LIBRARIES "${BLAS_LIBRARIES}")
141

PRUVOST Florent's avatar
PRUVOST Florent committed
142
    endif()
143

PRUVOST Florent's avatar
PRUVOST Florent committed
144 145
  endif (NOT CBLAS_STANDALONE)

146
  # test fails with blas: try to find CBLAS lib exterior to BLAS
PRUVOST Florent's avatar
PRUVOST Florent committed
147 148 149 150 151 152
  if (CBLAS_STANDALONE OR NOT CBLAS_WORKS)

    if(NOT CBLAS_WORKS AND NOT CBLAS_FIND_QUIETLY)
      message(STATUS "Looking for cblas : test with blas fails")
    endif()

153
    # try with pkg-config
PRUVOST Florent's avatar
PRUVOST Florent committed
154 155
    set(ENV_CBLAS_DIR "$ENV{CBLAS_DIR}")
    set(ENV_CBLAS_INCDIR "$ENV{CBLAS_INCDIR}")
156 157 158 159 160 161 162 163 164 165
    set(ENV_CBLAS_LIBDIR "$ENV{CBLAS_LIBDIR}")
    set(CBLAS_GIVEN_BY_USER "FALSE")
    if ( CBLAS_DIR OR ( CBLAS_INCDIR AND CBLAS_LIBDIR) OR ENV_CBLAS_DIR OR (ENV_CBLAS_INCDIR AND ENV_CBLAS_LIBDIR) )
      set(CBLAS_GIVEN_BY_USER "TRUE")
    endif()

    include(FindPkgConfig)
    find_package(PkgConfig QUIET)
    if( PKG_CONFIG_EXECUTABLE AND NOT CBLAS_GIVEN_BY_USER)

166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
      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(CBLAS mkl-${MKL_STR_BLA_STATIC}-lp64-iomp)
      elseif(BLA_VENDOR STREQUAL "Intel10_64lp_seq")
        pkg_search_module(CBLAS mkl-${MKL_STR_BLA_STATIC}-lp64-seq)
      elseif(BLA_VENDOR STREQUAL "Open")
        pkg_search_module(CBLAS openblas)
      elseif(BLA_VENDOR STREQUAL "Generic")
        pkg_search_module(CBLAS cblas)
      else()
        pkg_search_module(CBLAS cblas)
        pkg_search_module(CBLAS openblas)
        pkg_search_module(CBLAS mkl-${MKL_STR_BLA_STATIC}-lp64-seq)
      endif()
185 186 187 188 189 190 191 192 193 194 195 196 197 198

      if (NOT CBLAS_FIND_QUIETLY)
        if (CBLAS_FOUND AND CBLAS_LIBRARIES)
          message(STATUS "Looking for CBLAS - found using PkgConfig")
        else()
          message(STATUS "${Magenta}Looking for CBLAS - not found using PkgConfig."
            "\n   Perhaps you should add the directory containing cblas.pc to"
            "\n   the PKG_CONFIG_PATH environment variable.${ColourReset}")
        endif()
      endif()

      if (CBLAS_FOUND AND CBLAS_LIBRARIES)
        set(CBLAS_FOUND_WITH_PKGCONFIG "TRUE")
        find_pkgconfig_libraries_absolute_path(CBLAS)
PRUVOST Florent's avatar
PRUVOST Florent committed
199
      else()
200
        set(CBLAS_FOUND_WITH_PKGCONFIG "FALSE")
PRUVOST Florent's avatar
PRUVOST Florent committed
201
      endif()
202

PRUVOST Florent's avatar
PRUVOST Florent committed
203
    endif()
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222

    if (NOT CBLAS_FOUND_WITH_PKGCONFIG OR CBLAS_GIVEN_BY_USER)
      # Try to find CBLAS lib
      #######################

      # Looking for include
      # -------------------

      # Add system include paths to search include
      # ------------------------------------------
      unset(_inc_env)
      set(ENV_CBLAS_DIR "$ENV{CBLAS_DIR}")
      set(ENV_CBLAS_INCDIR "$ENV{CBLAS_INCDIR}")
      if(ENV_CBLAS_INCDIR)
        list(APPEND _inc_env "${ENV_CBLAS_INCDIR}")
      elseif(ENV_CBLAS_DIR)
        list(APPEND _inc_env "${ENV_CBLAS_DIR}")
        list(APPEND _inc_env "${ENV_CBLAS_DIR}/include")
        list(APPEND _inc_env "${ENV_CBLAS_DIR}/include/cblas")
PRUVOST Florent's avatar
PRUVOST Florent committed
223
      else()
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
        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)


      # Try to find the cblas header in the given paths
      # -------------------------------------------------
      # call cmake macro to find the header path
      if(CBLAS_INCDIR)
247 248 249
        set(CBLAS_cblas.h_DIRS "CBLAS_cblas.h_DIRS-NOTFOUND")
        find_path(CBLAS_cblas.h_DIRS
          NAMES cblas.h
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
          HINTS ${CBLAS_INCDIR})
      else()
        if(CBLAS_DIR)
          set(CBLAS_cblas.h_DIRS "CBLAS_cblas.h_DIRS-NOTFOUND")
          find_path(CBLAS_cblas.h_DIRS
            NAMES cblas.h
            HINTS ${CBLAS_DIR}
            PATH_SUFFIXES "include" "include/cblas")
        else()
          set(CBLAS_cblas.h_DIRS "CBLAS_cblas.h_DIRS-NOTFOUND")
          find_path(CBLAS_cblas.h_DIRS
            NAMES cblas.h
            HINTS ${_inc_env}
            PATH_SUFFIXES "cblas")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
265
      endif()
266 267 268 269 270 271 272 273 274 275 276
      mark_as_advanced(CBLAS_cblas.h_DIRS)

      # If found, add path to cmake variable
      # ------------------------------------
      if (CBLAS_cblas.h_DIRS)
        set(CBLAS_INCLUDE_DIRS "${CBLAS_cblas.h_DIRS}")
      else ()
        set(CBLAS_INCLUDE_DIRS "CBLAS_INCLUDE_DIRS-NOTFOUND")
        if(NOT CBLAS_FIND_QUIETLY)
          message(STATUS "Looking for cblas -- cblas.h not found")
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
277 278 279
      endif()


280 281
      # Looking for lib
      # ---------------
PRUVOST Florent's avatar
PRUVOST Florent committed
282

283 284 285 286 287 288 289 290 291
      # Add system library paths to search lib
      # --------------------------------------
      unset(_lib_env)
      set(ENV_CBLAS_LIBDIR "$ENV{CBLAS_LIBDIR}")
      if(ENV_CBLAS_LIBDIR)
        list(APPEND _lib_env "${ENV_CBLAS_LIBDIR}")
      elseif(ENV_CBLAS_DIR)
        list(APPEND _lib_env "${ENV_CBLAS_DIR}")
        list(APPEND _lib_env "${ENV_CBLAS_DIR}/lib")
PRUVOST Florent's avatar
PRUVOST Florent committed
292
      else()
293 294
        if(WIN32)
          string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
295
        else()
296 297 298 299 300 301 302
          if(APPLE)
            string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
          else()
            string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
          endif()
          list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
          list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
303
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
304
      endif()
305
      list(REMOVE_DUPLICATES _lib_env)
PRUVOST Florent's avatar
PRUVOST Florent committed
306

307 308
      # Try to find the cblas lib in the given paths
      # ----------------------------------------------
PRUVOST Florent's avatar
PRUVOST Florent committed
309

310 311
      # call cmake macro to find the lib path
      if(CBLAS_LIBDIR)
312 313 314
        set(CBLAS_cblas_LIBRARY "CBLAS_cblas_LIBRARY-NOTFOUND")
        find_library(CBLAS_cblas_LIBRARY
          NAMES cblas
315
          HINTS ${CBLAS_LIBDIR})
PRUVOST Florent's avatar
PRUVOST Florent committed
316
      else()
317 318 319 320 321 322 323 324 325 326 327 328
        if(CBLAS_DIR)
          set(CBLAS_cblas_LIBRARY "CBLAS_cblas_LIBRARY-NOTFOUND")
          find_library(CBLAS_cblas_LIBRARY
            NAMES cblas
            HINTS ${CBLAS_DIR}
            PATH_SUFFIXES lib lib32 lib64)
        else()
          set(CBLAS_cblas_LIBRARY "CBLAS_cblas_LIBRARY-NOTFOUND")
          find_library(CBLAS_cblas_LIBRARY
            NAMES cblas
            HINTS ${_lib_env})
        endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
329
      endif()
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
      mark_as_advanced(CBLAS_cblas_LIBRARY)

      # If found, add path to cmake variable
      # ------------------------------------
      if (CBLAS_cblas_LIBRARY)
        get_filename_component(cblas_lib_path "${CBLAS_cblas_LIBRARY}" PATH)
        # set cmake variables
        set(CBLAS_LIBRARIES    "${CBLAS_cblas_LIBRARY}")
        set(CBLAS_LIBRARY_DIRS "${cblas_lib_path}")
      else ()
        set(CBLAS_LIBRARIES    "CBLAS_LIBRARIES-NOTFOUND")
        set(CBLAS_LIBRARY_DIRS "CBLAS_LIBRARY_DIRS-NOTFOUND")
        if (NOT CBLAS_FIND_QUIETLY)
          message(STATUS "Looking for cblas -- lib cblas not found")
        endif()
      endif ()
    endif (NOT CBLAS_FOUND_WITH_PKGCONFIG OR CBLAS_GIVEN_BY_USER)
PRUVOST Florent's avatar
PRUVOST Florent committed
347

348
  endif (CBLAS_STANDALONE OR NOT CBLAS_WORKS)
PRUVOST Florent's avatar
PRUVOST Florent committed
349

350 351
  # check a function to validate the find
  if(CBLAS_LIBRARIES)
PRUVOST Florent's avatar
PRUVOST Florent committed
352

353
    set(REQUIRED_INCDIRS)
354
    set(REQUIRED_FLAGS)
355 356 357
    set(REQUIRED_LDFLAGS)
    set(REQUIRED_LIBDIRS)
    set(REQUIRED_LIBS)
PRUVOST Florent's avatar
PRUVOST Florent committed
358

359 360 361 362 363
    # CBLAS
    if (CBLAS_INCLUDE_DIRS)
      set(REQUIRED_INCDIRS "${CBLAS_INCLUDE_DIRS}")
    endif()
    if (CBLAS_CFLAGS_OTHER)
364
      set(REQUIRED_FLAGS "${CBLAS_CFLAGS_OTHER}")
365 366
    endif()
    if (CBLAS_LDFLAGS_OTHER)
367
      set(REQUIRED_LDFLAGS "${CBLAS_LDFLAGS_OTHER}")
368 369 370 371 372 373 374 375 376
    endif()
    if (CBLAS_LIBRARY_DIRS)
      set(REQUIRED_LIBDIRS "${CBLAS_LIBRARY_DIRS}")
    endif()
    set(REQUIRED_LIBS "${CBLAS_LIBRARIES}")
    # BLAS
    if (BLAS_INCLUDE_DIRS)
      list(APPEND REQUIRED_INCDIRS "${BLAS_INCLUDE_DIRS}")
    endif()
377 378
    if (BLAS_CFLAGS_OTHER)
      list(APPEND REQUIRED_FLAGS "${BLAS_CFLAGS_OTHER}")
379
    endif()
380 381
    if (BLAS_LDFLAGS_OTHER)
      list(APPEND REQUIRED_LDFLAGS "${BLAS_LDFLAGS_OTHER}")
382 383 384 385 386
    endif()
    if (BLAS_LIBRARY_DIRS)
      list(APPEND REQUIRED_LIBDIRS "${BLAS_LIBRARY_DIRS}")
    endif()
    list(APPEND REQUIRED_LIBS "${BLAS_LIBRARIES}")
387

388 389
    # set required libraries for link
    set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
390 391 392 393 394 395 396 397 398 399 400 401 402
    if (REQUIRED_FLAGS)
      set(REQUIRED_FLAGS_COPY "${REQUIRED_FLAGS}")
      set(REQUIRED_FLAGS)
      set(REQUIRED_DEFINITIONS)
      foreach(_flag ${REQUIRED_FLAGS_COPY})
        if (_flag MATCHES "^-D")
         list(APPEND REQUIRED_DEFINITIONS "${_flag}")
        endif()
        string(REGEX REPLACE "^-D.*" "" _flag "${_flag}")
        list(APPEND REQUIRED_FLAGS "${_flag}")
      endforeach()
    endif()
    set(CMAKE_REQUIRED_DEFINITIONS "${REQUIRED_DEFINITIONS}")
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
    set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}")
    set(CMAKE_REQUIRED_LIBRARIES)
    list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LDFLAGS}")
    list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
    string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")

    # test link
    unset(CBLAS_WORKS CACHE)
    include(CheckFunctionExists)
    check_function_exists(cblas_dscal CBLAS_WORKS)
    mark_as_advanced(CBLAS_WORKS)

    if(CBLAS_WORKS)

      # Check for faster complex GEMM routine
      # (only C/Z, no S/D version)
      check_function_exists(cblas_zgemm3m CBLAS_ZGEMM3M_FOUND)
      if ( CBLAS_ZGEMM3M_FOUND )
        add_definitions(-DCBLAS_HAS_ZGEMM3M -DCBLAS_HAS_CGEMM3M)
PRUVOST Florent's avatar
PRUVOST Florent committed
422 423
      endif()

424 425 426 427
      # save link with dependencies
      set(CBLAS_LIBRARIES_DEP "${REQUIRED_LIBS}")
      set(CBLAS_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
      set(CBLAS_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
428 429
      set(CBLAS_CFLAGS_OTHER_DEP "${REQUIRED_FLAGS}")
      set(CBLAS_LDFLAGS_OTHER_DEP "${REQUIRED_LDFLAGS}")
430
      list(REMOVE_DUPLICATES CBLAS_LIBRARY_DIRS_DEP)
431 432
      list(REMOVE_DUPLICATES CBLAS_CFLAGS_OTHER_DEP)
      list(REMOVE_DUPLICATES CBLAS_LDFLAGS_OTHER_DEP)
433 434 435 436 437
    else()
      if(NOT CBLAS_FIND_QUIETLY)
        message(STATUS "Looking for cblas : test of cblas_dscal with cblas and blas libraries fails")
        message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
        message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}")
438
        message(STATUS "CMAKE_REQUIRED_FLAGS: ${CMAKE_REQUIRED_FLAGS}")
439 440 441 442 443 444 445
        message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails")
      endif()
    endif()
    set(CMAKE_REQUIRED_INCLUDES)
    set(CMAKE_REQUIRED_FLAGS)
    set(CMAKE_REQUIRED_LIBRARIES)
  endif(CBLAS_LIBRARIES)
PRUVOST Florent's avatar
PRUVOST Florent committed
446 447 448 449 450 451 452 453 454 455 456 457 458

else(BLAS_FOUND)

  if (NOT CBLAS_FIND_QUIETLY)
    message(STATUS "CBLAS requires BLAS but BLAS has not been found."
      "Please look for BLAS first.")
  endif()

endif(BLAS_FOUND)

if (CBLAS_LIBRARIES)
  list(GET CBLAS_LIBRARIES 0 first_lib)
  get_filename_component(first_lib_path "${first_lib}" PATH)
459 460 461
  if (NOT CBLAS_LIBRARY_DIRS)
    set(CBLAS_LIBRARY_DIRS "${first_lib_path}")
  endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
  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}")
    set(CBLAS_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of CBLAS library" FORCE)
  else()
    set(CBLAS_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of CBLAS library" FORCE)
  endif()
endif()
mark_as_advanced(CBLAS_DIR)
mark_as_advanced(CBLAS_DIR_FOUND)

# check that CBLAS has been found
# -------------------------------
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CBLAS DEFAULT_MSG
  CBLAS_LIBRARIES
  CBLAS_WORKS)