ENH: typo
[cmake.git] / Modules / FindLAPACK.cmake
blob7f838cd6d685480628287828593a2011945395ec
1 # - Find LAPACK library
2 # This module finds an installed fortran library that implements the LAPACK
3 # linear-algebra interface (see http://www.netlib.org/lapack/).
5 # The approach follows that taken for the autoconf macro file, acx_lapack.m4
6 # (distributed at http://ac-archive.sourceforge.net/ac-archive/acx_lapack.html).
8 # This module sets the following variables:
9 #  LAPACK_FOUND - set to true if a library implementing the LAPACK interface
10 #    is found
11 #  LAPACK_LINKER_FLAGS - uncached list of required linker flags (excluding -l
12 #    and -L).
13 #  LAPACK_LIBRARIES - uncached list of libraries (using full path name) to 
14 #    link against to use LAPACK
17 include(CheckFortranFunctionExists)
18 set(LAPACK_FOUND FALSE)
20 macro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas)
21 # This macro checks for the existence of the combination of fortran libraries
22 # given by _list.  If the combination is found, this macro checks (using the 
23 # Check_Fortran_Function_Exists macro) whether can link against that library
24 # combination using the name of a routine given by _name using the linker
25 # flags given by _flags.  If the combination of libraries is found and passes
26 # the link test, LIBRARIES is set to the list of complete library paths that
27 # have been found.  Otherwise, LIBRARIES is set to FALSE.
29 # N.B. _prefix is the prefix applied to the names of all cached variables that
30 # are generated internally and marked advanced by this macro.
32 set(_libraries_work TRUE)
33 set(${LIBRARIES})
34 set(_combined_name)
35 foreach(_library ${_list})
36   set(_combined_name ${_combined_name}_${_library})
38   if(_libraries_work)
39   if(APPLE)
40     find_library(${_prefix}_${_library}_LIBRARY
41     NAMES ${_library}
42     PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
43     )
44     else(APPLE)
45         find_library(${_prefix}_${_library}_LIBRARY
46     NAMES ${_library}
47     PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
48     )
49     endif(APPLE)
51     mark_as_advanced(${_prefix}_${_library}_LIBRARY)
52     set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
53     set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
54   endif(_libraries_work)
55 endforeach(_library ${_list})
57 if(_libraries_work)
58   # Test this combination of libraries.
59   set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas})
60   #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
61   check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
62   set(CMAKE_REQUIRED_LIBRARIES)
63   mark_as_advanced(${_prefix}${_combined_name}_WORKS)
64   set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
65   #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
66 endif(_libraries_work)
68 if(NOT _libraries_work)
69   set(${LIBRARIES} FALSE)
70 endif(NOT _libraries_work)
72 endmacro(Check_Lapack_Libraries)
75 set(LAPACK_LINKER_FLAGS)
76 set(LAPACK_LIBRARIES)
79 if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
80   find_package(BLAS)
81 else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
82   find_package(BLAS REQUIRED)
83 endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
85 if(BLAS_FOUND)
86   set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
88 #intel lapack
89   if(NOT LAPACK_LIBRARIES)
91   check_lapack_libraries(
92   LAPACK_LIBRARIES
93   LAPACK
94   cheev
95   ""
96   "mkl_lapack"
97  "${BLAS_LIBRARIES}"
98   )
99   endif(NOT LAPACK_LIBRARIES)
103 #acml lapack
104   if(NOT LAPACK_LIBRARIES)
106   check_lapack_libraries(
107   LAPACK_LIBRARIES
108   LAPACK
109   cheev
110   ""
111   "acml"
112  "${BLAS_LIBRARIES}"
113   )
114 endif(NOT LAPACK_LIBRARIES)
117 # Apple LAPACK library?
118 if(NOT LAPACK_LIBRARIES)
119   check_lapack_libraries(
120   LAPACK_LIBRARIES
121   LAPACK
122   cheev
123   ""
124   "Accelerate"
125   "${BLAS_LIBRARIES}"
126   )
127   endif(NOT LAPACK_LIBRARIES)
128   
129   if ( NOT LAPACK_LIBRARIES )
130     check_lapack_libraries(
131     LAPACK_LIBRARIES
132     LAPACK
133     cheev
134     ""
135     "vecLib"
136     "${BLAS_LIBRARIES}"
137     )
138   endif ( NOT LAPACK_LIBRARIES )
144 # Generic LAPACK library?
145   if ( NOT LAPACK_LIBRARIES )
146     check_lapack_libraries(
147     LAPACK_LIBRARIES
148     LAPACK
149     cheev
150     ""
151     "lapack"
152     "${BLAS_LIBRARIES}"
153     )
154   endif ( NOT LAPACK_LIBRARIES )
156 else(BLAS_FOUND)
157   message(STATUS "LAPACK requires BLAS")
158 endif(BLAS_FOUND)
160 if(LAPACK_LIBRARIES)
161   set(LAPACK_FOUND TRUE)
162 else(LAPACK_LIBRARIES)
163   set(LAPACK_FOUND FALSE)
164 endif(LAPACK_LIBRARIES)
166 if(NOT LAPACK_FIND_QUIETLY)
167   if(LAPACK_FOUND)
168     message(STATUS "A library with LAPACK API found.")
169   else(LAPACK_FOUND)
170     if(LAPACK_FIND_REQUIRED)
171       message(FATAL_ERROR 
172       "A required library with LAPACK API not found. Please specify library location."
173       )
174     else(LAPACK_FIND_REQUIRED)
175       message(STATUS
176       "A library with LAPACK API not found. Please specify library location."
177       )
178     endif(LAPACK_FIND_REQUIRED)
179   endif(LAPACK_FOUND)
180 endif(NOT LAPACK_FIND_QUIETLY)