Commit 82fc6489 authored by PRUVOST Florent's avatar PRUVOST Florent

Merge branch 'improve-pkg-config' into 'master'

transform relative path from pkg-config into absolute path and check function…

See merge request !16
parents 289efa0a 6ee95304
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
# #
### ###
# Transform relative path into absolute path for libraries found with the # Transform relative path into absolute path for libraries found with the
# pkg_search_module cmake macro # pkg_search_module cmake macro
# _prefix: the name of the CMake variable used when pkg_search_module was called # _prefix: the name of the CMake variable used when pkg_search_module was called
# e.g. for pkg_search_module(BLAS blas) _prefix would be BLAS # e.g. for pkg_search_module(BLAS blas) _prefix would be BLAS
...@@ -34,10 +34,19 @@ macro(FIND_PKGCONFIG_LIBRARIES_ABSOLUTE_PATH _prefix) ...@@ -34,10 +34,19 @@ macro(FIND_PKGCONFIG_LIBRARIES_ABSOLUTE_PATH _prefix)
endif() endif()
list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}") list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}") list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
# non static case
set(${_prefix}_LIBRARIES_COPY "${${_prefix}_LIBRARIES}") set(${_prefix}_LIBRARIES_COPY "${${_prefix}_LIBRARIES}")
set(${_prefix}_LIBRARIES "") set(${_prefix}_LIBRARIES "")
foreach(_library ${${_prefix}_LIBRARIES_COPY}) foreach(_library ${${_prefix}_LIBRARIES_COPY})
get_filename_component(_library "${_library}" NAME_WE) if(EXISTS "${_library}")
list(APPEND ${_prefix}_LIBRARIES ${_library})
else()
get_filename_component(_ext "${_library}" EXT)
set(_lib_extensions ".so" ".a" ".dyld" ".dll")
list(FIND _lib_extensions "${_ext}" _index)
if (${_index} GREATER -1)
get_filename_component(_library "${_library}" NAME_WE)
endif()
find_library(_library_path NAMES ${_library} find_library(_library_path NAMES ${_library}
HINTS ${${_prefix}_LIBDIR} ${${_prefix}_LIBRARY_DIRS} ${_lib_env}) HINTS ${${_prefix}_LIBDIR} ${${_prefix}_LIBRARY_DIRS} ${_lib_env})
if (_library_path) if (_library_path)
...@@ -46,22 +55,33 @@ macro(FIND_PKGCONFIG_LIBRARIES_ABSOLUTE_PATH _prefix) ...@@ -46,22 +55,33 @@ macro(FIND_PKGCONFIG_LIBRARIES_ABSOLUTE_PATH _prefix)
message(FATAL_ERROR "Dependency of ${_prefix} '${_library}' NOT FOUND") message(FATAL_ERROR "Dependency of ${_prefix} '${_library}' NOT FOUND")
endif() endif()
unset(_library_path CACHE) unset(_library_path CACHE)
set (${_prefix}_LIBRARIES "${${_prefix}_LIBRARIES}" CACHE INTERNAL "" FORCE) endif()
endforeach() endforeach()
set (${_prefix}_LIBRARIES "${${_prefix}_LIBRARIES}" CACHE INTERNAL "" FORCE)
# static case
set(${_prefix}_STATIC_LIBRARIES_COPY "${${_prefix}_STATIC_LIBRARIES}") set(${_prefix}_STATIC_LIBRARIES_COPY "${${_prefix}_STATIC_LIBRARIES}")
set(${_prefix}_STATIC_LIBRARIES "") set(${_prefix}_STATIC_LIBRARIES "")
foreach(_library ${${_prefix}_STATIC_LIBRARIES_COPY}) foreach(_library ${${_prefix}_STATIC_LIBRARIES_COPY})
get_filename_component(_library "${_library}" NAME_WE) if(EXISTS "${_library}")
list(APPEND ${_prefix}_STATIC_LIBRARIES ${_library})
else()
get_filename_component(_ext "${_library}" EXT)
set(_lib_extensions ".so" ".a" ".dyld" ".dll")
list(FIND _lib_extensions "${_ext}" _index)
if (${_index} GREATER -1)
get_filename_component(_library "${_library}" NAME_WE)
endif()
find_library(_library_path NAMES ${_library} find_library(_library_path NAMES ${_library}
HINTS ${${_prefix}_STATIC_LIBDIR} ${${_prefix}_STATIC_LIBRARY_DIRS} ${_lib_env}) HINTS ${${_prefix}_STATIC_LIBDIR} ${${_prefix}_STATIC_LIBRARY_DIRS} ${_lib_env})
if (_library_path) if (_library_path)
list(APPEND ${_prefix}_STATIC_LIBRARIES ${_library_path}) list(APPEND ${_prefix}_STATIC_LIBRARIES ${_library_path})
else() else()
message(FATAL_ERROR "Dependency of ${_prefix} '${_library}' NOT FOUND") message(FATAL_ERROR "Dependency of ${_prefix} '${_library}' NOT FOUND")
endif() endif()
unset(_library_path CACHE) unset(_library_path CACHE)
set (${_prefix}_STATIC_LIBRARIES "${${_prefix}_STATIC_LIBRARIES}" CACHE INTERNAL "" FORCE) endif()
endforeach() endforeach()
set (${_prefix}_STATIC_LIBRARIES "${${_prefix}_STATIC_LIBRARIES}" CACHE INTERNAL "" FORCE)
endmacro() endmacro()
## ##
......
This diff is collapsed.
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# @copyright (c) 2009-2014 The University of Tennessee and The University # @copyright (c) 2009-2014 The University of Tennessee and The University
# of Tennessee Research Foundation. # of Tennessee Research Foundation.
# All rights reserved. # All rights reserved.
# @copyright (c) 2012-2016 Inria. All rights reserved. # @copyright (c) 2012-2018 Inria. All rights reserved.
# @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved. # @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
# #
### ###
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
# This module finds headers and cblas library. # This module finds headers and cblas library.
# Results are reported in variables: # Results are reported in variables:
# CBLAS_FOUND - True if headers and requested libraries were found # CBLAS_FOUND - True if headers and requested libraries were found
# CBLAS_LINKER_FLAGS - list of required linker flags (excluding -l and -L)
# CBLAS_INCLUDE_DIRS - cblas include directories # CBLAS_INCLUDE_DIRS - cblas include directories
# CBLAS_LIBRARY_DIRS - Link directories for cblas libraries # CBLAS_LIBRARY_DIRS - Link directories for cblas libraries
# CBLAS_LIBRARIES - cblas component libraries to be linked # CBLAS_LIBRARIES - cblas component libraries to be linked
...@@ -30,6 +29,20 @@ ...@@ -30,6 +29,20 @@
# CBLAS_LIBRARIES_DEP - cblas libraries + dependencies # CBLAS_LIBRARIES_DEP - cblas libraries + dependencies
# CBLAS_HAS_ZGEMM3M - True if cblas contains zgemm3m fast complex mat-mat product # CBLAS_HAS_ZGEMM3M - True if cblas contains zgemm3m fast complex mat-mat product
# #
# 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
#
# The user can give specific paths where to find the libraries adding cmake # 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): # options at configure (ex: cmake path/to/project -DCBLAS_DIR=path/to/cblas):
# CBLAS_DIR - Where to find the base directory of cblas # CBLAS_DIR - Where to find the base directory of cblas
...@@ -59,11 +72,11 @@ ...@@ -59,11 +72,11 @@
# #
#============================================================================= #=============================================================================
# Copyright 2012-2013 Inria # Copyright 2012-2018 Inria
# Copyright 2012-2013 Emmanuel Agullo # Copyright 2012-2013 Emmanuel Agullo
# Copyright 2012-2013 Mathieu Faverge # Copyright 2012-2013 Mathieu Faverge
# Copyright 2012 Cedric Castagnede # Copyright 2012 Cedric Castagnede
# Copyright 2013-2016 Florent Pruvost # Copyright 2013-2018 Florent Pruvost
# #
# Distributed under the OSI-approved BSD License (the "License"); # Distributed under the OSI-approved BSD License (the "License");
# see accompanying file MORSE-Copyright.txt for details. # see accompanying file MORSE-Copyright.txt for details.
...@@ -130,235 +143,276 @@ if (BLAS_FOUND) ...@@ -130,235 +143,276 @@ if (BLAS_FOUND)
set(CBLAS_INCLUDE_DIRS "${BLAS_INCLUDE_DIRS}") set(CBLAS_INCLUDE_DIRS "${BLAS_INCLUDE_DIRS}")
set(CBLAS_INCLUDE_DIRS_DEP "${BLAS_INCLUDE_DIRS_DEP}") set(CBLAS_INCLUDE_DIRS_DEP "${BLAS_INCLUDE_DIRS_DEP}")
endif() endif()
if (BLAS_LINKER_FLAGS)
set(CBLAS_LINKER_FLAGS "${BLAS_LINKER_FLAGS}")
endif()
endif() endif()
endif (NOT CBLAS_STANDALONE) endif (NOT CBLAS_STANDALONE)
# test fails with blas: try to find CBLAS lib exterior to BLAS
if (CBLAS_STANDALONE OR NOT CBLAS_WORKS) if (CBLAS_STANDALONE OR NOT CBLAS_WORKS)
if(NOT CBLAS_WORKS AND NOT CBLAS_FIND_QUIETLY) if(NOT CBLAS_WORKS AND NOT CBLAS_FIND_QUIETLY)
message(STATUS "Looking for cblas : test with blas fails") message(STATUS "Looking for cblas : test with blas fails")
endif() endif()
# test fails: try to find CBLAS lib exterior to BLAS
# Try to find CBLAS lib
#######################
# Looking for include # try with pkg-config
# -------------------
# Add system include paths to search include
# ------------------------------------------
unset(_inc_env)
set(ENV_CBLAS_DIR "$ENV{CBLAS_DIR}") set(ENV_CBLAS_DIR "$ENV{CBLAS_DIR}")
set(ENV_CBLAS_INCDIR "$ENV{CBLAS_INCDIR}") set(ENV_CBLAS_INCDIR "$ENV{CBLAS_INCDIR}")
if(ENV_CBLAS_INCDIR) set(ENV_CBLAS_LIBDIR "$ENV{CBLAS_LIBDIR}")
list(APPEND _inc_env "${ENV_CBLAS_INCDIR}") set(CBLAS_GIVEN_BY_USER "FALSE")
elseif(ENV_CBLAS_DIR) if ( CBLAS_DIR OR ( CBLAS_INCDIR AND CBLAS_LIBDIR) OR ENV_CBLAS_DIR OR (ENV_CBLAS_INCDIR AND ENV_CBLAS_LIBDIR) )
list(APPEND _inc_env "${ENV_CBLAS_DIR}") set(CBLAS_GIVEN_BY_USER "TRUE")
list(APPEND _inc_env "${ENV_CBLAS_DIR}/include") endif()
list(APPEND _inc_env "${ENV_CBLAS_DIR}/include/cblas")
else() include(FindPkgConfig)
if(WIN32) find_package(PkgConfig QUIET)
string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}") if( PKG_CONFIG_EXECUTABLE AND NOT CBLAS_GIVEN_BY_USER)
list(APPEND _inc_env "${_path_env}")
pkg_search_module(CBLAS cblas)
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)
else() else()
string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}") set(CBLAS_FOUND_WITH_PKGCONFIG "FALSE")
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()
endif() endif()
list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}") if (NOT CBLAS_FOUND_WITH_PKGCONFIG OR CBLAS_GIVEN_BY_USER)
list(REMOVE_DUPLICATES _inc_env) # Try to find CBLAS lib
#######################
# Try to find the cblas header in the given paths # Looking for include
# ------------------------------------------------- # -------------------
# call cmake macro to find the header path
if(CBLAS_INCDIR) # Add system include paths to search include
set(CBLAS_cblas.h_DIRS "CBLAS_cblas.h_DIRS-NOTFOUND") # ------------------------------------------
find_path(CBLAS_cblas.h_DIRS unset(_inc_env)
NAMES cblas.h set(ENV_CBLAS_DIR "$ENV{CBLAS_DIR}")
HINTS ${CBLAS_INCDIR}) set(ENV_CBLAS_INCDIR "$ENV{CBLAS_INCDIR}")
else() if(ENV_CBLAS_INCDIR)
if(CBLAS_DIR) list(APPEND _inc_env "${ENV_CBLAS_INCDIR}")
set(CBLAS_cblas.h_DIRS "CBLAS_cblas.h_DIRS-NOTFOUND") elseif(ENV_CBLAS_DIR)
find_path(CBLAS_cblas.h_DIRS list(APPEND _inc_env "${ENV_CBLAS_DIR}")
NAMES cblas.h list(APPEND _inc_env "${ENV_CBLAS_DIR}/include")
HINTS ${CBLAS_DIR} list(APPEND _inc_env "${ENV_CBLAS_DIR}/include/cblas")
PATH_SUFFIXES "include" "include/cblas")
else() else()
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)
set(CBLAS_cblas.h_DIRS "CBLAS_cblas.h_DIRS-NOTFOUND") set(CBLAS_cblas.h_DIRS "CBLAS_cblas.h_DIRS-NOTFOUND")
find_path(CBLAS_cblas.h_DIRS find_path(CBLAS_cblas.h_DIRS
NAMES cblas.h NAMES cblas.h
HINTS ${_inc_env} HINTS ${CBLAS_INCDIR})
PATH_SUFFIXES "cblas") 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()
endif() endif()
endif() mark_as_advanced(CBLAS_cblas.h_DIRS)
mark_as_advanced(CBLAS_cblas.h_DIRS)
# If found, add path to cmake variable
# If found, add path to cmake variable # ------------------------------------
# ------------------------------------ if (CBLAS_cblas.h_DIRS)
if (CBLAS_cblas.h_DIRS) set(CBLAS_INCLUDE_DIRS "${CBLAS_cblas.h_DIRS}")
set(CBLAS_INCLUDE_DIRS "${CBLAS_cblas.h_DIRS}") else ()
else () set(CBLAS_INCLUDE_DIRS "CBLAS_INCLUDE_DIRS-NOTFOUND")
set(CBLAS_INCLUDE_DIRS "CBLAS_INCLUDE_DIRS-NOTFOUND") if(NOT CBLAS_FIND_QUIETLY)
if(NOT CBLAS_FIND_QUIETLY) message(STATUS "Looking for cblas -- cblas.h not found")
message(STATUS "Looking for cblas -- cblas.h not found") endif()
endif() endif()
endif()
# Looking for lib # Looking for lib
# --------------- # ---------------
# Add system library paths to search lib # Add system library paths to search lib
# -------------------------------------- # --------------------------------------
unset(_lib_env) unset(_lib_env)
set(ENV_CBLAS_LIBDIR "$ENV{CBLAS_LIBDIR}") set(ENV_CBLAS_LIBDIR "$ENV{CBLAS_LIBDIR}")
if(ENV_CBLAS_LIBDIR) if(ENV_CBLAS_LIBDIR)
list(APPEND _lib_env "${ENV_CBLAS_LIBDIR}") list(APPEND _lib_env "${ENV_CBLAS_LIBDIR}")
elseif(ENV_CBLAS_DIR) elseif(ENV_CBLAS_DIR)
list(APPEND _lib_env "${ENV_CBLAS_DIR}") list(APPEND _lib_env "${ENV_CBLAS_DIR}")
list(APPEND _lib_env "${ENV_CBLAS_DIR}/lib") list(APPEND _lib_env "${ENV_CBLAS_DIR}/lib")
else()
if(WIN32)
string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
else() else()
if(APPLE) if(WIN32)
string(REPLACE ":" ";" _lib_env "$ENV{DYLD_LIBRARY_PATH}") string(REPLACE ":" ";" _lib_env "$ENV{LIB}")
else() else()
string(REPLACE ":" ";" _lib_env "$ENV{LD_LIBRARY_PATH}") 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}")
endif() endif()
list(APPEND _lib_env "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
list(APPEND _lib_env "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
endif() endif()
endif() list(REMOVE_DUPLICATES _lib_env)
list(REMOVE_DUPLICATES _lib_env)
# Try to find the cblas lib in the given paths # Try to find the cblas lib in the given paths
# ---------------------------------------------- # ----------------------------------------------
# call cmake macro to find the lib path # call cmake macro to find the lib path
if(CBLAS_LIBDIR) if(CBLAS_LIBDIR)
set(CBLAS_cblas_LIBRARY "CBLAS_cblas_LIBRARY-NOTFOUND")
find_library(CBLAS_cblas_LIBRARY
NAMES cblas
HINTS ${CBLAS_LIBDIR})
else()
if(CBLAS_DIR)
set(CBLAS_cblas_LIBRARY "CBLAS_cblas_LIBRARY-NOTFOUND") set(CBLAS_cblas_LIBRARY "CBLAS_cblas_LIBRARY-NOTFOUND")
find_library(CBLAS_cblas_LIBRARY find_library(CBLAS_cblas_LIBRARY
NAMES cblas NAMES cblas
HINTS ${CBLAS_DIR} HINTS ${CBLAS_LIBDIR})
PATH_SUFFIXES lib lib32 lib64)
else() else()
set(CBLAS_cblas_LIBRARY "CBLAS_cblas_LIBRARY-NOTFOUND") if(CBLAS_DIR)
find_library(CBLAS_cblas_LIBRARY set(CBLAS_cblas_LIBRARY "CBLAS_cblas_LIBRARY-NOTFOUND")
NAMES cblas find_library(CBLAS_cblas_LIBRARY
HINTS ${_lib_env}) NAMES cblas
endif() HINTS ${CBLAS_DIR}
endif() PATH_SUFFIXES lib lib32 lib64)
mark_as_advanced(CBLAS_cblas_LIBRARY) else()
set(CBLAS_cblas_LIBRARY "CBLAS_cblas_LIBRARY-NOTFOUND")
# If found, add path to cmake variable find_library(CBLAS_cblas_LIBRARY
# ------------------------------------ NAMES cblas
if (CBLAS_cblas_LIBRARY) HINTS ${_lib_env})
get_filename_component(cblas_lib_path "${CBLAS_cblas_LIBRARY}" PATH) endif()
# 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 () 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)
# check a function to validate the find endif (CBLAS_STANDALONE OR NOT CBLAS_WORKS)
if(CBLAS_LIBRARIES)
set(REQUIRED_INCDIRS) # check a function to validate the find
set(REQUIRED_LDFLAGS) if(CBLAS_LIBRARIES)
set(REQUIRED_LIBDIRS)
set(REQUIRED_LIBS)
# CBLAS set(REQUIRED_INCDIRS)
if (CBLAS_INCLUDE_DIRS) set(REQUIRED_LDFLAGS)
set(REQUIRED_INCDIRS "${CBLAS_INCLUDE_DIRS}") set(REQUIRED_LIBDIRS)
endif() set(REQUIRED_LIBS)
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()
if (BLAS_LIBRARY_DIRS)
list(APPEND REQUIRED_LIBDIRS "${BLAS_LIBRARY_DIRS}")
endif()
list(APPEND REQUIRED_LIBS "${BLAS_LIBRARIES}")
if (BLAS_LINKER_FLAGS)
list(APPEND REQUIRED_LDFLAGS "${BLAS_LINKER_FLAGS}")
endif()
# set required libraries for link # CBLAS
set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}") if (CBLAS_INCLUDE_DIRS)
set(CMAKE_REQUIRED_LIBRARIES) set(REQUIRED_INCDIRS "${CBLAS_INCLUDE_DIRS}")
list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LDFLAGS}") endif()
foreach(lib_dir ${REQUIRED_LIBDIRS}) if (CBLAS_CFLAGS_OTHER)
list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}") list(APPEND REQUIRED_FLAGS "${CBLAS_CFLAGS_OTHER}")
endforeach() endif()
list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}") if (CBLAS_LDFLAGS_OTHER)
string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") list(APPEND REQUIRED_LDFLAGS "${CBLAS_LDFLAGS_OTHER}")
endif()
# test link if (CBLAS_LIBRARY_DIRS)
unset(CBLAS_WORKS CACHE) set(REQUIRED_LIBDIRS "${CBLAS_LIBRARY_DIRS}")
include(CheckFunctionExists) endif()
check_function_exists(cblas_dscal CBLAS_WORKS) set(REQUIRED_LIBS "${CBLAS_LIBRARIES}")
mark_as_advanced(CBLAS_WORKS) # BLAS
if (BLAS_INCLUDE_DIRS)
if(CBLAS_WORKS) list(APPEND REQUIRED_INCDIRS "${BLAS_INCLUDE_DIRS}")
endif()
# Check for faster complex GEMM routine if (BLAS_COMPILER_FLAGS)
# (only C/Z, no S/D version) list(APPEND REQUIRED_FLAGS "${BLAS_COMPILER_FLAGS}")
check_function_exists(cblas_zgemm3m CBLAS_ZGEMM3M_FOUND) endif()
if ( CBLAS_ZGEMM3M_FOUND ) if (BLAS_LINKER_FLAGS)
add_definitions(-DCBLAS_HAS_ZGEMM3M -DCBLAS_HAS_CGEMM3M) list(APPEND REQUIRED_LDFLAGS "${BLAS_LINKER_FLAGS}")
endif() endif()
if (BLAS_LIBRARY_DIRS)
list(APPEND REQUIRED_LIBDIRS "${BLAS_LIBRARY_DIRS}")
endif()
list(APPEND REQUIRED_LIBS "${BLAS_LIBRARIES}")
# save link with dependencies # set required libraries for link
set(CBLAS_LIBRARIES_DEP "${REQUIRED_LIBS}") set(CMAKE_REQUIRED_INCLUDES "${REQUIRED_INCDIRS}")
set(CBLAS_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}") set(CMAKE_REQUIRED_FLAGS "${REQUIRED_FLAGS}")
set(CBLAS_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}") set(CMAKE_REQUIRED_LIBRARIES)
set(CBLAS_LINKER_FLAGS "${REQUIRED_LDFLAGS}") list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LDFLAGS}")
list(REMOVE_DUPLICATES CBLAS_LIBRARY_DIRS_DEP) foreach(lib_dir ${REQUIRED_LIBDIRS})
list(REMOVE_DUPLICATES CBLAS_INCLUDE_DIRS_DEP) list(APPEND CMAKE_REQUIRED_LIBRARIES "-L${lib_dir}")
list(REMOVE_DUPLICATES CBLAS_LINKER_FLAGS) endforeach()
else() list(APPEND CMAKE_REQUIRED_LIBRARIES "${REQUIRED_LIBS}")
if(NOT CBLAS_FIND_QUIETLY) string(REGEX REPLACE "^ -" "-" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
message(STATUS "Looking for cblas : test of cblas_dscal with cblas and blas libraries fails")
message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}") # test link
message(STATUS "CMAKE_REQUIRED_INCLUDES: ${CMAKE_REQUIRED_INCLUDES}") unset(CBLAS_WORKS CACHE)
message(STATUS "Check in CMakeFiles/CMakeError.log to figure out why it fails") include(CheckFunctionExists)
endif() 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)