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 posibilities
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 get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES)
26 if(NOT _LANGUAGES_ MATCHES Fortran)
27 if(LAPACK_FIND_REQUIRED)
29 "FindLAPACK is Fortran-only so Fortran must be enabled.")
30 else(LAPACK_FIND_REQUIRED)
31 message(STATUS "Looking for LAPACK... - NOT found (Fortran not enabled)")
33 endif(LAPACK_FIND_REQUIRED)
34 endif(NOT _LANGUAGES_ MATCHES Fortran)
36 include(CheckFortranFunctionExists)
37 set(LAPACK_FOUND FALSE)
38 set(LAPACK95_FOUND FALSE)
40 macro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas _threads)
41 # This macro checks for the existence of the combination of fortran libraries
42 # given by _list. If the combination is found, this macro checks (using the
43 # Check_Fortran_Function_Exists macro) whether can link against that library
44 # combination using the name of a routine given by _name using the linker
45 # flags given by _flags. If the combination of libraries is found and passes
46 # the link test, LIBRARIES is set to the list of complete library paths that
47 # have been found. Otherwise, LIBRARIES is set to FALSE.
49 # N.B. _prefix is the prefix applied to the names of all cached variables that
50 # are generated internally and marked advanced by this macro.
52 set(_libraries_work TRUE)
55 foreach(_library ${_list})
56 set(_combined_name ${_combined_name}_${_library})
61 set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
63 find_library(${_prefix}_${_library}_LIBRARY
71 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so;.dylib")
73 find_library(${_prefix}_${_library}_LIBRARY
75 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
79 set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so")
81 find_library(${_prefix}_${_library}_LIBRARY
83 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
87 mark_as_advanced(${_prefix}_${_library}_LIBRARY)
88 set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
89 set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
90 endif(_libraries_work)
91 endforeach(_library ${_list})
94 # Test this combination of libraries.
95 if(UNIX AND BLA_STATIC)
96 set(CMAKE_REQUIRED_LIBRARIES ${_flags} "-Wl,--start-group ${${LIBRARIES}} ${_blas};-Wl,--end-group" ${_threads})
97 else(UNIX AND BLA_STATIC)
98 set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas} ${_threads})
99 endif(UNIX AND BLA_STATIC)
100 # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
101 check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
102 set(CMAKE_REQUIRED_LIBRARIES)
103 mark_as_advanced(${_prefix}${_combined_name}_WORKS)
104 set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
105 #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
106 endif(_libraries_work)
109 set(${LIBRARIES} ${${LIBRARIES}} ${_blas})
110 else(_libraries_work)
111 set(${LIBRARIES} FALSE)
112 endif(_libraries_work)
114 endmacro(Check_Lapack_Libraries)
117 set(LAPACK_LINKER_FLAGS)
118 set(LAPACK_LIBRARIES)
119 set(LAPACK95_LIBRARIES)
122 if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
124 else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
125 find_package(BLAS REQUIRED)
126 endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
130 set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
131 if ($ENV{BLA_VENDOR} MATCHES ".+")
132 set(BLA_VENDOR $ENV{BLA_VENDOR})
133 else ($ENV{BLA_VENDOR} MATCHES ".+")
135 set(BLA_VENDOR "All")
136 endif(NOT BLA_VENDOR)
137 endif ($ENV{BLA_VENDOR} MATCHES ".+")
139 if (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
140 if(NOT LAPACK_LIBRARIES)
141 check_lapack_libraries(
150 endif(NOT LAPACK_LIBRARIES)
151 endif (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
153 # Apple LAPACK library?
154 if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
155 if(NOT LAPACK_LIBRARIES)
156 check_lapack_libraries(
165 endif(NOT LAPACK_LIBRARIES)
166 endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
167 if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
168 if ( NOT LAPACK_LIBRARIES )
169 check_lapack_libraries(
178 endif ( NOT LAPACK_LIBRARIES )
179 endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
180 # Generic LAPACK library?
181 if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
182 if ( NOT LAPACK_LIBRARIES )
183 check_lapack_libraries(
192 endif ( NOT LAPACK_LIBRARIES )
193 endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
195 if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
196 if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
197 if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
198 find_PACKAGE(Threads)
199 else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
200 find_package(Threads REQUIRED)
201 endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
203 if(NOT LAPACK95_LIBRARIES)
204 check_lapack_libraries(
210 "${BLAS95_LIBRARIES}"
211 "${CMAKE_THREAD_LIBS_INIT}"
213 endif(NOT LAPACK95_LIBRARIES)
215 if(NOT LAPACK_LIBRARIES)
216 check_lapack_libraries(
223 "${CMAKE_THREAD_LIBS_INIT}"
225 endif(NOT LAPACK_LIBRARIES)
227 endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
228 endif(BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
230 message(STATUS "LAPACK requires BLAS")
234 if(LAPACK95_LIBRARIES)
235 set(LAPACK95_FOUND TRUE)
236 else(LAPACK95_LIBRARIES)
237 set(LAPACK95_FOUND FALSE)
238 endif(LAPACK95_LIBRARIES)
239 if(NOT LAPACK_FIND_QUIETLY)
241 message(STATUS "A library with LAPACK95 API found.")
243 if(LAPACK_FIND_REQUIRED)
245 "A required library with LAPACK95 API not found. Please specify library location."
247 else(LAPACK_FIND_REQUIRED)
249 "A library with LAPACK95 API not found. Please specify library location."
251 endif(LAPACK_FIND_REQUIRED)
252 endif(LAPACK95_FOUND)
253 endif(NOT LAPACK_FIND_QUIETLY)
254 set(LAPACK_FOUND "${LAPACK95_FOUND}")
255 set(LAPACK_LIBRARIES "${LAPACK95_LIBRARIES}")
258 set(LAPACK_FOUND TRUE)
259 else(LAPACK_LIBRARIES)
260 set(LAPACK_FOUND FALSE)
261 endif(LAPACK_LIBRARIES)
263 if(NOT LAPACK_FIND_QUIETLY)
265 message(STATUS "A library with LAPACK API found.")
267 if(LAPACK_FIND_REQUIRED)
269 "A required library with LAPACK API not found. Please specify library location."
271 else(LAPACK_FIND_REQUIRED)
273 "A library with LAPACK API not found. Please specify library location."
275 endif(LAPACK_FIND_REQUIRED)
277 endif(NOT LAPACK_FIND_QUIETLY)