1 # Copyright 2009-2011 The VOTCA Development Team (http://www.votca.org)
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 #! \ingroup FindPackage
20 #! Find the native CBLAS headers and libraries.
22 #! - `CBLAS_LIBRARIES` - List of libraries when using cblas.
23 #! - `CBLAS_INCLUDE_DIRS` - List of include directories
24 #! - `CBLAS_FOUND` - True if cblas found.
26 #! Cblas can be provided by libblas (Ubuntu), cblas or gslcblas, it will be searched for in
29 include(LibFindMacros)
32 find_package(PkgConfig QUIET)
33 pkg_check_modules(CBLAS_PKGCONF QUIET cblas)
38 if(CBLAS_PKGCONF_FOUND)
40 foreach(NEW_CBLAS_LIB ${CBLAS_PKGCONF_LIBRARIES})
41 find_library(LIB_${NEW_CBLAS_LIB} ${NEW_CBLAS_LIB} HINTS ${CBLAS_PKGCONF_LIBRARY_DIRS})
42 if(NOT LIB_${NEW_CBLAS_LIB})
43 message(FATAL_ERROR "Could not find ${NEW_CBLAS_LIB} where pkgconfig said it is: ${CBLAS_PKGCONF_LIBRARY_DIRS}")
44 else(NOT LIB_${NEW_CBLAS_LIB})
45 message(STATUS "Found ${LIB_${NEW_CBLAS_LIB}}.")
46 endif(NOT LIB_${NEW_CBLAS_LIB})
47 set(CBLAS_LIBRARY ${CBLAS_LIBRARY} ${LIB_${NEW_CBLAS_LIB}})
48 endforeach(NEW_CBLAS_LIB)
50 else(CBLAS_PKGCONF_FOUND)
52 set(CBLAS_HINT_PATH $ENV{CBLASDIR}/lib $ENV{CBLASDIR}/lib64 $ENV{UIBK_GSL_LIB})
54 # Check if libblas provides cblas (Ubuntu)
55 find_library(BLAS_LIBRARY NAMES blas PATHS ${CBLAS_HINT_PATH})
57 include(CheckSymbolExists)
58 set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARY})
59 check_symbol_exists(cblas_scopy "cblas.h" BLAS_HAS_CBLAS)
62 set(CBLAS_CANDIDATES cblas gslcblas)
64 message(STATUS "libblas provides cblas.")
65 set(CBLAS_CANDIDATES blas ${CBLAS_CANDIDATES})
68 find_library(CBLAS_LIBRARY
69 NAMES ${CBLAS_CANDIDATES}
70 PATHS ${CBLAS_HINT_PATH}
72 endif(CBLAS_PKGCONF_FOUND)
74 if("${CBLAS_LIBRARY}" MATCHES gslcblas)
75 set(CBLAS_INCLUDE_CANDIDATE gsl/gsl_cblas.h)
76 else("${CBLAS_LIBRARY}" MATCHES gslcblas)
77 set(CBLAS_INCLUDE_CANDIDATE cblas.h)
78 endif("${CBLAS_LIBRARY}" MATCHES gslcblas)
80 find_path(CBLAS_INCLUDE_DIR ${CBLAS_INCLUDE_CANDIDATE} HINTS ${CBLAS_PKGCONF_INCLUDE_DIRS} $ENV{CBLASDIR}/include $ENV{UIBK_GSL_INC})
82 # Set the include dir variables and the libraries and let libfind_process do the rest.
83 # NOTE: Singular variables for this library, plural for libraries this this lib depends on.
84 set(CBLAS_PROCESS_INCLUDES CBLAS_INCLUDE_DIR)
85 set(CBLAS_PROCESS_LIBS CBLAS_LIBRARY)
86 libfind_process(CBLAS)
87 message(STATUS "Using ${CBLAS_LIBRARIES} for cblas.")
89 endif(NOT CBLAS_FOUND)