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
17 include(CheckFortranFunctionExists)
18 set(LAPACK_FOUND FALSE)
20 macro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas)
21 # This macro checks for the existence of the combination of fortran libraries
22 # given by _list. If the combination is found, this macro checks (using the
23 # Check_Fortran_Function_Exists macro) whether can link against that library
24 # combination using the name of a routine given by _name using the linker
25 # flags given by _flags. If the combination of libraries is found and passes
26 # the link test, LIBRARIES is set to the list of complete library paths that
27 # have been found. Otherwise, LIBRARIES is set to FALSE.
29 # N.B. _prefix is the prefix applied to the names of all cached variables that
30 # are generated internally and marked advanced by this macro.
32 set(_libraries_work TRUE)
35 foreach(_library ${_list})
36 set(_combined_name ${_combined_name}_${_library})
40 find_library(${_prefix}_${_library}_LIBRARY
42 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
45 find_library(${_prefix}_${_library}_LIBRARY
47 PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
51 mark_as_advanced(${_prefix}_${_library}_LIBRARY)
52 set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
53 set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
54 endif(_libraries_work)
55 endforeach(_library ${_list})
58 # Test this combination of libraries.
59 set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas})
60 #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
61 check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
62 set(CMAKE_REQUIRED_LIBRARIES)
63 mark_as_advanced(${_prefix}${_combined_name}_WORKS)
64 set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
65 #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
66 endif(_libraries_work)
68 if(NOT _libraries_work)
69 set(${LIBRARIES} FALSE)
70 endif(NOT _libraries_work)
72 endmacro(Check_Lapack_Libraries)
75 set(LAPACK_LINKER_FLAGS)
79 if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
81 else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
82 find_package(BLAS REQUIRED)
83 endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
86 set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
89 if(NOT LAPACK_LIBRARIES)
91 check_lapack_libraries(
99 endif(NOT LAPACK_LIBRARIES)
104 if(NOT LAPACK_LIBRARIES)
106 check_lapack_libraries(
114 endif(NOT LAPACK_LIBRARIES)
117 # Apple LAPACK library?
118 if(NOT LAPACK_LIBRARIES)
119 check_lapack_libraries(
127 endif(NOT LAPACK_LIBRARIES)
129 if ( NOT LAPACK_LIBRARIES )
130 check_lapack_libraries(
138 endif ( NOT LAPACK_LIBRARIES )
144 # Generic LAPACK library?
145 if ( NOT LAPACK_LIBRARIES )
146 check_lapack_libraries(
154 endif ( NOT LAPACK_LIBRARIES )
157 message(STATUS "LAPACK requires BLAS")
161 set(LAPACK_FOUND TRUE)
162 else(LAPACK_LIBRARIES)
163 set(LAPACK_FOUND FALSE)
164 endif(LAPACK_LIBRARIES)
166 if(NOT LAPACK_FIND_QUIETLY)
168 message(STATUS "A library with LAPACK API found.")
170 if(LAPACK_FIND_REQUIRED)
172 "A required library with LAPACK API not found. Please specify library location."
174 else(LAPACK_FIND_REQUIRED)
176 "A library with LAPACK API not found. Please specify library location."
178 endif(LAPACK_FIND_REQUIRED)
180 endif(NOT LAPACK_FIND_QUIETLY)