FindMAGMA.cmake 15.7 KB
Newer Older
1
###
2 3
# WARNING: not maintained anymore
###
4 5 6 7
#
# @copyright (c) 2009-2014 The University of Tennessee and The University
#                          of Tennessee Research Foundation.
#                          All rights reserved.
8
# @copyright (c) 2012-2016 Inria. All rights reserved.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
# @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
#
###
#
# - Find MAGMA include dirs and libraries
# Use this module by invoking find_package with the form:
#  find_package(MAGMA
#               [REQUIRED]             # Fail with error if magma is not found
#               [COMPONENTS <comp1> <comp2> ...] # dependencies
#              )
#
#  MAGMA depends on the following libraries:
#   - CUDA/cuBLAS
#   - LAPACK
#   - CBLAS
#
#  COMPONENTS are optional libraries MAGMA could be linked with,
#  Use it to drive detection of a specific compilation chain
#  COMPONENTS can be some of the following:
#   - no components are available for now: maybe PLASMA in the future?
#
# Results are reported in variables:
#  MAGMA_FOUND            - True if headers and requested libraries were found
32
#  MAGMA_C_FLAGS          - list of required compilation flags (excluding -I)
33
#  MAGMA_LINKER_FLAGS     - list of required linker flags (excluding -l and -L)
34 35 36 37 38 39 40 41 42 43 44 45
#  MAGMA_INCLUDE_DIRS     - magma include directories
#  MAGMA_LIBRARY_DIRS     - Link directories for magma libraries
#  MAGMA_LIBRARIES        - magma libraries
#  MAGMA_INCLUDE_DIRS_DEP - magma + dependencies include directories
#  MAGMA_LIBRARY_DIRS_DEP - magma + dependencies link directories
#  MAGMA_LIBRARIES_DEP    - magma libraries + dependencies
#
# The user can give specific paths where to find the libraries adding cmake
# options at configure (ex: cmake path/to/project -DMAGMA_DIR=path/to/magma):
#  MAGMA_DIR              - Where to find the base directory of magma
#  MAGMA_INCDIR           - Where to find the header files
#  MAGMA_LIBDIR           - Where to find the library files
46 47
# The module can also look for the following environment variables if paths
# are not given as cmake variable: MAGMA_DIR, MAGMA_INCDIR, MAGMA_LIBDIR
48 49 50 51 52 53
#
#=============================================================================
# Copyright 2012-2013 Inria
# Copyright 2012-2013 Emmanuel Agullo
# Copyright 2012-2013 Mathieu Faverge
# Copyright 2012      Cedric Castagnede
54
# Copyright 2013-2016 Florent Pruvost
55 56 57 58 59 60 61 62 63 64 65 66 67
#
# 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 MAGMA_FOUND)
PRUVOST Florent's avatar
PRUVOST Florent committed
68 69 70 71
  set(MAGMA_DIR "" CACHE PATH "Installation directory of MAGMA library")
  if (NOT MAGMA_FIND_QUIETLY)
    message(STATUS "A cache variable, namely MAGMA_DIR, has been set to specify the install directory of MAGMA")
  endif()
72 73 74 75
endif(NOT MAGMA_FOUND)

# MAGMA depends on CUDA anyway, try to find it
if (NOT CUDA_FOUND)
PRUVOST Florent's avatar
PRUVOST Florent committed
76 77 78 79 80
  if(MAGMA_FIND_REQUIRED)
    find_package(CUDA REQUIRED)
  else()
    find_package(CUDA)
  endif()
81 82 83
endif()
# MAGMA depends on cuBLAS which should come with CUDA, if not found -> error
if (NOT CUDA_CUBLAS_LIBRARIES)
PRUVOST Florent's avatar
PRUVOST Florent committed
84 85 86 87
  if(MAGMA_FIND_REQUIRED)
    message(FATAL_ERROR "Looking for MAGMA - MAGMA depends on cuBLAS which has "
      "not been found (should come with cuda install)")
  endif()
88 89 90
endif()
# MAGMA depends on LAPACK anyway, try to find it
if (NOT LAPACK_FOUND)
PRUVOST Florent's avatar
PRUVOST Florent committed
91 92 93 94 95
  if(MAGMA_FIND_REQUIRED)
    find_package(LAPACKEXT REQUIRED)
  else()
    find_package(LAPACKEXT)
  endif()
96 97 98
endif()
# MAGMA depends on CBLAS anyway, try to find it
if (NOT CBLAS_FOUND)
PRUVOST Florent's avatar
PRUVOST Florent committed
99 100 101 102 103
  if(MAGMA_FIND_REQUIRED)
    find_package(CBLAS REQUIRED)
  else()
    find_package(CBLAS)
  endif()
104 105
endif()

106 107 108 109 110
set(ENV_MAGMA_DIR "$ENV{MAGMA_DIR}")
set(ENV_MAGMA_INCDIR "$ENV{MAGMA_INCDIR}")
set(ENV_MAGMA_LIBDIR "$ENV{MAGMA_LIBDIR}")
set(MAGMA_GIVEN_BY_USER "FALSE")
if ( MAGMA_DIR OR ( MAGMA_INCDIR AND MAGMA_LIBDIR) OR ENV_MAGMA_DIR OR (ENV_MAGMA_INCDIR AND ENV_MAGMA_LIBDIR) )
PRUVOST Florent's avatar
PRUVOST Florent committed
111
  set(MAGMA_GIVEN_BY_USER "TRUE")
112 113
endif()

114 115 116 117
# Optionally use pkg-config to detect include/library dirs (if pkg-config is available)
# -------------------------------------------------------------------------------------
include(FindPkgConfig)
find_package(PkgConfig QUIET)
118
if(PKG_CONFIG_EXECUTABLE AND NOT MAGMA_GIVEN_BY_USER)
119

PRUVOST Florent's avatar
PRUVOST Florent committed
120 121 122 123 124 125 126 127 128 129 130
  pkg_search_module(MAGMA magma)
  if (NOT MAGMA_FIND_QUIETLY)
    if (MAGMA_FOUND AND MAGMA_LIBRARIES)
      message(STATUS "Looking for MAGMA - found using PkgConfig")
      #if(NOT MAGMA_INCLUDE_DIRS)
      #    message("${Magenta}MAGMA_INCLUDE_DIRS is empty using PkgConfig."
      #        "Perhaps the path to magma headers is already present in your"
      #        "C(PLUS)_INCLUDE_PATH environment variable.${ColourReset}")
      #endif()
    else()
      message(STATUS "${Magenta}Looking for MAGMA - not found using PkgConfig. "
131 132
        "\n   Perhaps you should add the directory containing magma.pc "
        "\n   to the PKG_CONFIG_PATH environment variable.${ColourReset}")
133
    endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
134
  endif()
135

PRUVOST Florent's avatar
PRUVOST Florent committed
136 137
  if (MAGMA_FIND_VERSION_EXACT)
    if( NOT (MAGMA_FIND_VERSION_MAJOR STREQUAL MAGMA_VERSION_MAJOR) OR
138
        NOT (MAGMA_FIND_VERSION_MINOR STREQUAL MAGMA_VERSION_MINOR) )
PRUVOST Florent's avatar
PRUVOST Florent committed
139
      if(NOT MAGMA_FIND_QUIETLY)
140 141 142
        message(FATAL_ERROR
          "MAGMA version found is ${MAGMA_VERSION_STRING} "
          "when required is ${MAGMA_FIND_VERSION}")
PRUVOST Florent's avatar
PRUVOST Florent committed
143
      endif()
144
    endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
145 146 147
  else()
    # if the version found is older than the required then error
    if( (MAGMA_FIND_VERSION_MAJOR STRGREATER MAGMA_VERSION_MAJOR) OR
148
        (MAGMA_FIND_VERSION_MINOR STRGREATER MAGMA_VERSION_MINOR) )
PRUVOST Florent's avatar
PRUVOST Florent committed
149
      if(NOT MAGMA_FIND_QUIETLY)
150 151 152
        message(FATAL_ERROR
          "MAGMA version found is ${MAGMA_VERSION_STRING} "
          "when required is ${MAGMA_FIND_VERSION} or newer")
PRUVOST Florent's avatar
PRUVOST Florent committed
153 154 155
      endif()
    endif()
  endif()
156

PRUVOST Florent's avatar
PRUVOST Florent committed
157 158 159 160 161 162 163 164
  # if pkg-config is used: these variables are empty
  # the pkg_search_module call will set the following:
  # MAGMA_LDFLAGS: all required linker flags
  # MAGMA_CFLAGS:  all required cflags
  set(MAGMA_INCLUDE_DIRS_DEP "")
  set(MAGMA_LIBRARY_DIRS_DEP "")
  set(MAGMA_LIBRARIES_DEP "")
  # replace it anyway: we should update it with dependencies given by pkg-config
165 166 167 168
  set(MAGMA_INCLUDE_DIRS_DEP "${MAGMA_STATIC_INCLUDE_DIRS}")
  set(MAGMA_LIBRARY_DIRS_DEP "${MAGMA_STATIC_LIBRARY_DIRS}")
  set(MAGMA_LIBRARIES_DEP "${MAGMA_STATIC_LIBRARIES}")
  set(MAGMA_C_FLAGS "${MAGMA_CFLAGS_OTHER}")
169

170
endif(PKG_CONFIG_EXECUTABLE AND NOT MAGMA_GIVEN_BY_USER)
171 172

# if MAGMA is not found using pkg-config
173
if( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT MAGMA_FOUND) OR (MAGMA_GIVEN_BY_USER) )
174

PRUVOST Florent's avatar
PRUVOST Florent committed
175 176 177
  if (NOT MAGMA_FIND_QUIETLY)
    message(STATUS "Looking for MAGMA - PkgConfig not used")
  endif()
178

PRUVOST Florent's avatar
PRUVOST Florent committed
179 180
  # Looking for include
  # -------------------
181

PRUVOST Florent's avatar
PRUVOST Florent committed
182 183 184 185 186 187 188 189 190 191 192 193 194 195
  # Add system include paths to search include
  # ------------------------------------------
  unset(_inc_env)
  set(ENV_MAGMA_DIR "$ENV{MAGMA_DIR}")
  set(ENV_MAGMA_INCDIR "$ENV{MAGMA_INCDIR}")
  if(ENV_MAGMA_INCDIR)
    list(APPEND _inc_env "${ENV_MAGMA_INCDIR}")
  elseif(ENV_MAGMA_DIR)
    list(APPEND _inc_env "${ENV_MAGMA_DIR}")
    list(APPEND _inc_env "${ENV_MAGMA_DIR}/include")
    list(APPEND _inc_env "${ENV_MAGMA_DIR}/include/magma")
  else()
    if(WIN32)
      string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
196
    else()
PRUVOST Florent's avatar
PRUVOST Florent committed
197 198 199 200 201 202 203 204
      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}")
205
    endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
206 207 208 209
  endif()
  list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
  list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
  list(REMOVE_DUPLICATES _inc_env)
210 211


PRUVOST Florent's avatar
PRUVOST Florent committed
212 213 214 215 216 217 218 219 220 221 222 223
  # Try to find the magma header in the given paths
  # -------------------------------------------------
  # call cmake macro to find the header path
  if(MAGMA_INCDIR)
    set(MAGMA_magma.h_DIRS "MAGMA_magma.h_DIRS-NOTFOUND")
    find_path(MAGMA_magma.h_DIRS
      NAMES magma.h
      HINTS ${MAGMA_INCDIR})
  else()
    if(MAGMA_DIR)
      set(MAGMA_magma.h_DIRS "MAGMA_magma.h_DIRS-NOTFOUND")
      find_path(MAGMA_magma.h_DIRS
224 225 226
        NAMES magma.h
        HINTS ${MAGMA_DIR}
        PATH_SUFFIXES "include" "include/magma")
227
    else()
PRUVOST Florent's avatar
PRUVOST Florent committed
228 229
      set(MAGMA_magma.h_DIRS "MAGMA_magma.h_DIRS-NOTFOUND")
      find_path(MAGMA_magma.h_DIRS
230 231
        NAMES magma.h
        HINTS ${_inc_env})
232
    endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
233 234
  endif()
  mark_as_advanced(MAGMA_magma.h_DIRS)
235

PRUVOST Florent's avatar
PRUVOST Florent committed
236 237 238 239 240 241 242 243
  # If found, add path to cmake variable
  # ------------------------------------
  if (MAGMA_magma.h_DIRS)
    set(MAGMA_INCLUDE_DIRS "${MAGMA_magma.h_DIRS}")
  else ()
    set(MAGMA_INCLUDE_DIRS "MAGMA_INCLUDE_DIRS-NOTFOUND")
    if(NOT MAGMA_FIND_QUIETLY)
      message(STATUS "Looking for magma -- magma.h not found")
244
    endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
245
  endif()
246 247


PRUVOST Florent's avatar
PRUVOST Florent committed
248 249
  # Looking for lib
  # ---------------
250

PRUVOST Florent's avatar
PRUVOST Florent committed
251 252 253 254 255 256 257 258 259 260 261 262
  # Add system library paths to search lib
  # --------------------------------------
  unset(_lib_env)
  set(ENV_MAGMA_LIBDIR "$ENV{MAGMA_LIBDIR}")
  if(ENV_MAGMA_LIBDIR)
    list(APPEND _lib_env "${ENV_MAGMA_LIBDIR}")
  elseif(ENV_MAGMA_DIR)
    list(APPEND _lib_env "${ENV_MAGMA_DIR}")
    list(APPEND _lib_env "${ENV_MAGMA_DIR}/lib")
  else()
    if(WIN32)
      string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
263
    else()
PRUVOST Florent's avatar
PRUVOST Florent committed
264
      if(APPLE)
265
        string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
PRUVOST Florent's avatar
PRUVOST Florent committed
266
      else()
267
        string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
PRUVOST Florent's avatar
PRUVOST Florent committed
268 269 270
      endif()
      list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
      list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
271
    endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
272 273
  endif()
  list(REMOVE_DUPLICATES _lib_env)
274

PRUVOST Florent's avatar
PRUVOST Florent committed
275 276
  # Try to find the magma lib in the given paths
  # ----------------------------------------------
277

PRUVOST Florent's avatar
PRUVOST Florent committed
278 279 280 281 282 283 284 285 286 287
  # call cmake macro to find the lib path
  if(MAGMA_LIBDIR)
    set(MAGMA_magma_LIBRARY "MAGMA_magma_LIBRARY-NOTFOUND")
    find_library(MAGMA_magma_LIBRARY
      NAMES magma
      HINTS ${MAGMA_LIBDIR})
  else()
    if(MAGMA_DIR)
      set(MAGMA_magma_LIBRARY "MAGMA_magma_LIBRARY-NOTFOUND")
      find_library(MAGMA_magma_LIBRARY
288 289 290
        NAMES magma
        HINTS ${MAGMA_DIR}
        PATH_SUFFIXES lib lib32 lib64)
291
    else()
PRUVOST Florent's avatar
PRUVOST Florent committed
292 293
      set(MAGMA_magma_LIBRARY "MAGMA_magma_LIBRARY-NOTFOUND")
      find_library(MAGMA_magma_LIBRARY
294 295
        NAMES magma
        HINTS ${_lib_env})
296
    endif()
PRUVOST Florent's avatar
PRUVOST Florent committed
297 298
  endif()
  mark_as_advanced(MAGMA_magma_LIBRARY)
299

PRUVOST Florent's avatar
PRUVOST Florent committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313
  # If found, add path to cmake variable
  # ------------------------------------
  if (MAGMA_magma_LIBRARY)
    get_filename_component(magma_lib_path "${MAGMA_magma_LIBRARY}" PATH)
    # set cmake variables
    set(MAGMA_LIBRARIES    "${MAGMA_magma_LIBRARY}")
    set(MAGMA_LIBRARY_DIRS "${magma_lib_path}")
  else ()
    set(MAGMA_LIBRARIES    "MAGMA_LIBRARIES-NOTFOUND")
    set(MAGMA_LIBRARY_DIRS "MAGMA_LIBRARY_DIRS-NOTFOUND")
    if(NOT MAGMA_FIND_QUIETLY)
      message(STATUS "Looking for magma -- lib magma not found")
    endif()
  endif ()
314

PRUVOST Florent's avatar
PRUVOST Florent committed
315 316
  # check a function to validate the find
  if (MAGMA_LIBRARIES)
317

PRUVOST Florent's avatar
PRUVOST Florent committed
318 319 320 321
    set(REQUIRED_LDFLAGS)
    set(REQUIRED_INCDIRS)
    set(REQUIRED_LIBDIRS)
    set(REQUIRED_LIBS)
322

PRUVOST Florent's avatar
PRUVOST Florent committed
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
    # MAGMA
    if (MAGMA_INCLUDE_DIRS)
      set(REQUIRED_INCDIRS "${MAGMA_INCLUDE_DIRS}")
    endif()
    if (MAGMA_LIBRARY_DIRS)
      set(REQUIRED_LIBDIRS "${MAGMA_LIBRARY_DIRS}")
    endif()
    set(REQUIRED_LIBS "${MAGMA_LIBRARIES}")
    # CBLAS
    if (CBLAS_INCLUDE_DIRS_DEP)
      list(APPEND REQUIRED_INCDIRS "${CBLAS_INCLUDE_DIRS_DEP}")
    elseif (CBLAS_INCLUDE_DIRS)
      list(APPEND REQUIRED_INCDIRS "${CBLAS_INCLUDE_DIRS}")
    endif()
    if(CBLAS_LIBRARY_DIRS_DEP)
      list(APPEND REQUIRED_LIBDIRS "${CBLAS_LIBRARY_DIRS_DEP}")
    elseif(CBLAS_LIBRARY_DIRS)
      list(APPEND REQUIRED_LIBDIRS "${CBLAS_LIBRARY_DIRS}")
    endif()
    if (CBLAS_LIBRARIES_DEP)
      list(APPEND REQUIRED_LIBS "${CBLAS_LIBRARIES_DEP}")
    elseif(CBLAS_LIBRARIES)
      list(APPEND REQUIRED_LIBS "${CBLAS_LIBRARIES}")
    endif()
    if (BLAS_LINKER_FLAGS)
      list(APPEND REQUIRED_LDFLAGS "${BLAS_LINKER_FLAGS}")
    endif()
    # LAPACK
    if (LAPACK_INCLUDE_DIRS)
      list(APPEND REQUIRED_INCDIRS "${LAPACK_INCLUDE_DIRS}")
    endif()
    if(LAPACK_LIBRARY_DIRS)
      list(APPEND REQUIRED_LIBDIRS "${LAPACK_LIBRARY_DIRS}")
    endif()
    list(APPEND REQUIRED_LIBS "${LAPACK_LIBRARIES}")
    if (LAPACK_LINKER_FLAGS)
      list(APPEND REQUIRED_LDFLAGS "${LAPACK_LINKER_FLAGS}")
    endif()
    # CUDA
    if (CUDA_INCLUDE_DIRS)
      list(APPEND REQUIRED_INCDIRS "${CUDA_INCLUDE_DIRS}")
    endif()
    if(CUDA_LIBRARY_DIRS)
      list(APPEND REQUIRED_LIBDIRS "${CUDA_LIBRARY_DIRS}")
    endif()
    list(APPEND REQUIRED_LIBS "${CUDA_CUBLAS_LIBRARIES};${CUDA_LIBRARIES}")
369

PRUVOST Florent's avatar
PRUVOST Florent committed
370 371 372 373 374 375 376 377 378
    # set required libraries for link
    set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
    set(CMAKE_REQUIRED_LIBRARIES)
    list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LDFLAGS}")
    foreach(lib_dir ${REQUIRED_LIBDIRS})
      list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
    endforeach()
    list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
    string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
379

PRUVOST Florent's avatar
PRUVOST Florent committed
380 381 382 383 384
    # test link
    unset(MAGMA_WORKS CACHE)
    include(CheckFunctionExists)
    check_function_exists(magma_dgetrf MAGMA_WORKS)
    mark_as_advanced(MAGMA_WORKS)
385

PRUVOST Florent's avatar
PRUVOST Florent committed
386 387 388 389 390 391 392 393 394 395 396
    if(MAGMA_WORKS)
      # save link with dependencies
      set(MAGMA_LIBRARIES_DEP    "${REQUIRED_LIBS}")
      set(MAGMA_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
      set(MAGMA_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
      set(MAGMA_LINKER_FLAGS     "${REQUIRED_LDFLAGS}")
      list(REMOVE_DUPLICATES MAGMA_LIBRARY_DIRS_DEP)
      list(REMOVE_DUPLICATES MAGMA_INCLUDE_DIRS_DEP)
      list(REMOVE_DUPLICATES MAGMA_LINKER_FLAGS)
    else()
      if(NOT MAGMA_FIND_QUIETLY)
397 398 399 400 401
        message(STATUS "Looking for magma : test of magma_dgetrf with
                magma, cblas, cuda and lapack libraries fails")
        message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
        message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}")
        message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails")
PRUVOST Florent's avatar
PRUVOST Florent committed
402 403 404 405 406 407
      endif()
    endif()
    set(CMAKE_REQUIRED_INCLUDES)
    set(CMAKE_REQUIRED_FLAGS)
    set(CMAKE_REQUIRED_LIBRARIES)
  endif(MAGMA_LIBRARIES)
408

409
endif( (NOT PKG_CONFIG_EXECUTABLE) OR (PKG_CONFIG_EXECUTABLE AND NOT MAGMA_FOUND) OR (MAGMA_GIVEN_BY_USER) )
410

411
if (MAGMA_LIBRARIES)
PRUVOST Florent's avatar
PRUVOST Florent committed
412 413 414
  if (MAGMA_LIBRARY_DIRS)
    foreach(dir ${MAGMA_LIBRARY_DIRS})
      if ("${dir}" MATCHES "magma")
415
        set(first_lib_path "${dir}")
PRUVOST Florent's avatar
PRUVOST Florent committed
416 417 418 419 420
      endif()
    endforeach()
  else()
    list(GET MAGMA_LIBRARIES 0 first_lib)
    get_filename_component(first_lib_path "${first_lib}" PATH)
421
    set(MAGMA_LIBRARY_DIRS "${first_lib_path}")
PRUVOST Florent's avatar
PRUVOST Florent committed
422 423 424 425 426 427 428
  endif()
  if (${first_lib_path} MATCHES "/lib(32|64)?$")
    string(REGEX REPLACE "/lib(32|64)?$" "" not_cached_dir "${first_lib_path}")
    set(MAGMA_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of MAGMA library" FORCE)
  else()
    set(MAGMA_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of MAGMA library" FORCE)
  endif()
429
endif()
430 431
mark_as_advanced(MAGMA_DIR)
mark_as_advanced(MAGMA_DIR_FOUND)
432 433 434 435 436

# check that MAGMA has been found
# -------------------------------
include(FindPackageHandleStandardArgs)
if (PKG_CONFIG_EXECUTABLE AND MAGMA_FOUND)
PRUVOST Florent's avatar
PRUVOST Florent committed
437 438
  find_package_handle_standard_args(MAGMA DEFAULT_MSG
    MAGMA_LIBRARIES)
439
else()
PRUVOST Florent's avatar
PRUVOST Florent committed
440 441 442
  find_package_handle_standard_args(MAGMA DEFAULT_MSG
    MAGMA_LIBRARIES
    MAGMA_WORKS)
443
endif()