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
11 # LAPACK_LINKER_FLAGS - uncached list of required linker flags (excluding -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
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
26 #=============================================================================
27 # Copyright 2007-2009 Kitware, Inc.
29 # Distributed under the OSI-approved BSD License (the "License");
30 # see accompanying file Copyright.txt for details.
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.)
39 set(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
41 get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES)
42 if (NOT _LANGUAGES_ MATCHES Fortran)
43 include(CheckFunctionExists)
44 else (NOT _LANGUAGES_ MATCHES Fortran)
45 include(CheckFortranFunctionExists)
46 endif (NOT _LANGUAGES_ MATCHES Fortran)
48 set(LAPACK_FOUND FALSE)
49 set(LAPACK95_FOUND FALSE)
51 # TODO: move this stuff to separate module
53 macro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas _threads)
54 # This macro checks for the existence of the combination of fortran libraries
55 # given by _list. If the combination is found, this macro checks (using the
56 # Check_Fortran_Function_Exists macro) whether can link against that library
57 # combination using the name of a routine given by _name using the linker
58 # flags given by _flags. If the combination of libraries is found and passes
59 # the link test, LIBRARIES is set to the list of complete library paths that
60 # have been found. Otherwise, LIBRARIES is set to FALSE.
62 # N.B. _prefix is the prefix applied to the names of all cached variables that
63 # are generated internally and marked advanced by this macro.
65 set(_libraries_work TRUE)
72 set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH)
74 set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH)
77 foreach(_library ${_list})
78 set(_combined_name ${_combined_name}_${_library})
83 set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
86 set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
88 set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
91 if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
92 # for ubuntu's libblas3gf and liblapack3gf packages
93 set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
96 find_library(${_prefix}_${_library}_LIBRARY
100 mark_as_advanced(${_prefix}_${_library}_LIBRARY)
101 set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
102 set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
103 endif(_libraries_work)
104 endforeach(_library ${_list})
107 # Test this combination of libraries.
108 if(UNIX AND BLA_STATIC)
109 set(CMAKE_REQUIRED_LIBRARIES ${_flags} "-Wl,--start-group" ${${LIBRARIES}} ${_blas} "-Wl,--end-group" ${_threads})
110 else(UNIX AND BLA_STATIC)
111 set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas} ${_threads})
112 endif(UNIX AND BLA_STATIC)
113 # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
114 if (NOT _LANGUAGES_ MATCHES Fortran)
115 check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
116 else (NOT _LANGUAGES_ MATCHES Fortran)
117 check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
118 endif (NOT _LANGUAGES_ MATCHES Fortran)
119 set(CMAKE_REQUIRED_LIBRARIES)
120 mark_as_advanced(${_prefix}${_combined_name}_WORKS)
121 set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
122 #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
123 endif(_libraries_work)
126 set(${LIBRARIES} ${${LIBRARIES}} ${_blas} ${_threads})
127 else(_libraries_work)
128 set(${LIBRARIES} FALSE)
129 endif(_libraries_work)
131 endmacro(Check_Lapack_Libraries)
134 set(LAPACK_LINKER_FLAGS)
135 set(LAPACK_LIBRARIES)
136 set(LAPACK95_LIBRARIES)
139 if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
141 else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
142 find_package(BLAS REQUIRED)
143 endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
147 set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
148 if ($ENV{BLA_VENDOR} MATCHES ".+")
149 set(BLA_VENDOR $ENV{BLA_VENDOR})
150 else ($ENV{BLA_VENDOR} MATCHES ".+")
152 set(BLA_VENDOR "All")
153 endif(NOT BLA_VENDOR)
154 endif ($ENV{BLA_VENDOR} MATCHES ".+")
156 if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
157 if(NOT LAPACK_LIBRARIES)
158 check_lapack_libraries(
167 endif(NOT LAPACK_LIBRARIES)
168 endif (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
172 if (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All")
173 if (BLAS_LIBRARIES MATCHES ".+acml.+")
174 set (LAPACK_LIBRARIES ${BLAS_LIBRARIES})
178 # Apple LAPACK library?
179 if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
180 if(NOT LAPACK_LIBRARIES)
181 check_lapack_libraries(
190 endif(NOT LAPACK_LIBRARIES)
191 endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
192 if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
193 if ( NOT LAPACK_LIBRARIES )
194 check_lapack_libraries(
203 endif ( NOT LAPACK_LIBRARIES )
204 endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
205 # Generic LAPACK library?
206 if (BLA_VENDOR STREQUAL "Generic" OR
207 BLA_VENDOR STREQUAL "ATLAS" OR
208 BLA_VENDOR STREQUAL "All")
209 if ( NOT LAPACK_LIBRARIES )
210 check_lapack_libraries(
219 endif ( NOT LAPACK_LIBRARIES )
222 if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
226 if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
227 if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
228 find_PACKAGE(Threads)
229 else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
230 find_package(Threads REQUIRED)
231 endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
233 if(NOT LAPACK95_LIBRARIES)
235 check_lapack_libraries(
241 "${BLAS95_LIBRARIES}"
242 "${CMAKE_THREAD_LIBS_INIT};${LM}"
244 endif(NOT LAPACK95_LIBRARIES)
245 if(NOT LAPACK95_LIBRARIES)
247 check_lapack_libraries(
253 "${BLAS95_LIBRARIES}"
254 "${CMAKE_THREAD_LIBS_INIT};${LM}"
256 endif(NOT LAPACK95_LIBRARIES)
258 if(NOT LAPACK_LIBRARIES)
260 check_lapack_libraries(
267 "${CMAKE_THREAD_LIBS_INIT};${LM}"
269 endif(NOT LAPACK_LIBRARIES)
270 if(NOT LAPACK_LIBRARIES)
272 check_lapack_libraries(
279 "${CMAKE_THREAD_LIBS_INIT};${LM}"
281 endif(NOT LAPACK_LIBRARIES)
283 endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
284 endif(BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
286 message(STATUS "LAPACK requires BLAS")
290 if(LAPACK95_LIBRARIES)
291 set(LAPACK95_FOUND TRUE)
292 else(LAPACK95_LIBRARIES)
293 set(LAPACK95_FOUND FALSE)
294 endif(LAPACK95_LIBRARIES)
295 if(NOT LAPACK_FIND_QUIETLY)
297 message(STATUS "A library with LAPACK95 API found.")
299 if(LAPACK_FIND_REQUIRED)
301 "A required library with LAPACK95 API not found. Please specify library location."
303 else(LAPACK_FIND_REQUIRED)
305 "A library with LAPACK95 API not found. Please specify library location."
307 endif(LAPACK_FIND_REQUIRED)
308 endif(LAPACK95_FOUND)
309 endif(NOT LAPACK_FIND_QUIETLY)
310 set(LAPACK_FOUND "${LAPACK95_FOUND}")
311 set(LAPACK_LIBRARIES "${LAPACK95_LIBRARIES}")
314 set(LAPACK_FOUND TRUE)
315 else(LAPACK_LIBRARIES)
316 set(LAPACK_FOUND FALSE)
317 endif(LAPACK_LIBRARIES)
319 if(NOT LAPACK_FIND_QUIETLY)
321 message(STATUS "A library with LAPACK API found.")
323 if(LAPACK_FIND_REQUIRED)
325 "A required library with LAPACK API not found. Please specify library location."
327 else(LAPACK_FIND_REQUIRED)
329 "A library with LAPACK API not found. Please specify library location."
331 endif(LAPACK_FIND_REQUIRED)
333 endif(NOT LAPACK_FIND_QUIETLY)
336 set(CMAKE_FIND_LIBRARY_SUFFIXES ${_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})