Home | History | Annotate | Download | only in cmake
      1 ###
      2 #
      3 # @copyright (c) 2009-2014 The University of Tennessee and The University
      4 #                          of Tennessee Research Foundation.
      5 #                          All rights reserved.
      6 # @copyright (c) 2012-2014 Inria. All rights reserved.
      7 # @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
      8 #
      9 ###
     10 #
     11 # - Find PASTIX include dirs and libraries
     12 # Use this module by invoking find_package with the form:
     13 #  find_package(PASTIX
     14 #               [REQUIRED] # Fail with error if pastix is not found
     15 #               [COMPONENTS <comp1> <comp2> ...] # dependencies
     16 #              )
     17 #
     18 #  PASTIX depends on the following libraries:
     19 #   - Threads, m, rt
     20 #   - MPI
     21 #   - HWLOC
     22 #   - BLAS
     23 #
     24 #  COMPONENTS are optional libraries PASTIX could be linked with,
     25 #  Use it to drive detection of a specific compilation chain
     26 #  COMPONENTS can be some of the following:
     27 #   - MPI: to activate detection of the parallel MPI version (default)
     28 #        it looks for Threads, HWLOC, BLAS, MPI and ScaLAPACK libraries
     29 #   - SEQ: to activate detection of the sequential version (exclude MPI version)
     30 #   - STARPU: to activate detection of StarPU version
     31 #   it looks for MPI version of StarPU (default behaviour)
     32 #   if SEQ and STARPU are given, it looks for a StarPU without MPI
     33 #   - STARPU_CUDA: to activate detection of StarPU with CUDA
     34 #   - STARPU_FXT: to activate detection of StarPU with FxT
     35 #   - SCOTCH: to activate detection of PASTIX linked with SCOTCH
     36 #   - PTSCOTCH: to activate detection of PASTIX linked with SCOTCH
     37 #   - METIS: to activate detection of PASTIX linked with SCOTCH
     38 #
     39 # This module finds headers and pastix library.
     40 # Results are reported in variables:
     41 #  PASTIX_FOUND            - True if headers and requested libraries were found
     42 #  PASTIX_LINKER_FLAGS     - list of required linker flags (excluding -l and -L)
     43 #  PASTIX_INCLUDE_DIRS     - pastix include directories
     44 #  PASTIX_LIBRARY_DIRS     - Link directories for pastix libraries
     45 #  PASTIX_LIBRARIES        - pastix libraries
     46 #  PASTIX_INCLUDE_DIRS_DEP - pastix + dependencies include directories
     47 #  PASTIX_LIBRARY_DIRS_DEP - pastix + dependencies link directories
     48 #  PASTIX_LIBRARIES_DEP    - pastix libraries + dependencies
     49 #
     50 # The user can give specific paths where to find the libraries adding cmake
     51 # options at configure (ex: cmake path/to/project -DPASTIX_DIR=path/to/pastix):
     52 #  PASTIX_DIR              - Where to find the base directory of pastix
     53 #  PASTIX_INCDIR           - Where to find the header files
     54 #  PASTIX_LIBDIR           - Where to find the library files
     55 # The module can also look for the following environment variables if paths
     56 # are not given as cmake variable: PASTIX_DIR, PASTIX_INCDIR, PASTIX_LIBDIR
     57 
     58 #=============================================================================
     59 # Copyright 2012-2013 Inria
     60 # Copyright 2012-2013 Emmanuel Agullo
     61 # Copyright 2012-2013 Mathieu Faverge
     62 # Copyright 2012      Cedric Castagnede
     63 # Copyright 2013      Florent Pruvost
     64 #
     65 # Distributed under the OSI-approved BSD License (the "License");
     66 # see accompanying file MORSE-Copyright.txt for details.
     67 #
     68 # This software is distributed WITHOUT ANY WARRANTY; without even the
     69 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     70 # See the License for more information.
     71 #=============================================================================
     72 # (To distribute this file outside of Morse, substitute the full
     73 #  License text for the above reference.)
     74 
     75 
     76 if (NOT PASTIX_FOUND)
     77   set(PASTIX_DIR "" CACHE PATH "Installation directory of PASTIX library")
     78   if (NOT PASTIX_FIND_QUIETLY)
     79     message(STATUS "A cache variable, namely PASTIX_DIR, has been set to specify the install directory of PASTIX")
     80   endif()
     81 endif()
     82 
     83 # Set the version to find
     84 set(PASTIX_LOOK_FOR_MPI ON)
     85 set(PASTIX_LOOK_FOR_SEQ OFF)
     86 set(PASTIX_LOOK_FOR_STARPU OFF)
     87 set(PASTIX_LOOK_FOR_STARPU_CUDA OFF)
     88 set(PASTIX_LOOK_FOR_STARPU_FXT OFF)
     89 set(PASTIX_LOOK_FOR_SCOTCH ON)
     90 set(PASTIX_LOOK_FOR_PTSCOTCH OFF)
     91 set(PASTIX_LOOK_FOR_METIS OFF)
     92 
     93 if( PASTIX_FIND_COMPONENTS )
     94   foreach( component ${PASTIX_FIND_COMPONENTS} )
     95     if (${component} STREQUAL "SEQ")
     96       # means we look for the sequential version of PaStiX (without MPI)
     97       set(PASTIX_LOOK_FOR_SEQ ON)
     98       set(PASTIX_LOOK_FOR_MPI OFF)
     99     endif()
    100     if (${component} STREQUAL "MPI")
    101       # means we look for the MPI version of PaStiX (default)
    102       set(PASTIX_LOOK_FOR_SEQ OFF)
    103       set(PASTIX_LOOK_FOR_MPI ON)
    104     endif()
    105     if (${component} STREQUAL "STARPU")
    106       # means we look for PaStiX with StarPU
    107       set(PASTIX_LOOK_FOR_STARPU ON)
    108     endif()
    109     if (${component} STREQUAL "STARPU_CUDA")
    110       # means we look for PaStiX with StarPU + CUDA
    111       set(PASTIX_LOOK_FOR_STARPU ON)
    112       set(PASTIX_LOOK_FOR_STARPU_CUDA ON)
    113     endif()
    114     if (${component} STREQUAL "STARPU_FXT")
    115       # means we look for PaStiX with StarPU + FxT
    116       set(PASTIX_LOOK_FOR_STARPU_FXT ON)
    117     endif()
    118     if (${component} STREQUAL "SCOTCH")
    119       set(PASTIX_LOOK_FOR_SCOTCH ON)
    120     endif()
    121     if (${component} STREQUAL "SCOTCH")
    122       set(PASTIX_LOOK_FOR_PTSCOTCH ON)
    123     endif()
    124     if (${component} STREQUAL "METIS")
    125       set(PASTIX_LOOK_FOR_METIS ON)
    126     endif()
    127   endforeach()
    128 endif()
    129 
    130 # Dependencies detection
    131 # ----------------------
    132 
    133 
    134 # Required dependencies
    135 # ---------------------
    136 
    137 if (NOT PASTIX_FIND_QUIETLY)
    138   message(STATUS "Looking for PASTIX - Try to detect pthread")
    139 endif()
    140 if (PASTIX_FIND_REQUIRED)
    141   find_package(Threads REQUIRED QUIET)
    142 else()
    143   find_package(Threads QUIET)
    144 endif()
    145 set(PASTIX_EXTRA_LIBRARIES "")
    146 if( THREADS_FOUND )
    147   list(APPEND PASTIX_EXTRA_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
    148 endif ()
    149 
    150 # Add math library to the list of extra
    151 # it normally exists on all common systems provided with a C compiler
    152 if (NOT PASTIX_FIND_QUIETLY)
    153   message(STATUS "Looking for PASTIX - Try to detect libm")
    154 endif()
    155 set(PASTIX_M_LIBRARIES "")
    156 if(UNIX OR WIN32)
    157   find_library(
    158     PASTIX_M_m_LIBRARY
    159     NAMES m
    160     )
    161   mark_as_advanced(PASTIX_M_m_LIBRARY)
    162   if (PASTIX_M_m_LIBRARY)
    163     list(APPEND PASTIX_M_LIBRARIES "${PASTIX_M_m_LIBRARY}")
    164     list(APPEND PASTIX_EXTRA_LIBRARIES "${PASTIX_M_m_LIBRARY}")
    165   else()
    166     if (PASTIX_FIND_REQUIRED)
    167       message(FATAL_ERROR "Could NOT find libm on your system."
    168 	"Are you sure to a have a C compiler installed?")
    169     endif()
    170   endif()
    171 endif()
    172 
    173 # Try to find librt (libposix4 - POSIX.1b Realtime Extensions library)
    174 # on Unix systems except Apple ones because it does not exist on it
    175 if (NOT PASTIX_FIND_QUIETLY)
    176   message(STATUS "Looking for PASTIX - Try to detect librt")
    177 endif()
    178 set(PASTIX_RT_LIBRARIES "")
    179 if(UNIX AND NOT APPLE)
    180   find_library(
    181     PASTIX_RT_rt_LIBRARY
    182     NAMES rt
    183     )
    184   mark_as_advanced(PASTIX_RT_rt_LIBRARY)
    185   if (PASTIX_RT_rt_LIBRARY)
    186     list(APPEND PASTIX_RT_LIBRARIES "${PASTIX_RT_rt_LIBRARY}")
    187     list(APPEND PASTIX_EXTRA_LIBRARIES "${PASTIX_RT_rt_LIBRARY}")
    188   else()
    189     if (PASTIX_FIND_REQUIRED)
    190       message(FATAL_ERROR "Could NOT find librt on your system")
    191     endif()
    192   endif()
    193 endif()
    194 
    195 # PASTIX depends on HWLOC
    196 #------------------------
    197 if (NOT PASTIX_FIND_QUIETLY)
    198   message(STATUS "Looking for PASTIX - Try to detect HWLOC")
    199 endif()
    200 if (PASTIX_FIND_REQUIRED)
    201   find_package(HWLOC REQUIRED QUIET)
    202 else()
    203   find_package(HWLOC QUIET)
    204 endif()
    205 
    206 # PASTIX depends on BLAS
    207 #-----------------------
    208 if (NOT PASTIX_FIND_QUIETLY)
    209   message(STATUS "Looking for PASTIX - Try to detect BLAS")
    210 endif()
    211 if (PASTIX_FIND_REQUIRED)
    212   find_package(BLASEXT REQUIRED QUIET)
    213 else()
    214   find_package(BLASEXT QUIET)
    215 endif()
    216 
    217 # Optional dependencies
    218 # ---------------------
    219 
    220 # PASTIX may depend on MPI
    221 #-------------------------
    222 if (NOT MPI_FOUND AND PASTIX_LOOK_FOR_MPI)
    223   if (NOT PASTIX_FIND_QUIETLY)
    224     message(STATUS "Looking for PASTIX - Try to detect MPI")
    225   endif()
    226   # allows to use an external mpi compilation by setting compilers with
    227   # -DMPI_C_COMPILER=path/to/mpicc -DMPI_Fortran_COMPILER=path/to/mpif90
    228   # at cmake configure
    229   if(NOT MPI_C_COMPILER)
    230     set(MPI_C_COMPILER mpicc)
    231   endif()
    232   if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_MPI)
    233     find_package(MPI REQUIRED QUIET)
    234   else()
    235     find_package(MPI QUIET)
    236   endif()
    237   if (MPI_FOUND)
    238     mark_as_advanced(MPI_LIBRARY)
    239     mark_as_advanced(MPI_EXTRA_LIBRARY)
    240   endif()
    241 endif (NOT MPI_FOUND AND PASTIX_LOOK_FOR_MPI)
    242 
    243 # PASTIX may depend on STARPU
    244 #----------------------------
    245 if( NOT STARPU_FOUND AND PASTIX_LOOK_FOR_STARPU)
    246 
    247   if (NOT PASTIX_FIND_QUIETLY)
    248     message(STATUS "Looking for PASTIX - Try to detect StarPU")
    249   endif()
    250 
    251   set(PASTIX_STARPU_VERSION "1.1" CACHE STRING "oldest STARPU version desired")
    252 
    253   # create list of components in order to make a single call to find_package(starpu...)
    254   # we explicitly need a StarPU version built with hwloc
    255   set(STARPU_COMPONENT_LIST "HWLOC")
    256 
    257   # StarPU may depend on MPI
    258   # allows to use an external mpi compilation by setting compilers with
    259   # -DMPI_C_COMPILER=path/to/mpicc -DMPI_Fortran_COMPILER=path/to/mpif90
    260   # at cmake configure
    261   if (PASTIX_LOOK_FOR_MPI)
    262     if(NOT MPI_C_COMPILER)
    263       set(MPI_C_COMPILER mpicc)
    264     endif()
    265     list(APPEND STARPU_COMPONENT_LIST "MPI")
    266   endif()
    267   if (PASTIX_LOOK_FOR_STARPU_CUDA)
    268     list(APPEND STARPU_COMPONENT_LIST "CUDA")
    269   endif()
    270   if (PASTIX_LOOK_FOR_STARPU_FXT)
    271     list(APPEND STARPU_COMPONENT_LIST "FXT")
    272   endif()
    273   # set the list of optional dependencies we may discover
    274   if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_STARPU)
    275     find_package(STARPU ${PASTIX_STARPU_VERSION} REQUIRED
    276       COMPONENTS ${STARPU_COMPONENT_LIST})
    277   else()
    278     find_package(STARPU ${PASTIX_STARPU_VERSION}
    279       COMPONENTS ${STARPU_COMPONENT_LIST})
    280   endif()
    281 
    282 endif( NOT STARPU_FOUND AND PASTIX_LOOK_FOR_STARPU)
    283 
    284 # PASTIX may depends on SCOTCH
    285 #-----------------------------
    286 if (NOT SCOTCH_FOUND AND PASTIX_LOOK_FOR_SCOTCH)
    287   if (NOT PASTIX_FIND_QUIETLY)
    288     message(STATUS "Looking for PASTIX - Try to detect SCOTCH")
    289   endif()
    290   if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_SCOTCH)
    291     find_package(SCOTCH REQUIRED QUIET)
    292   else()
    293     find_package(SCOTCH QUIET)
    294   endif()
    295 endif()
    296 
    297 # PASTIX may depends on PTSCOTCH
    298 #-------------------------------
    299 if (NOT PTSCOTCH_FOUND AND PASTIX_LOOK_FOR_PTSCOTCH)
    300   if (NOT PASTIX_FIND_QUIETLY)
    301     message(STATUS "Looking for PASTIX - Try to detect PTSCOTCH")
    302   endif()
    303   if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_PTSCOTCH)
    304     find_package(PTSCOTCH REQUIRED QUIET)
    305   else()
    306     find_package(PTSCOTCH QUIET)
    307   endif()
    308 endif()
    309 
    310 # PASTIX may depends on METIS
    311 #----------------------------
    312 if (NOT METIS_FOUND AND PASTIX_LOOK_FOR_METIS)
    313   if (NOT PASTIX_FIND_QUIETLY)
    314     message(STATUS "Looking for PASTIX - Try to detect METIS")
    315   endif()
    316   if (PASTIX_FIND_REQUIRED AND PASTIX_FIND_REQUIRED_METIS)
    317     find_package(METIS REQUIRED QUIET)
    318   else()
    319     find_package(METIS QUIET)
    320   endif()
    321 endif()
    322 
    323 # Error if pastix required and no partitioning lib found
    324 if (PASTIX_FIND_REQUIRED AND NOT SCOTCH_FOUND AND NOT PTSCOTCH_FOUND AND NOT METIS_FOUND)
    325   message(FATAL_ERROR "Could NOT find any partitioning library on your system"
    326     " (install scotch, ptscotch or metis)")
    327 endif()
    328 
    329 
    330 # Looking for PaStiX
    331 # ------------------
    332 
    333 # Looking for include
    334 # -------------------
    335 
    336 # Add system include paths to search include
    337 # ------------------------------------------
    338 unset(_inc_env)
    339 set(ENV_PASTIX_DIR "$ENV{PASTIX_DIR}")
    340 set(ENV_PASTIX_INCDIR "$ENV{PASTIX_INCDIR}")
    341 if(ENV_PASTIX_INCDIR)
    342   list(APPEND _inc_env "${ENV_PASTIX_INCDIR}")
    343 elseif(ENV_PASTIX_DIR)
    344   list(APPEND _inc_env "${ENV_PASTIX_DIR}")
    345   list(APPEND _inc_env "${ENV_PASTIX_DIR}/include")
    346   list(APPEND _inc_env "${ENV_PASTIX_DIR}/include/pastix")
    347 else()
    348   if(WIN32)
    349     string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
    350   else()
    351     string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
    352     list(APPEND _inc_env "${_path_env}")
    353     string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
    354     list(APPEND _inc_env "${_path_env}")
    355     string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
    356     list(APPEND _inc_env "${_path_env}")
    357     string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
    358     list(APPEND _inc_env "${_path_env}")
    359   endif()
    360 endif()
    361 list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
    362 list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
    363 list(REMOVE_DUPLICATES _inc_env)
    364 
    365 
    366 # Try to find the pastix header in the given paths
    367 # ---------------------------------------------------
    368 # call cmake macro to find the header path
    369 if(PASTIX_INCDIR)
    370   set(PASTIX_pastix.h_DIRS "PASTIX_pastix.h_DIRS-NOTFOUND")
    371   find_path(PASTIX_pastix.h_DIRS
    372     NAMES pastix.h
    373     HINTS ${PASTIX_INCDIR})
    374 else()
    375   if(PASTIX_DIR)
    376     set(PASTIX_pastix.h_DIRS "PASTIX_pastix.h_DIRS-NOTFOUND")
    377     find_path(PASTIX_pastix.h_DIRS
    378       NAMES pastix.h
    379       HINTS ${PASTIX_DIR}
    380       PATH_SUFFIXES "include" "include/pastix")
    381   else()
    382     set(PASTIX_pastix.h_DIRS "PASTIX_pastix.h_DIRS-NOTFOUND")
    383     find_path(PASTIX_pastix.h_DIRS
    384       NAMES pastix.h
    385       HINTS ${_inc_env}
    386       PATH_SUFFIXES "pastix")
    387   endif()
    388 endif()
    389 mark_as_advanced(PASTIX_pastix.h_DIRS)
    390 
    391 # If found, add path to cmake variable
    392 # ------------------------------------
    393 if (PASTIX_pastix.h_DIRS)
    394   set(PASTIX_INCLUDE_DIRS "${PASTIX_pastix.h_DIRS}")
    395 else ()
    396   set(PASTIX_INCLUDE_DIRS "PASTIX_INCLUDE_DIRS-NOTFOUND")
    397   if(NOT PASTIX_FIND_QUIETLY)
    398     message(STATUS "Looking for pastix -- pastix.h not found")
    399   endif()
    400 endif()
    401 
    402 
    403 # Looking for lib
    404 # ---------------
    405 
    406 # Add system library paths to search lib
    407 # --------------------------------------
    408 unset(_lib_env)
    409 set(ENV_PASTIX_LIBDIR "$ENV{PASTIX_LIBDIR}")
    410 if(ENV_PASTIX_LIBDIR)
    411   list(APPEND _lib_env "${ENV_PASTIX_LIBDIR}")
    412 elseif(ENV_PASTIX_DIR)
    413   list(APPEND _lib_env "${ENV_PASTIX_DIR}")
    414   list(APPEND _lib_env "${ENV_PASTIX_DIR}/lib")
    415 else()
    416   if(WIN32)
    417     string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
    418   else()
    419     if(APPLE)
    420       string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}")
    421     else()
    422       string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}")
    423     endif()
    424     list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
    425     list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
    426   endif()
    427 endif()
    428 list(REMOVE_DUPLICATES _lib_env)
    429 
    430 # Try to find the pastix lib in the given paths
    431 # ------------------------------------------------
    432 
    433 # create list of libs to find
    434 set(PASTIX_libs_to_find "pastix_murge;pastix")
    435 
    436 # call cmake macro to find the lib path
    437 if(PASTIX_LIBDIR)
    438   foreach(pastix_lib ${PASTIX_libs_to_find})
    439     set(PASTIX_${pastix_lib}_LIBRARY "PASTIX_${pastix_lib}_LIBRARY-NOTFOUND")
    440     find_library(PASTIX_${pastix_lib}_LIBRARY
    441       NAMES ${pastix_lib}
    442       HINTS ${PASTIX_LIBDIR})
    443   endforeach()
    444 else()
    445   if(PASTIX_DIR)
    446     foreach(pastix_lib ${PASTIX_libs_to_find})
    447       set(PASTIX_${pastix_lib}_LIBRARY "PASTIX_${pastix_lib}_LIBRARY-NOTFOUND")
    448       find_library(PASTIX_${pastix_lib}_LIBRARY
    449 	NAMES ${pastix_lib}
    450 	HINTS ${PASTIX_DIR}
    451 	PATH_SUFFIXES lib lib32 lib64)
    452     endforeach()
    453   else()
    454     foreach(pastix_lib ${PASTIX_libs_to_find})
    455       set(PASTIX_${pastix_lib}_LIBRARY "PASTIX_${pastix_lib}_LIBRARY-NOTFOUND")
    456       find_library(PASTIX_${pastix_lib}_LIBRARY
    457 	NAMES ${pastix_lib}
    458 	HINTS ${_lib_env})
    459     endforeach()
    460   endif()
    461 endif()
    462 
    463 # If found, add path to cmake variable
    464 # ------------------------------------
    465 foreach(pastix_lib ${PASTIX_libs_to_find})
    466 
    467   get_filename_component(${pastix_lib}_lib_path ${PASTIX_${pastix_lib}_LIBRARY} PATH)
    468   # set cmake variables (respects naming convention)
    469   if (PASTIX_LIBRARIES)
    470     list(APPEND PASTIX_LIBRARIES "${PASTIX_${pastix_lib}_LIBRARY}")
    471   else()
    472     set(PASTIX_LIBRARIES "${PASTIX_${pastix_lib}_LIBRARY}")
    473   endif()
    474   if (PASTIX_LIBRARY_DIRS)
    475     list(APPEND PASTIX_LIBRARY_DIRS "${${pastix_lib}_lib_path}")
    476   else()
    477     set(PASTIX_LIBRARY_DIRS "${${pastix_lib}_lib_path}")
    478   endif()
    479   mark_as_advanced(PASTIX_${pastix_lib}_LIBRARY)
    480 
    481 endforeach(pastix_lib ${PASTIX_libs_to_find})
    482 
    483 # check a function to validate the find
    484 if(PASTIX_LIBRARIES)
    485 
    486   set(REQUIRED_LDFLAGS)
    487   set(REQUIRED_INCDIRS)
    488   set(REQUIRED_LIBDIRS)
    489   set(REQUIRED_LIBS)
    490 
    491   # PASTIX
    492   if (PASTIX_INCLUDE_DIRS)
    493     set(REQUIRED_INCDIRS "${PASTIX_INCLUDE_DIRS}")
    494   endif()
    495   foreach(libdir ${PASTIX_LIBRARY_DIRS})
    496     if (libdir)
    497       list(APPEND REQUIRED_LIBDIRS "${libdir}")
    498     endif()
    499   endforeach()
    500   set(REQUIRED_LIBS "${PASTIX_LIBRARIES}")
    501   # STARPU
    502   if (PASTIX_LOOK_FOR_STARPU AND STARPU_FOUND)
    503     if (STARPU_INCLUDE_DIRS_DEP)
    504       list(APPEND REQUIRED_INCDIRS "${STARPU_INCLUDE_DIRS_DEP}")
    505     elseif (STARPU_INCLUDE_DIRS)
    506       list(APPEND REQUIRED_INCDIRS "${STARPU_INCLUDE_DIRS}")
    507     endif()
    508     if(STARPU_LIBRARY_DIRS_DEP)
    509       list(APPEND REQUIRED_LIBDIRS "${STARPU_LIBRARY_DIRS_DEP}")
    510     elseif(STARPU_LIBRARY_DIRS)
    511       list(APPEND REQUIRED_LIBDIRS "${STARPU_LIBRARY_DIRS}")
    512     endif()
    513     if (STARPU_LIBRARIES_DEP)
    514       list(APPEND REQUIRED_LIBS "${STARPU_LIBRARIES_DEP}")
    515     elseif (STARPU_LIBRARIES)
    516       foreach(lib ${STARPU_LIBRARIES})
    517 	if (EXISTS ${lib} OR ${lib} MATCHES "^-")
    518 	  list(APPEND REQUIRED_LIBS "${lib}")
    519 	else()
    520 	  list(APPEND REQUIRED_LIBS "-l${lib}")
    521 	endif()
    522       endforeach()
    523     endif()
    524   endif()
    525   # CUDA
    526   if (PASTIX_LOOK_FOR_STARPU_CUDA AND CUDA_FOUND)
    527     if (CUDA_INCLUDE_DIRS)
    528       list(APPEND REQUIRED_INCDIRS "${CUDA_INCLUDE_DIRS}")
    529     endif()
    530     foreach(libdir ${CUDA_LIBRARY_DIRS})
    531       if (libdir)
    532 	list(APPEND REQUIRED_LIBDIRS "${libdir}")
    533       endif()
    534     endforeach()
    535     list(APPEND REQUIRED_LIBS "${CUDA_CUBLAS_LIBRARIES};${CUDA_LIBRARIES}")
    536   endif()
    537   # MPI
    538   if (PASTIX_LOOK_FOR_MPI AND MPI_FOUND)
    539     if (MPI_C_INCLUDE_PATH)
    540       list(APPEND REQUIRED_INCDIRS "${MPI_C_INCLUDE_PATH}")
    541     endif()
    542     if (MPI_C_LINK_FLAGS)
    543       if (${MPI_C_LINK_FLAGS} MATCHES "  -")
    544 	string(REGEX REPLACE " -" "-" MPI_C_LINK_FLAGS ${MPI_C_LINK_FLAGS})
    545       endif()
    546       list(APPEND REQUIRED_LDFLAGS "${MPI_C_LINK_FLAGS}")
    547     endif()
    548     list(APPEND REQUIRED_LIBS "${MPI_C_LIBRARIES}")
    549   endif()
    550   # HWLOC
    551   if (HWLOC_FOUND)
    552     if (HWLOC_INCLUDE_DIRS)
    553       list(APPEND REQUIRED_INCDIRS "${HWLOC_INCLUDE_DIRS}")
    554     endif()
    555     foreach(libdir ${HWLOC_LIBRARY_DIRS})
    556       if (libdir)
    557 	list(APPEND REQUIRED_LIBDIRS "${libdir}")
    558       endif()
    559     endforeach()
    560     foreach(lib ${HWLOC_LIBRARIES})
    561       if (EXISTS ${lib} OR ${lib} MATCHES "^-")
    562 	list(APPEND REQUIRED_LIBS "${lib}")
    563       else()
    564 	list(APPEND REQUIRED_LIBS "-l${lib}")
    565       endif()
    566     endforeach()
    567   endif()
    568   # BLAS
    569   if (BLAS_FOUND)
    570     if (BLAS_INCLUDE_DIRS)
    571       list(APPEND REQUIRED_INCDIRS "${BLAS_INCLUDE_DIRS}")
    572     endif()
    573     foreach(libdir ${BLAS_LIBRARY_DIRS})
    574       if (libdir)
    575 	list(APPEND REQUIRED_LIBDIRS "${libdir}")
    576       endif()
    577     endforeach()
    578     list(APPEND REQUIRED_LIBS "${BLAS_LIBRARIES}")
    579     if (BLAS_LINKER_FLAGS)
    580       list(APPEND REQUIRED_LDFLAGS "${BLAS_LINKER_FLAGS}")
    581     endif()
    582   endif()
    583   # SCOTCH
    584   if (PASTIX_LOOK_FOR_SCOTCH AND SCOTCH_FOUND)
    585     if (SCOTCH_INCLUDE_DIRS)
    586       list(APPEND REQUIRED_INCDIRS "${SCOTCH_INCLUDE_DIRS}")
    587     endif()
    588     foreach(libdir ${SCOTCH_LIBRARY_DIRS})
    589       if (libdir)
    590 	list(APPEND REQUIRED_LIBDIRS "${libdir}")
    591       endif()
    592     endforeach()
    593     list(APPEND REQUIRED_LIBS "${SCOTCH_LIBRARIES}")
    594   endif()
    595   # PTSCOTCH
    596   if (PASTIX_LOOK_FOR_PTSCOTCH AND PTSCOTCH_FOUND)
    597     if (PTSCOTCH_INCLUDE_DIRS)
    598       list(APPEND REQUIRED_INCDIRS "${PTSCOTCH_INCLUDE_DIRS}")
    599     endif()
    600     foreach(libdir ${PTSCOTCH_LIBRARY_DIRS})
    601       if (libdir)
    602 	list(APPEND REQUIRED_LIBDIRS "${libdir}")
    603       endif()
    604     endforeach()
    605     list(APPEND REQUIRED_LIBS "${PTSCOTCH_LIBRARIES}")
    606   endif()
    607   # METIS
    608   if (PASTIX_LOOK_FOR_METIS AND METIS_FOUND)
    609     if (METIS_INCLUDE_DIRS)
    610       list(APPEND REQUIRED_INCDIRS "${METIS_INCLUDE_DIRS}")
    611     endif()
    612     foreach(libdir ${METIS_LIBRARY_DIRS})
    613       if (libdir)
    614 	list(APPEND REQUIRED_LIBDIRS "${libdir}")
    615       endif()
    616     endforeach()
    617     list(APPEND REQUIRED_LIBS "${METIS_LIBRARIES}")
    618   endif()
    619   # Fortran
    620   if (CMAKE_C_COMPILER_ID MATCHES "GNU")
    621     find_library(
    622       FORTRAN_gfortran_LIBRARY
    623       NAMES gfortran
    624       HINTS ${_lib_env}
    625       )
    626     mark_as_advanced(FORTRAN_gfortran_LIBRARY)
    627     if (FORTRAN_gfortran_LIBRARY)
    628       list(APPEND REQUIRED_LIBS "${FORTRAN_gfortran_LIBRARY}")
    629     endif()
    630   elseif (CMAKE_C_COMPILER_ID MATCHES "Intel")
    631     find_library(
    632       FORTRAN_ifcore_LIBRARY
    633       NAMES ifcore
    634       HINTS ${_lib_env}
    635       )
    636     mark_as_advanced(FORTRAN_ifcore_LIBRARY)
    637     if (FORTRAN_ifcore_LIBRARY)
    638       list(APPEND REQUIRED_LIBS "${FORTRAN_ifcore_LIBRARY}")
    639     endif()
    640   endif()
    641   # EXTRA LIBS such that pthread, m, rt
    642   list(APPEND REQUIRED_LIBS ${PASTIX_EXTRA_LIBRARIES})
    643 
    644   # set required libraries for link
    645   set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
    646   set(CMAKE_REQUIRED_LIBRARIES)
    647   list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LDFLAGS}")
    648   foreach(lib_dir ${REQUIRED_LIBDIRS})
    649     list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
    650   endforeach()
    651   list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
    652   list(APPEND CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}")
    653   string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
    654 
    655   # test link
    656   unset(PASTIX_WORKS CACHE)
    657   include(CheckFunctionExists)
    658   check_function_exists(pastix PASTIX_WORKS)
    659   mark_as_advanced(PASTIX_WORKS)
    660 
    661   if(PASTIX_WORKS)
    662     # save link with dependencies
    663     set(PASTIX_LIBRARIES_DEP "${REQUIRED_LIBS}")
    664     set(PASTIX_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
    665     set(PASTIX_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
    666     set(PASTIX_LINKER_FLAGS "${REQUIRED_LDFLAGS}")
    667     list(REMOVE_DUPLICATES PASTIX_LIBRARY_DIRS_DEP)
    668     list(REMOVE_DUPLICATES PASTIX_INCLUDE_DIRS_DEP)
    669     list(REMOVE_DUPLICATES PASTIX_LINKER_FLAGS)
    670   else()
    671     if(NOT PASTIX_FIND_QUIETLY)
    672       message(STATUS "Looking for PASTIX : test of pastix() fails")
    673       message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
    674       message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}")
    675       message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails")
    676       message(STATUS "Maybe PASTIX is linked with specific libraries. "
    677 	"Have you tried with COMPONENTS (MPI/SEQ, STARPU, STARPU_CUDA, SCOTCH, PTSCOTCH, METIS)? "
    678 	"See the explanation in FindPASTIX.cmake.")
    679     endif()
    680   endif()
    681   set(CMAKE_REQUIRED_INCLUDES)
    682   set(CMAKE_REQUIRED_FLAGS)
    683   set(CMAKE_REQUIRED_LIBRARIES)
    684 endif(PASTIX_LIBRARIES)
    685 
    686 if (PASTIX_LIBRARIES)
    687   list(GET PASTIX_LIBRARIES 0 first_lib)
    688   get_filename_component(first_lib_path "${first_lib}" PATH)
    689   if (${first_lib_path} MATCHES "/lib(32|64)?$")
    690     string(REGEX REPLACE "/lib(32|64)?$" "" not_cached_dir "${first_lib_path}")
    691     set(PASTIX_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of PASTIX library" FORCE)
    692   else()
    693     set(PASTIX_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of PASTIX library" FORCE)
    694   endif()
    695 endif()
    696 mark_as_advanced(PASTIX_DIR)
    697 mark_as_advanced(PASTIX_DIR_FOUND)
    698 
    699 # check that PASTIX has been found
    700 # ---------------------------------
    701 include(FindPackageHandleStandardArgs)
    702 find_package_handle_standard_args(PASTIX DEFAULT_MSG
    703   PASTIX_LIBRARIES
    704   PASTIX_WORKS)
    705