FindLAPACKEXT.cmake 10.9 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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 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
# - Find LAPACK EXTENDED for MORSE projects: find include dirs and libraries
#
# This module allows to find LAPACK libraries by calling the official FindLAPACK module
# and handles the creation of different library lists whether the user wishes to link 
# with a sequential LAPACK or a multihreaded (LAPACK_SEQ_LIBRARIES and LAPACK_PAR_LIBRARIES).
# LAPACK is detected with a FindLAPACK call then if the LAPACK vendor is in the following list,
# Intel mkl, Goto, Openlapack, ACML, IBMESSL
# then the module tries find the corresponding multithreaded libraries
# LAPACK_LIBRARIES does not exists anymore. 
#
# The following variables have been added to manage links with sequential or multithreaded 
# versions:
#  LAPACK_INCLUDE_DIRS  - LAPACK include directories
#  LAPACK_LIBRARY_DIRS  - Link directories for LAPACK libraries
#  LAPACK_SEQ_LIBRARIES - LAPACK component libraries to be linked (sequential)
#  LAPACK_PAR_LIBRARIES - LAPACK component libraries to be linked (multithreaded)

#=============================================================================
# Copyright 2012-2013 Inria
# Copyright 2012-2013 Emmanuel Agullo
# Copyright 2012-2013 Mathieu Faverge
# Copyright 2012      Cedric Castagnede
# Copyright 2013      Florent Pruvost
#
# 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.)


# Some macros to print status when search for headers and libs
# PrintFindStatus.cmake is in cmake_modules/morse/find directory of magmamorse
include(PrintFindStatus)

# LAPACKEXT depends on BLASEXT
# call our extended module for BLAS
#----------------------------------
if (NOT BLAS_FOUND)
    if(LAPACKEXT_FIND_REQUIRED)
        find_package(BLASEXT REQUIRED)
    else()
        find_package(BLASEXT)
    endif()
endif ()


if(BLA_VENDOR MATCHES "Intel*")

    ###
    # look for include path if the LAPACK vendor is Intel
    ###
    
    # gather system include paths
    unset(_inc_env)
    if(WIN32)
        string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
    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()
    list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
    list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
    list(REMOVE_DUPLICATES _inc_env)
    
    if (BLAS_DIR)
        set(LAPACK_DIR ${BLAS_DIR})
    endif ()
    if (BLAS_INCDIR)
        set(LAPACK_INCDIR ${BLAS_INCDIR})
    endif ()    
    # find mkl.h inside known include paths
    set(LAPACK_mkl_lapack.h_INCLUDE_DIRS "LAPACK_mkl_lapack.h_INCLUDE_DIRS-NOTFOUND")
    if(LAPACK_INCDIR)
        find_path(LAPACK_mkl_lapack.h_INCLUDE_DIRS
                NAMES mkl_lapack.h
                HINTS ${LAPACK_INCDIR})
    else()
        if(LAPACK_DIR)
            find_path(LAPACK_mkl_lapack.h_INCLUDE_DIRS
                    NAMES mkl_lapack.h
                    HINTS ${LAPACK_DIR}
                    PATH_SUFFIXES include)
        else()
            find_path(LAPACK_mkl_lapack.h_INCLUDE_DIRS
                    NAMES mkl_lapack.h
                    HINTS ${_inc_env})
        endif()
    endif()  
    mark_as_advanced(LAPACK_mkl_lapack.h_INCLUDE_DIRS)
    # Print status if not found
    # -------------------------
    if (NOT LAPACK_mkl_lapack.h_INCLUDE_DIRS)
        Print_Find_Header_Status(lapack mkl_lapack.h)
    endif ()    
    set(LAPACK_INCLUDE_DIRS "")
    if(LAPACK_mkl_lapack.h_INCLUDE_DIRS)
        list(APPEND LAPACK_INCLUDE_DIRS "${LAPACK_mkl_lapack.h_INCLUDE_DIRS}" )
    endif()
    
    ###
    # look for libs
    ###
    
    if (BLA_VENDOR MATCHES "Intel10_64lp*")
        ## look for the sequential version
        set(BLA_VENDOR "Intel10_64lp_seq")
    endif()
    
    if(LAPACKEXT_FIND_REQUIRED)
        find_package(LAPACK REQUIRED)
    else()
        find_package(LAPACK)
    endif()
    
    if (LAPACK_FOUND)
        if(BLAS_SEQ_LIBRARIES)
            set(LAPACK_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES}")
        else()
            set(LAPACK_SEQ_LIBRARIES "${LAPACK_SEQ_LIBRARIES-NOTFOUND}")
        endif()     
        # if BLAS Intel 10 64 bit -> save sequential and multithreaded versions
        if(BLA_VENDOR MATCHES "Intel10_64lp*")
            if(BLAS_PAR_LIBRARIES)
                set(LAPACK_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES}")
            else()
                set(LAPACK_PAR_LIBRARIES "${LAPACK_PAR_LIBRARIES-NOTFOUND}")
            endif()         
        endif()  
    endif()
    
elseif(BLA_VENDOR MATCHES "ACML*") 

    ###
    # look for libs
    ###
    if(LAPACKEXT_FIND_REQUIRED)
        find_package(LAPACK REQUIRED)
    else()
        find_package(LAPACK)
    endif()

    if (LAPACK_FOUND)
        if(BLAS_SEQ_LIBRARIES)
            set(LAPACK_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES}")
        else()
            set(LAPACK_SEQ_LIBRARIES "${LAPACK_SEQ_LIBRARIES-NOTFOUND}")
        endif()    
        if(BLAS_PAR_LIBRARIES)
            set(LAPACK_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES}")
        else()
            set(LAPACK_PAR_LIBRARIES "${LAPACK_PAR_LIBRARIES-NOTFOUND}")
        endif()  
    endif()   
    
else()

    ## look for a sequential version
    # call to the cmake official FindLAPACK module
    # This module sets the following variables:
    #  LAPACK_FOUND - set to true if a library implementing the LAPACK interface
    #    is found
    #  LAPACK_LINKER_FLAGS - uncached list of required linker flags (excluding -l
    #    and -L).
    #  LAPACK_LIBRARIES - uncached list of libraries (using full path name) to
    #    link against to use LAPACK
    #  LAPACK95_LIBRARIES - uncached list of libraries (using full path name)
    #    to link against to use LAPACK95 interface
    #  LAPACK95_FOUND - set to true if a library implementing the LAPACK 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 LAPACK/LAPACK
    # Remark: it looks only into paths contained in the system environment variables
    if(LAPACKEXT_FIND_REQUIRED)
        find_package(LAPACK REQUIRED)
    else()
        find_package(LAPACK)
    endif()
    
    if(LAPACK_FOUND)
        set(LAPACK_SEQ_LIBRARIES "${LAPACK_LIBRARIES}")
    else()
        set(LAPACK_SEQ_LIBRARIES "${LAPACK_SEQ_LIBRARIES-NOTFOUND}")
    endif()    
    set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}")

endif()

if (LAPACK_SEQ_LIBRARIES)
    set(LAPACK_LIBRARIES "${LAPACK_SEQ_LIBRARIES}")
endif()

# extract libs paths
# remark: because it is not given by find_package(LAPACK)
set(LAPACK_LIBRARY_DIRS "")
foreach(lapack_lib ${LAPACK_LIBRARIES})
    get_filename_component(a_lapack_lib_dir "${lapack_lib}" PATH)
    list(APPEND LAPACK_LIBRARY_DIRS "${a_lapack_lib_dir}" )
endforeach()
if (LAPACK_LIBRARY_DIRS)
    list(REMOVE_DUPLICATES LAPACK_LIBRARY_DIRS)
endif ()


# message(STATUS "LAPACK_FOUND: ${LAPACK_FOUND}")
# message(STATUS "LAPACK_VENDOR: ${LAPACK_VENDOR}")
# message(STATUS "LAPACK_LIBRARIES: ${LAPACK_LIBRARIES}")
# message(STATUS "LAPACK_SEQ_LIBRARIES: ${LAPACK_SEQ_LIBRARIES}")
# message(STATUS "LAPACK_PAR_LIBRARIES: ${LAPACK_PAR_LIBRARIES}")
# message(STATUS "LAPACK_INCLUDE_DIRS: ${LAPACK_INCLUDE_DIRS}")
# message(STATUS "LAPACK_LIBRARY_DIRS: ${LAPACK_LIBRARY_DIRS}")

# check that LAPACK has been found
# ---------------------------------
include(FindPackageHandleStandardArgs)
if(BLA_VENDOR MATCHES "Intel*")
    if(BLA_VENDOR MATCHES "Intel10_64lp*")
        if(NOT LAPACKEXT_FIND_QUIETLY)
            message(STATUS "LAPACK found is Intel MKL:"
                           "we manage two lists of libs,"
                           " one sequential and one parallel (see"
                           "LAPACK_SEQ_LIBRARIES and LAPACK_PAR_LIBRARIES)")
            message(STATUS "LAPACK sequential libraries stored in"
                           "LAPACK_SEQ_LIBRARIES")
        endif()
        find_package_handle_standard_args(LAPACK DEFAULT_MSG
                                          LAPACK_SEQ_LIBRARIES
                                          LAPACK_LIBRARY_DIRS
                                          LAPACK_INCLUDE_DIRS)
        if(LAPACK_PAR_LIBRARIES)
            if(NOT LAPACKEXT_FIND_QUIETLY)
                message(STATUS "LAPACK parallel libraries stored in"
                               "LAPACK_PAR_LIBRARIES")
            endif()
            find_package_handle_standard_args(LAPACK DEFAULT_MSG
                                              LAPACK_PAR_LIBRARIES)
        endif()
                          
    else()
        if(NOT LAPACKEXT_FIND_QUIETLY)
            message(STATUS "LAPACK sequential libraries stored in"
                           "LAPACK_SEQ_LIBRARIES")
        endif()
        find_package_handle_standard_args(LAPACK DEFAULT_MSG
                                          LAPACK_SEQ_LIBRARIES
                                          LAPACK_LIBRARY_DIRS
                                          LAPACK_INCLUDE_DIRS)    
    endif()
elseif(BLA_VENDOR MATCHES "ACML*")
    if(NOT LAPACKEXT_FIND_QUIETLY)
        message(STATUS "LAPACK found is ACML:"
                        "we manage two lists of libs,"
                        " one sequential and one parallel (see"
                        "LAPACK_SEQ_LIBRARIES and LAPACK_PAR_LIBRARIES)")
        message(STATUS "LAPACK sequential libraries stored in"
                       "LAPACK_SEQ_LIBRARIES")
    endif()
    find_package_handle_standard_args(LAPACK DEFAULT_MSG
                                      LAPACK_SEQ_LIBRARIES
                                      LAPACK_LIBRARY_DIRS
                                      LAPACK_INCLUDE_DIRS)
    if(LAPACK_PAR_LIBRARIES)
        if(NOT LAPACKEXT_FIND_QUIETLY)
            message(STATUS "LAPACK parallel libraries stored in"
                           "LAPACK_PAR_LIBRARIES")
        endif()
        find_package_handle_standard_args(LAPACK DEFAULT_MSG
                                        LAPACK_PAR_LIBRARIES)
    endif()
else()
    if(NOT LAPACKEXT_FIND_QUIETLY)
        message(STATUS "LAPACK sequential libraries stored in"
                       "LAPACK_SEQ_LIBRARIES")
    endif()
    find_package_handle_standard_args(LAPACK DEFAULT_MSG
                                      LAPACK_SEQ_LIBRARIES
                                      LAPACK_LIBRARY_DIRS)
endif()