Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Modules / FindLAPACK.cmake
blobca727af3a4446794c06c93eb4f7667d3bc1f7810
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
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 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)
28     message(FATAL_ERROR
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)")
32     return()
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)
53 set(${LIBRARIES})
54 set(_combined_name)
55 foreach(_library ${_list})
56   set(_combined_name ${_combined_name}_${_library})
58   if(_libraries_work)
59   IF (WIN32)
60     if(BLA_STATIC)
61       set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
62     endif(BLA_STATIC)
63     find_library(${_prefix}_${_library}_LIBRARY
64     NAMES ${_library}
65     PATHS ENV LIB
66     )
67   ENDIF (WIN32)
69   if(APPLE)
70     if(BLA_STATIC)
71       set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so;.dylib")
72     endif(BLA_STATIC)
73     find_library(${_prefix}_${_library}_LIBRARY
74     NAMES ${_library}
75     PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
76     )
77     else(APPLE)
78     if(BLA_STATIC)
79      set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so")
80     endif(BLA_STATIC)
81     find_library(${_prefix}_${_library}_LIBRARY
82     NAMES ${_library}
83     PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
84     )
85     endif(APPLE)
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})
93 if(_libraries_work)
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)
108  if(_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)
123   find_package(BLAS)
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)
129 if(BLAS_FOUND)
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 ".+")
134     if(NOT BLA_VENDOR)
135       set(BLA_VENDOR "All")
136     endif(NOT BLA_VENDOR)
137   endif ($ENV{BLA_VENDOR} MATCHES ".+")
138 #acml lapack
139  if (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
140   if(NOT LAPACK_LIBRARIES)
141    check_lapack_libraries(
142     LAPACK_LIBRARIES
143     LAPACK
144     cheev
145     ""
146     "acml"
147     ""
148     ""
149     )
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(
157   LAPACK_LIBRARIES
158   LAPACK
159   cheev
160   ""
161   "Accelerate"
162   "${BLAS_LIBRARIES}"
163   ""
164   )
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(
170     LAPACK_LIBRARIES
171     LAPACK
172     cheev
173     ""
174     "vecLib"
175     "${BLAS_LIBRARIES}"
176     ""
177     )
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(
184     LAPACK_LIBRARIES
185     LAPACK
186     cheev
187     ""
188     "lapack"
189     "${BLAS_LIBRARIES}"
190     ""
191     )
192   endif ( NOT LAPACK_LIBRARIES )
193 endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
194 #intel lapack
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)
202    if (BLA_F95)
203     if(NOT LAPACK95_LIBRARIES)
204      check_lapack_libraries(
205      LAPACK95_LIBRARIES
206      LAPACK
207      cheev
208      ""
209      "mkl_lapack95"
210      "${BLAS95_LIBRARIES}"
211      "${CMAKE_THREAD_LIBS_INIT}"
212      )
213     endif(NOT LAPACK95_LIBRARIES)
214    else(BLA_F95)
215     if(NOT LAPACK_LIBRARIES)
216      check_lapack_libraries(
217      LAPACK_LIBRARIES
218      LAPACK
219      cheev
220      ""
221      "mkl_lapack"
222      "${BLAS_LIBRARIES}"
223      "${CMAKE_THREAD_LIBS_INIT}"
224      )
225     endif(NOT LAPACK_LIBRARIES)
226    endif(BLA_F95)
227   endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
228  endif(BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
229 else(BLAS_FOUND)
230   message(STATUS "LAPACK requires BLAS")
231 endif(BLAS_FOUND)
233 if(BLA_F95)
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)
240   if(LAPACK95_FOUND)
241     message(STATUS "A library with LAPACK95 API found.")
242   else(LAPACK95_FOUND)
243     if(LAPACK_FIND_REQUIRED)
244       message(FATAL_ERROR
245       "A required library with LAPACK95 API not found. Please specify library location."
246       )
247     else(LAPACK_FIND_REQUIRED)
248       message(STATUS
249       "A library with LAPACK95 API not found. Please specify library location."
250       )
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}")
256 else(BLA_F95)
257  if(LAPACK_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)
264   if(LAPACK_FOUND)
265     message(STATUS "A library with LAPACK API found.")
266   else(LAPACK_FOUND)
267     if(LAPACK_FIND_REQUIRED)
268       message(FATAL_ERROR
269       "A required library with LAPACK API not found. Please specify library location."
270       )
271     else(LAPACK_FIND_REQUIRED)
272       message(STATUS
273       "A library with LAPACK API not found. Please specify library location."
274       )
275     endif(LAPACK_FIND_REQUIRED)
276   endif(LAPACK_FOUND)
277  endif(NOT LAPACK_FIND_QUIETLY)
278 endif(BLA_F95)