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/). |
---|
4 | # |
---|
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). |
---|
7 | # |
---|
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 |
---|
15 | # LAPACK95_LIBRARIES - uncached list of libraries (using full path name) to |
---|
16 | # link against to use LAPACK95 |
---|
17 | # LAPACK95_FOUND - set to true if a library implementing the LAPACK f95 |
---|
18 | # interface is found |
---|
19 | # BLA_STATIC if set on this determines what kind of linkage we do (static) |
---|
20 | # BLA_VENDOR if set checks only the specified vendor, if not set checks |
---|
21 | # all the possibilities |
---|
22 | # BLA_F95 if set on tries to find the f95 interfaces for BLAS/LAPACK |
---|
23 | ### List of vendors (BLA_VENDOR) valid in this module |
---|
24 | ## Intel(mkl), ACML,Apple, NAS, Generic |
---|
25 | |
---|
26 | #============================================================================= |
---|
27 | # Copyright 2007-2009 Kitware, Inc. |
---|
28 | # |
---|
29 | # Distributed under the OSI-approved BSD License (the "License"); |
---|
30 | # see accompanying file Copyright.txt for details. |
---|
31 | # |
---|
32 | # This software is distributed WITHOUT ANY WARRANTY; without even the |
---|
33 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
---|
34 | # See the License for more information. |
---|
35 | #============================================================================= |
---|
36 | # (To distribute this file outside of CMake, substitute the full |
---|
37 | # License text for the above reference.) |
---|
38 | # |
---|
39 | # YIL Comment: Added this file here because it is broken in the version distributed |
---|
40 | # with cmake 2.8 |
---|
41 | |
---|
42 | set(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) |
---|
43 | |
---|
44 | get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES) |
---|
45 | if (NOT _LANGUAGES_ MATCHES Fortran) |
---|
46 | include(CheckFunctionExists) |
---|
47 | else (NOT _LANGUAGES_ MATCHES Fortran) |
---|
48 | include(CheckFortranFunctionExists) |
---|
49 | endif (NOT _LANGUAGES_ MATCHES Fortran) |
---|
50 | |
---|
51 | set(LAPACK_FOUND FALSE) |
---|
52 | set(LAPACK95_FOUND FALSE) |
---|
53 | |
---|
54 | # TODO: move this stuff to separate module |
---|
55 | |
---|
56 | macro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas _threads) |
---|
57 | # This macro checks for the existence of the combination of fortran libraries |
---|
58 | # given by _list. If the combination is found, this macro checks (using the |
---|
59 | # Check_Fortran_Function_Exists macro) whether can link against that library |
---|
60 | # combination using the name of a routine given by _name using the linker |
---|
61 | # flags given by _flags. If the combination of libraries is found and passes |
---|
62 | # the link test, LIBRARIES is set to the list of complete library paths that |
---|
63 | # have been found. Otherwise, LIBRARIES is set to FALSE. |
---|
64 | |
---|
65 | # N.B. _prefix is the prefix applied to the names of all cached variables that |
---|
66 | # are generated internally and marked advanced by this macro. |
---|
67 | |
---|
68 | set(_libraries_work TRUE) |
---|
69 | set(${LIBRARIES}) |
---|
70 | set(_combined_name) |
---|
71 | if (NOT _libdir) |
---|
72 | if (WIN32) |
---|
73 | set(_libdir ENV LIB) |
---|
74 | elseif (APPLE) |
---|
75 | set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH) |
---|
76 | else () |
---|
77 | set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH) |
---|
78 | endif () |
---|
79 | endif () |
---|
80 | foreach(_library ${_list}) |
---|
81 | set(_combined_name ${_combined_name}_${_library}) |
---|
82 | |
---|
83 | if(_libraries_work) |
---|
84 | if (BLA_STATIC) |
---|
85 | if (WIN32) |
---|
86 | set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) |
---|
87 | endif ( WIN32 ) |
---|
88 | if (APPLE) |
---|
89 | set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) |
---|
90 | else (APPLE) |
---|
91 | set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) |
---|
92 | endif (APPLE) |
---|
93 | else (BLA_STATIC) |
---|
94 | if (CMAKE_SYSTEM_NAME STREQUAL "Linux") |
---|
95 | # for ubuntu's libblas3gf and liblapack3gf packages |
---|
96 | set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf) |
---|
97 | endif () |
---|
98 | endif (BLA_STATIC) |
---|
99 | find_library(${_prefix}_${_library}_LIBRARY |
---|
100 | NAMES ${_library} |
---|
101 | PATHS ${_libdir} |
---|
102 | ) |
---|
103 | mark_as_advanced(${_prefix}_${_library}_LIBRARY) |
---|
104 | set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY}) |
---|
105 | set(_libraries_work ${${_prefix}_${_library}_LIBRARY}) |
---|
106 | endif(_libraries_work) |
---|
107 | endforeach(_library ${_list}) |
---|
108 | |
---|
109 | if(_libraries_work) |
---|
110 | # Test this combination of libraries. |
---|
111 | if(UNIX AND BLA_STATIC) |
---|
112 | set(CMAKE_REQUIRED_LIBRARIES ${_flags} "-Wl,--start-group ${${LIBRARIES}} ${_blas};-Wl,--end-group" ${_threads}) |
---|
113 | else(UNIX AND BLA_STATIC) |
---|
114 | set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas} ${_threads}) |
---|
115 | endif(UNIX AND BLA_STATIC) |
---|
116 | if (NOT _LANGUAGES_ MATCHES Fortran) |
---|
117 | check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS) |
---|
118 | else (NOT _LANGUAGES_ MATCHES Fortran) |
---|
119 | check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS) |
---|
120 | endif (NOT _LANGUAGES_ MATCHES Fortran) |
---|
121 | set(CMAKE_REQUIRED_LIBRARIES) |
---|
122 | mark_as_advanced(${_prefix}${_combined_name}_WORKS) |
---|
123 | set(_libraries_work ${${_prefix}${_combined_name}_WORKS}) |
---|
124 | endif(_libraries_work) |
---|
125 | |
---|
126 | if(_libraries_work) |
---|
127 | set(${LIBRARIES} ${${LIBRARIES}} ${_blas}) |
---|
128 | else(_libraries_work) |
---|
129 | set(${LIBRARIES} FALSE) |
---|
130 | endif(_libraries_work) |
---|
131 | |
---|
132 | endmacro(Check_Lapack_Libraries) |
---|
133 | |
---|
134 | |
---|
135 | set(LAPACK_LINKER_FLAGS) |
---|
136 | set(LAPACK_LIBRARIES) |
---|
137 | set(LAPACK95_LIBRARIES) |
---|
138 | |
---|
139 | |
---|
140 | if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) |
---|
141 | find_package(BLAS) |
---|
142 | else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) |
---|
143 | find_package(BLAS REQUIRED) |
---|
144 | endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) |
---|
145 | |
---|
146 | |
---|
147 | if(BLAS_FOUND) |
---|
148 | set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS}) |
---|
149 | if ($ENV{BLA_VENDOR} MATCHES ".+") |
---|
150 | set(BLA_VENDOR $ENV{BLA_VENDOR}) |
---|
151 | else ($ENV{BLA_VENDOR} MATCHES ".+") |
---|
152 | if(NOT BLA_VENDOR) |
---|
153 | set(BLA_VENDOR "All") |
---|
154 | endif(NOT BLA_VENDOR) |
---|
155 | endif ($ENV{BLA_VENDOR} MATCHES ".+") |
---|
156 | |
---|
157 | if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All") |
---|
158 | if(NOT LAPACK_LIBRARIES) |
---|
159 | check_lapack_libraries( |
---|
160 | LAPACK_LIBRARIES |
---|
161 | LAPACK |
---|
162 | cheev |
---|
163 | "" |
---|
164 | "goto2" |
---|
165 | "${BLAS_LIBRARIES}" |
---|
166 | "" |
---|
167 | ) |
---|
168 | endif(NOT LAPACK_LIBRARIES) |
---|
169 | endif (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All") |
---|
170 | |
---|
171 | |
---|
172 | #acml lapack |
---|
173 | if (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All") |
---|
174 | if (BLAS_LIBRARIES MATCHES ".+acml.+") |
---|
175 | set (LAPACK_LIBRARIES ${BLAS_LIBRARIES}) |
---|
176 | endif () |
---|
177 | endif () |
---|
178 | |
---|
179 | # Apple LAPACK library? |
---|
180 | if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All") |
---|
181 | if(NOT LAPACK_LIBRARIES) |
---|
182 | check_lapack_libraries( |
---|
183 | LAPACK_LIBRARIES |
---|
184 | LAPACK |
---|
185 | cheev |
---|
186 | "" |
---|
187 | "Accelerate" |
---|
188 | "${BLAS_LIBRARIES}" |
---|
189 | "" |
---|
190 | ) |
---|
191 | endif(NOT LAPACK_LIBRARIES) |
---|
192 | endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All") |
---|
193 | if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All") |
---|
194 | if ( NOT LAPACK_LIBRARIES ) |
---|
195 | check_lapack_libraries( |
---|
196 | LAPACK_LIBRARIES |
---|
197 | LAPACK |
---|
198 | cheev |
---|
199 | "" |
---|
200 | "vecLib" |
---|
201 | "${BLAS_LIBRARIES}" |
---|
202 | "" |
---|
203 | ) |
---|
204 | endif ( NOT LAPACK_LIBRARIES ) |
---|
205 | endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All") |
---|
206 | # Generic LAPACK library? |
---|
207 | if (BLA_VENDOR STREQUAL "Generic" OR |
---|
208 | BLA_VENDOR STREQUAL "ATLAS" OR |
---|
209 | BLA_VENDOR STREQUAL "All") |
---|
210 | if ( NOT LAPACK_LIBRARIES ) |
---|
211 | check_lapack_libraries( |
---|
212 | LAPACK_LIBRARIES |
---|
213 | LAPACK |
---|
214 | cheev |
---|
215 | "" |
---|
216 | "lapack" |
---|
217 | "${BLAS_LIBRARIES}" |
---|
218 | "" |
---|
219 | ) |
---|
220 | endif ( NOT LAPACK_LIBRARIES ) |
---|
221 | endif () |
---|
222 | #intel lapack |
---|
223 | if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All") |
---|
224 | if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX) |
---|
225 | if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) |
---|
226 | find_PACKAGE(Threads) |
---|
227 | else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) |
---|
228 | find_package(Threads REQUIRED) |
---|
229 | endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) |
---|
230 | if (BLA_F95) |
---|
231 | if(NOT LAPACK95_LIBRARIES) |
---|
232 | check_lapack_libraries( |
---|
233 | LAPACK95_LIBRARIES |
---|
234 | LAPACK |
---|
235 | cheev |
---|
236 | "" |
---|
237 | "mkl_lapack95" |
---|
238 | "${BLAS95_LIBRARIES}" |
---|
239 | "${CMAKE_THREAD_LIBS_INIT}" |
---|
240 | ) |
---|
241 | endif(NOT LAPACK95_LIBRARIES) |
---|
242 | else(BLA_F95) |
---|
243 | if(NOT LAPACK_LIBRARIES) |
---|
244 | check_lapack_libraries( |
---|
245 | LAPACK_LIBRARIES |
---|
246 | LAPACK |
---|
247 | cheev |
---|
248 | "" |
---|
249 | "mkl_lapack" |
---|
250 | "${BLAS_LIBRARIES}" |
---|
251 | "${CMAKE_THREAD_LIBS_INIT}" |
---|
252 | ) |
---|
253 | endif(NOT LAPACK_LIBRARIES) |
---|
254 | endif(BLA_F95) |
---|
255 | endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX) |
---|
256 | endif(BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All") |
---|
257 | else(BLAS_FOUND) |
---|
258 | message(STATUS "LAPACK requires BLAS") |
---|
259 | endif(BLAS_FOUND) |
---|
260 | |
---|
261 | if(BLA_F95) |
---|
262 | if(LAPACK95_LIBRARIES) |
---|
263 | set(LAPACK95_FOUND TRUE) |
---|
264 | else(LAPACK95_LIBRARIES) |
---|
265 | set(LAPACK95_FOUND FALSE) |
---|
266 | endif(LAPACK95_LIBRARIES) |
---|
267 | if(NOT LAPACK_FIND_QUIETLY) |
---|
268 | if(LAPACK95_FOUND) |
---|
269 | message(STATUS "A library with LAPACK95 API found.") |
---|
270 | else(LAPACK95_FOUND) |
---|
271 | if(LAPACK_FIND_REQUIRED) |
---|
272 | message(FATAL_ERROR |
---|
273 | "A required library with LAPACK95 API not found. Please specify library location." |
---|
274 | ) |
---|
275 | else(LAPACK_FIND_REQUIRED) |
---|
276 | message(STATUS |
---|
277 | "A library with LAPACK95 API not found. Please specify library location." |
---|
278 | ) |
---|
279 | endif(LAPACK_FIND_REQUIRED) |
---|
280 | endif(LAPACK95_FOUND) |
---|
281 | endif(NOT LAPACK_FIND_QUIETLY) |
---|
282 | set(LAPACK_FOUND "${LAPACK95_FOUND}") |
---|
283 | set(LAPACK_LIBRARIES "${LAPACK95_LIBRARIES}") |
---|
284 | else(BLA_F95) |
---|
285 | if(LAPACK_LIBRARIES) |
---|
286 | set(LAPACK_FOUND TRUE) |
---|
287 | else(LAPACK_LIBRARIES) |
---|
288 | set(LAPACK_FOUND FALSE) |
---|
289 | endif(LAPACK_LIBRARIES) |
---|
290 | |
---|
291 | if(NOT LAPACK_FIND_QUIETLY) |
---|
292 | if(LAPACK_FOUND) |
---|
293 | message(STATUS "A library with LAPACK API found.") |
---|
294 | else(LAPACK_FOUND) |
---|
295 | if(LAPACK_FIND_REQUIRED) |
---|
296 | message(FATAL_ERROR |
---|
297 | "A required library with LAPACK API not found. Please specify library location." |
---|
298 | ) |
---|
299 | else(LAPACK_FIND_REQUIRED) |
---|
300 | message(STATUS |
---|
301 | "A library with LAPACK API not found. Please specify library location." |
---|
302 | ) |
---|
303 | endif(LAPACK_FIND_REQUIRED) |
---|
304 | endif(LAPACK_FOUND) |
---|
305 | endif(NOT LAPACK_FIND_QUIETLY) |
---|
306 | endif(BLA_F95) |
---|
307 | |
---|
308 | set(CMAKE_FIND_LIBRARY_SUFFIXES ${_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) |
---|