C++QED  v2 Milestone 10
a framework for simulating open quantum dynamics
FindCBLAS.cmake
1 # Copyright 2009-2011 The VOTCA Development Team (http://www.votca.org)
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14 #
15 
16 #! \file
17 #! \ingroup FindPackage
18 #! \brief Find CBLAS
19 #!
20 #! Find the native CBLAS headers and libraries.
21 #!
22 #! - `CBLAS_LIBRARIES` - List of libraries when using cblas.
23 #! - `CBLAS_INCLUDE_DIRS` - List of include directories
24 #! - `CBLAS_FOUND` - True if cblas found.
25 #!
26 #! Cblas can be provided by libblas (Ubuntu), cblas or gslcblas, it will be searched for in
27 #! this order.
28 
29 include(LibFindMacros)
30 
31 if (UNIX)
32  find_package(PkgConfig QUIET)
33  pkg_check_modules(CBLAS_PKGCONF QUIET cblas)
34 endif()
35 
36 if (NOT CBLAS_FOUND)
37 
38 if(CBLAS_PKGCONF_FOUND)
39 
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)
49 
50 else(CBLAS_PKGCONF_FOUND)
51 
52 set(CBLAS_HINT_PATH $ENV{CBLASDIR}/lib $ENV{CBLASDIR}/lib64 $ENV{UIBK_GSL_LIB})
53 
54 # Check if libblas provides cblas (Ubuntu)
55 find_library(BLAS_LIBRARY NAMES blas PATHS ${CBLAS_HINT_PATH})
56 if(BLAS_LIBRARY)
57  include(CheckSymbolExists)
58  set(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARY})
59  check_symbol_exists(cblas_scopy "cblas.h" BLAS_HAS_CBLAS)
60 endif(BLAS_LIBRARY)
61 
62 set(CBLAS_CANDIDATES cblas gslcblas)
63 if(BLAS_HAS_CBLAS)
64  message(STATUS "libblas provides cblas.")
65  set(CBLAS_CANDIDATES blas ${CBLAS_CANDIDATES})
66 endif(BLAS_HAS_CBLAS)
67 
68 find_library(CBLAS_LIBRARY
69  NAMES ${CBLAS_CANDIDATES}
70  PATHS ${CBLAS_HINT_PATH}
71 )
72 endif(CBLAS_PKGCONF_FOUND)
73 
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)
79 
80 find_path(CBLAS_INCLUDE_DIR ${CBLAS_INCLUDE_CANDIDATE} HINTS ${CBLAS_PKGCONF_INCLUDE_DIRS} $ENV{CBLASDIR}/include $ENV{UIBK_GSL_INC})
81 
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.")
88 
89 endif(NOT CBLAS_FOUND)