Debian Codegraph @

cmake/modules/FindLAPACK.cmake

raw
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 # Redistribution and use in source and binary forms, with or without
30 # modification, are permitted provided that the following conditions
31 # are met:
32 #
33 # 1. Redistributions of source code must retain the copyright
34 # notice, this list of conditions and the following disclaimer.
35 # 2. Redistributions in binary form must reproduce the copyright
36 # notice, this list of conditions and the following disclaimer in the
37 # documentation and/or other materials provided with the distribution.
38 # 3. The name of the author may not be used to endorse or promote products
39 # derived from this software without specific prior written permission.
40 #
41 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
42 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
45 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
50 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 #=============================================================================
52
53 set(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
54
55 get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES)
56 if (NOT _LANGUAGES_ MATCHES Fortran OR NOT CMAKE_Fortran_COMPILER_WORKS)
57 include(CheckFunctionExists)
58 else (NOT _LANGUAGES_ MATCHES Fortran OR NOT CMAKE_Fortran_COMPILER_WORKS)
59 include(CheckFortranFunctionExists)
60 endif (NOT _LANGUAGES_ MATCHES Fortran OR NOT CMAKE_Fortran_COMPILER_WORKS)
61
62 set(LAPACK_FOUND FALSE)
63 set(LAPACK95_FOUND FALSE)
64
65 # TODO: move this stuff to separate module
66
67 macro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas _threads)
68 # This macro checks for the existence of the combination of fortran libraries
69 # given by _list. If the combination is found, this macro checks (using the
70 # Check_Fortran_Function_Exists macro) whether can link against that library
71 # combination using the name of a routine given by _name using the linker
72 # flags given by _flags. If the combination of libraries is found and passes
73 # the link test, LIBRARIES is set to the list of complete library paths that
74 # have been found. Otherwise, LIBRARIES is set to FALSE.
75
76 # N.B. _prefix is the prefix applied to the names of all cached variables that
77 # are generated internally and marked advanced by this macro.
78
79 set(_libraries_work TRUE)
80 set(${LIBRARIES})
81 set(_combined_name)
82 if (NOT _libdir)
83 if (WIN32)
84 set(_libdir ENV LIB)
85 elseif (APPLE)
86 set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH)
87 else ()
88 set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH)
89 endif ()
90 endif ()
91 foreach(_library ${_list})
92 set(_combined_name ${_combined_name}_${_library})
93
94 if(_libraries_work)
95 if (BLA_STATIC)
96 if (WIN32)
97 set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
98 endif ( WIN32 )
99 if (APPLE)
100 set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
101 else (APPLE)
102 set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
103 endif (APPLE)
104 else (BLA_STATIC)
105 if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
106 # for ubuntu's libblas3gf and liblapack3gf packages
107 #set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
108 endif ()
109 endif (BLA_STATIC)
110 find_library(${_prefix}_${_library}_LIBRARY
111 NAMES ${_library}
112 PATHS ${_libdir}
113 )
114 mark_as_advanced(${_prefix}_${_library}_LIBRARY)
115 set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
116 set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
117 endif(_libraries_work)
118 endforeach(_library ${_list})
119
120 if(_libraries_work)
121 # Test this combination of libraries.
122 if(UNIX AND BLA_STATIC)
123 set(CMAKE_REQUIRED_LIBRARIES ${_flags} "-Wl,--start-group" ${${LIBRARIES}} ${_blas} "-Wl,--end-group" ${_threads})
124 else(UNIX AND BLA_STATIC)
125 set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas} ${_threads})
126 endif(UNIX AND BLA_STATIC)
127 # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
128 if (NOT _LANGUAGES_ MATCHES Fortran OR NOT CMAKE_Fortran_COMPILER_WORKS)
129 check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
130 else (NOT _LANGUAGES_ MATCHES Fortran OR NOT CMAKE_Fortran_COMPILER_WORKS)
131 check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
132 endif (NOT _LANGUAGES_ MATCHES Fortran OR NOT CMAKE_Fortran_COMPILER_WORKS)
133 set(CMAKE_REQUIRED_LIBRARIES)
134 mark_as_advanced(${_prefix}${_combined_name}_WORKS)
135 set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
136 #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
137 endif(_libraries_work)
138
139 if(_libraries_work)
140 set(${LIBRARIES} ${${LIBRARIES}} ${_blas} ${_threads})
141 else(_libraries_work)
142 set(${LIBRARIES} FALSE)
143 endif(_libraries_work)
144
145 endmacro(Check_Lapack_Libraries)
146
147
148 set(LAPACK_LINKER_FLAGS)
149 set(LAPACK_LIBRARIES)
150 set(LAPACK95_LIBRARIES)
151
152
153 if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
154 find_package(BLAS)
155 else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
156 find_package(BLAS REQUIRED)
157 endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
158
159
160 if(BLAS_FOUND)
161 set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
162 if ($ENV{BLA_VENDOR} MATCHES ".+")
163 set(BLA_VENDOR $ENV{BLA_VENDOR})
164 else ($ENV{BLA_VENDOR} MATCHES ".+")
165 if(NOT BLA_VENDOR)
166 set(BLA_VENDOR "All")
167 endif(NOT BLA_VENDOR)
168 endif ($ENV{BLA_VENDOR} MATCHES ".+")
169
170 if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
171 if(NOT LAPACK_LIBRARIES)
172 check_lapack_libraries(
173 LAPACK_LIBRARIES
174 LAPACK
175 cheev
176 ""
177 "goto2"
178 "${BLAS_LIBRARIES}"
179 ""
180 )
181 endif(NOT LAPACK_LIBRARIES)
182 endif (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
183
184 if (BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All")
185 if(NOT LAPACK_LIBRARIES)
186 check_lapack_libraries(
187 LAPACK_LIBRARIES
188 LAPACK
189 cheev
190 ""
191 "openblas"
192 "${BLAS_LIBRARIES}"
193 ""
194 )
195 endif(NOT LAPACK_LIBRARIES)
196 endif (BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All")
197
198 #acml lapack
199 if (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All")
200 if (BLAS_LIBRARIES MATCHES ".+acml.+")
201 set (LAPACK_LIBRARIES ${BLAS_LIBRARIES})
202 endif ()
203 endif ()
204
205 # Apple LAPACK library?
206 if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
207 if(NOT LAPACK_LIBRARIES)
208 check_lapack_libraries(
209 LAPACK_LIBRARIES
210 LAPACK
211 cheev
212 ""
213 "Accelerate"
214 "${BLAS_LIBRARIES}"
215 ""
216 )
217 endif(NOT LAPACK_LIBRARIES)
218 endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
219 if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
220 if ( NOT LAPACK_LIBRARIES )
221 check_lapack_libraries(
222 LAPACK_LIBRARIES
223 LAPACK
224 cheev
225 ""
226 "vecLib"
227 "${BLAS_LIBRARIES}"
228 ""
229 )
230 endif ( NOT LAPACK_LIBRARIES )
231 endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
232 # Generic LAPACK library?
233 if (BLA_VENDOR STREQUAL "Generic" OR
234 BLA_VENDOR STREQUAL "ATLAS" OR
235 BLA_VENDOR STREQUAL "All")
236 if ( NOT LAPACK_LIBRARIES )
237 check_lapack_libraries(
238 LAPACK_LIBRARIES
239 LAPACK
240 cheev
241 ""
242 "lapack"
243 "${BLAS_LIBRARIES}"
244 ""
245 )
246 endif ( NOT LAPACK_LIBRARIES )
247 endif ()
248 #intel lapack
249 if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
250 if (NOT WIN32)
251 set(LM "-lm")
252 endif ()
253 if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
254 if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
255 find_PACKAGE(Threads)
256 else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
257 find_package(Threads REQUIRED)
258 endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
259 if (BLA_F95)
260 if(NOT LAPACK95_LIBRARIES)
261 # old
262 check_lapack_libraries(
263 LAPACK95_LIBRARIES
264 LAPACK
265 cheev
266 ""
267 "mkl_lapack95"
268 "${BLAS95_LIBRARIES}"
269 "${CMAKE_THREAD_LIBS_INIT};${LM}"
270 )
271 endif(NOT LAPACK95_LIBRARIES)
272 if(NOT LAPACK95_LIBRARIES)
273 # new >= 10.3
274 check_lapack_libraries(
275 LAPACK95_LIBRARIES
276 LAPACK
277 CHEEV
278 ""
279 "mkl_intel_lp64"
280 "${BLAS95_LIBRARIES}"
281 "${CMAKE_THREAD_LIBS_INIT};${LM}"
282 )
283 endif(NOT LAPACK95_LIBRARIES)
284 else(BLA_F95)
285 if(NOT LAPACK_LIBRARIES)
286 # old
287 check_lapack_libraries(
288 LAPACK_LIBRARIES
289 LAPACK
290 cheev
291 ""
292 "mkl_lapack"
293 "${BLAS_LIBRARIES}"
294 "${CMAKE_THREAD_LIBS_INIT};${LM}"
295 )
296 endif(NOT LAPACK_LIBRARIES)
297 if(NOT LAPACK_LIBRARIES)
298 # new >= 10.3
299 check_lapack_libraries(
300 LAPACK_LIBRARIES
301 LAPACK
302 cheev
303 ""
304 "mkl_gf_lp64"
305 "${BLAS_LIBRARIES}"
306 "${CMAKE_THREAD_LIBS_INIT};${LM}"
307 )
308 endif(NOT LAPACK_LIBRARIES)
309 endif(BLA_F95)
310 endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
311 endif(BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
312 else(BLAS_FOUND)
313 message(STATUS "LAPACK requires BLAS")
314 endif(BLAS_FOUND)
315
316 if(BLA_F95)
317 if(LAPACK95_LIBRARIES)
318 set(LAPACK95_FOUND TRUE)
319 else(LAPACK95_LIBRARIES)
320 set(LAPACK95_FOUND FALSE)
321 endif(LAPACK95_LIBRARIES)
322 if(NOT LAPACK_FIND_QUIETLY)
323 if(LAPACK95_FOUND)
324 message(STATUS "A library with LAPACK95 API found.")
325 else(LAPACK95_FOUND)
326 if(LAPACK_FIND_REQUIRED)
327 message(FATAL_ERROR
328 "A required library with LAPACK95 API not found. Please specify library location."
329 )
330 else(LAPACK_FIND_REQUIRED)
331 message(STATUS
332 "A library with LAPACK95 API not found. Please specify library location."
333 )
334 endif(LAPACK_FIND_REQUIRED)
335 endif(LAPACK95_FOUND)
336 endif(NOT LAPACK_FIND_QUIETLY)
337 set(LAPACK_FOUND "${LAPACK95_FOUND}")
338 set(LAPACK_LIBRARIES "${LAPACK95_LIBRARIES}")
339 else(BLA_F95)
340 if(LAPACK_LIBRARIES)
341 set(LAPACK_FOUND TRUE)
342 else(LAPACK_LIBRARIES)
343 set(LAPACK_FOUND FALSE)
344 endif(LAPACK_LIBRARIES)
345
346 if(NOT LAPACK_FIND_QUIETLY)
347 if(LAPACK_FOUND)
348 message(STATUS "Found LAPACK: ${LAPACK_LIBRARIES}")
349 else(LAPACK_FOUND)
350 if(LAPACK_FIND_REQUIRED)
351 message(FATAL_ERROR
352 "A required library with LAPACK API not found. Please specify library location."
353 )
354 else(LAPACK_FIND_REQUIRED)
355 message(STATUS
356 "A library with LAPACK API not found. Please specify library location."
357 )
358 endif(LAPACK_FIND_REQUIRED)
359 endif(LAPACK_FOUND)
360 endif(NOT LAPACK_FIND_QUIETLY)
361 endif(BLA_F95)
362
363 set(CMAKE_FIND_LIBRARY_SUFFIXES ${_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})