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 distributed this file outside of CMake, substitute the full
37 # License text for the above reference.)
39 get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES)
40 if(NOT _LANGUAGES_ MATCHES Fortran)
41 if(LAPACK_FIND_REQUIRED)
43 "FindLAPACK is Fortran-only so Fortran must be enabled.")
44 else(LAPACK_FIND_REQUIRED)
45 message(STATUS "Looking for LAPACK... - NOT found (Fortran not enabled)")
47 endif(LAPACK_FIND_REQUIRED)
48 endif(NOT _LANGUAGES_ MATCHES Fortran)
50 include(CheckFortranFunctionExists)
51 set(LAPACK_FOUND FALSE)
52 set(LAPACK95_FOUND FALSE)
54 macro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas _threads)
55 # This macro checks for the existence of the combination of fortran libraries
56 # given by _list. If the combination is found, this macro checks (using the
57 # Check_Fortran_Function_Exists macro) whether can link against that library
58 # combination using the name of a routine given by _name using the linker
59 # flags given by _flags. If the combination of libraries is found and passes
60 # the link test, LIBRARIES is set to the list of complete library paths that
61 # have been found. Otherwise, LIBRARIES is set to FALSE.
63 # N.B. _prefix is the prefix applied to the names of all cached variables that
64 # are generated internally and marked advanced by this macro.
66 set(_libraries_work TRUE)
69 foreach(_library ${_list})
70 set(_combined_name ${_combined_name}_${_library})
75 set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
77 find_library(${_prefix}_${_library}_LIBRARY
85 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so;.dylib")
87 find_library(${_prefix}_${_library}_LIBRARY
89 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
93 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so")
95 find_library(${_prefix}_${_library}_LIBRARY
97 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
101 mark_as_advanced(${_prefix}_${_library}_LIBRARY)
102 set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
103 set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
104 endif(_libraries_work)
105 endforeach(_library ${_list})
108 # Test this combination of libraries.
109 if(UNIX AND BLA_STATIC)
110 set(CMAKE_REQUIRED_LIBRARIES ${_flags} "-Wl,--start-group" ${${LIBRARIES}} ${_blas} "-Wl,--end-group" ${_threads})
111 else(UNIX AND BLA_STATIC)
112 set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas} ${_threads})
113 endif(UNIX AND BLA_STATIC)
114 # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
115 check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
116 set(CMAKE_REQUIRED_LIBRARIES)
117 mark_as_advanced(${_prefix}${_combined_name}_WORKS)
118 set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
119 #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
120 endif(_libraries_work)
123 set(${LIBRARIES} ${${LIBRARIES}} ${_blas})
124 else(_libraries_work)
125 set(${LIBRARIES} FALSE)
126 endif(_libraries_work)
128 endmacro(Check_Lapack_Libraries)
131 set(LAPACK_LINKER_FLAGS)
132 set(LAPACK_LIBRARIES)
133 set(LAPACK95_LIBRARIES)
136 if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
138 else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
139 find_package(BLAS REQUIRED)
140 endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
144 set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
145 if ($ENV{BLA_VENDOR} MATCHES ".+")
146 set(BLA_VENDOR $ENV{BLA_VENDOR})
147 else ($ENV{BLA_VENDOR} MATCHES ".+")
149 set(BLA_VENDOR "All")
150 endif(NOT BLA_VENDOR)
151 endif ($ENV{BLA_VENDOR} MATCHES ".+")
153 if (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
154 if(NOT LAPACK_LIBRARIES)
155 check_lapack_libraries(
164 endif(NOT LAPACK_LIBRARIES)
165 endif (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
167 # Apple LAPACK library?
168 if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
169 if(NOT LAPACK_LIBRARIES)
170 check_lapack_libraries(
179 endif(NOT LAPACK_LIBRARIES)
180 endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
181 if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
182 if ( NOT LAPACK_LIBRARIES )
183 check_lapack_libraries(
192 endif ( NOT LAPACK_LIBRARIES )
193 endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
194 # Generic LAPACK library?
195 if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
196 if ( NOT LAPACK_LIBRARIES )
197 check_lapack_libraries(
206 endif ( NOT LAPACK_LIBRARIES )
207 endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
209 if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
210 if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
211 if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
212 find_PACKAGE(Threads)
213 else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
214 find_package(Threads REQUIRED)
215 endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
217 if(NOT LAPACK95_LIBRARIES)
218 check_lapack_libraries(
224 "${BLAS95_LIBRARIES}"
225 "${CMAKE_THREAD_LIBS_INIT}"
227 endif(NOT LAPACK95_LIBRARIES)
229 if(NOT LAPACK_LIBRARIES)
230 check_lapack_libraries(
237 "${CMAKE_THREAD_LIBS_INIT}"
239 endif(NOT LAPACK_LIBRARIES)
241 endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
242 endif(BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
244 message(STATUS "LAPACK requires BLAS")
248 if(LAPACK95_LIBRARIES)
249 set(LAPACK95_FOUND TRUE)
250 else(LAPACK95_LIBRARIES)
251 set(LAPACK95_FOUND FALSE)
252 endif(LAPACK95_LIBRARIES)
253 if(NOT LAPACK_FIND_QUIETLY)
255 message(STATUS "A library with LAPACK95 API found.")
257 if(LAPACK_FIND_REQUIRED)
259 "A required library with LAPACK95 API not found. Please specify library location."
261 else(LAPACK_FIND_REQUIRED)
263 "A library with LAPACK95 API not found. Please specify library location."
265 endif(LAPACK_FIND_REQUIRED)
266 endif(LAPACK95_FOUND)
267 endif(NOT LAPACK_FIND_QUIETLY)
268 set(LAPACK_FOUND "${LAPACK95_FOUND}")
269 set(LAPACK_LIBRARIES "${LAPACK95_LIBRARIES}")
272 set(LAPACK_FOUND TRUE)
273 else(LAPACK_LIBRARIES)
274 set(LAPACK_FOUND FALSE)
275 endif(LAPACK_LIBRARIES)
277 if(NOT LAPACK_FIND_QUIETLY)
279 message(STATUS "A library with LAPACK API found.")
281 if(LAPACK_FIND_REQUIRED)
283 "A required library with LAPACK API not found. Please specify library location."
285 else(LAPACK_FIND_REQUIRED)
287 "A library with LAPACK API not found. Please specify library location."
289 endif(LAPACK_FIND_REQUIRED)
291 endif(NOT LAPACK_FIND_QUIETLY)