Another typo.
[gromacs/rigid-bodies.git] / cmake / FindBLAS.cmake
blobbe41736ae6529fde8b291ed955c542ecaca4b299
1 # - Find BLAS library
2 # This module finds an installed fortran library that implements the BLAS
3 # linear-algebra interface (see http://www.netlib.org/blas/).
4 # The list of libraries searched for is taken
5 # from the autoconf macro file, acx_blas.m4 (distributed at
6 # http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
8 # This module sets the following variables:
9 #  BLAS_FOUND - set to true if a library implementing the BLAS interface
10 #    is found
11 #  BLAS_LINKER_FLAGS - uncached list of required linker flags (excluding -l
12 #    and -L).
13 #  BLAS_LIBRARIES - uncached list of libraries (using full path name) to
14 #    link against to use BLAS
15 #  BLAS95_LIBRARIES - uncached list of libraries (using full path name)
16 #    to link against to use BLAS95 interface
17 #  BLAS95_FOUND - set to true if a library implementing the BLAS f95 interface
18 #    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 possibilities
22 #  BLA_F95     if set on tries to find the f95 interfaces for BLAS/LAPACK
23 ##########
24 ### List of vendors (BLA_VENDOR) valid in this module
25 ##  ATLAS, PhiPACK,CXML,DXML,SunPerf,SCSL,SGIMATH,IBMESSL,Intel10_32 (intel mkl v10 32 bit),Intel10_64lp (intel mkl v10 64 bit,lp thread model, lp64 model),
26 ##  Intel( older versions of mkl 32 and 64 bit), ACML,Apple, NAS, Generic
27 # C/CXX should be enabled to use Intel mkl
29 #=============================================================================
30 # Copyright 2007-2009 Kitware, Inc.
32 # Distributed under the OSI-approved BSD License (the "License");
33 # see accompanying file Copyright.txt for details.
35 # This software is distributed WITHOUT ANY WARRANTY; without even the
36 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
37 # See the License for more information.
38 #=============================================================================
39 # (To distributed this file outside of CMake, substitute the full
40 #  License text for the above reference.)
42 get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES)
43 if(NOT _LANGUAGES_ MATCHES Fortran)
44   if(BLAS_FIND_REQUIRED)
45     message(FATAL_ERROR "FindBLAS is Fortran-only so Fortran must be enabled.")
46   else(BLAS_FIND_REQUIRED)
47     message(STATUS "Looking for BLAS... - NOT found (Fortran not enabled)") #
48     return()
49   endif(BLAS_FIND_REQUIRED)
50 endif(NOT _LANGUAGES_ MATCHES Fortran)
52 include(CheckFortranFunctionExists)
54 macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _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)
67 set(${LIBRARIES})
68 set(_combined_name)
69 foreach(_library ${_list})
70   set(_combined_name ${_combined_name}_${_library})
72   if(_libraries_work)
73    if ( WIN32 )
74     if(BLA_STATIC)
75       set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
76     endif(BLA_STATIC)
77     find_library(${_prefix}_${_library}_LIBRARY
78     NAMES ${_library}
79     PATHS ENV LIB
80     )
81    endif ( WIN32 )
83    if ( APPLE )
84     if(BLA_STATIC)
85      set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
86     endif(BLA_STATIC)
87     find_library(${_prefix}_${_library}_LIBRARY
88     NAMES ${_library}
89     PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
90     )
92    else ( APPLE )
93     if(BLA_STATIC)
94       set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so")
95     endif(BLA_STATIC)
96     find_library(${_prefix}_${_library}_LIBRARY
97     NAMES ${_library}
98     PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
99     )
100    endif( APPLE )
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})
106 if(_libraries_work)
107   # Test this combination of libraries.
108   set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_threads})
109 #  message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
110   check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
111   set(CMAKE_REQUIRED_LIBRARIES)
112   mark_as_advanced(${_prefix}${_combined_name}_WORKS)
113   set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
114 endif(_libraries_work)
115 if(NOT _libraries_work)
116   set(${LIBRARIES} FALSE)
117 endif(NOT _libraries_work)
118 #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
119 endmacro(Check_Fortran_Libraries)
121 set(BLAS_LINKER_FLAGS)
122 set(BLAS_LIBRARIES)
123 set(BLAS95_LIBRARIES)
124 if ($ENV{BLA_VENDOR} MATCHES ".+")
125   set(BLA_VENDOR $ENV{BLA_VENDOR})
126 else ($ENV{BLA_VENDOR} MATCHES ".+")
127   if(NOT BLA_VENDOR)
128     set(BLA_VENDOR "All")
129   endif(NOT BLA_VENDOR)
130 endif ($ENV{BLA_VENDOR} MATCHES ".+")
132 if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
133  if(NOT BLAS_LIBRARIES)
134   # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
135   check_fortran_libraries(
136   BLAS_LIBRARIES
137   BLAS
138   cblas_dgemm
139   ""
140   "cblas;f77blas;atlas"
141   ""
142   )
143  endif(NOT BLAS_LIBRARIES)
144 endif (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
146 # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
147 if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
148  if(NOT BLAS_LIBRARIES)
149   check_fortran_libraries(
150   BLAS_LIBRARIES
151   BLAS
152   sgemm
153   ""
154   "sgemm;dgemm;blas"
155   ""
156   )
157  endif(NOT BLAS_LIBRARIES)
158 endif (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
160 # BLAS in Alpha CXML library?
161 if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
162  if(NOT BLAS_LIBRARIES)
163   check_fortran_libraries(
164   BLAS_LIBRARIES
165   BLAS
166   sgemm
167   ""
168   "cxml"
169   ""
170   )
171  endif(NOT BLAS_LIBRARIES)
172 endif (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
174 # BLAS in Alpha DXML library? (now called CXML, see above)
175 if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
176  if(NOT BLAS_LIBRARIES)
177   check_fortran_libraries(
178   BLAS_LIBRARIES
179   BLAS
180   sgemm
181   ""
182   "dxml"
183   ""
184   )
185  endif(NOT BLAS_LIBRARIES)
186 endif (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
188 # BLAS in Sun Performance library?
189 if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
190  if(NOT BLAS_LIBRARIES)
191   check_fortran_libraries(
192   BLAS_LIBRARIES
193   BLAS
194   sgemm
195   "-xlic_lib=sunperf"
196   "sunperf;sunmath"
197   ""
198   )
199   if(BLAS_LIBRARIES)
200     set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
201   endif(BLAS_LIBRARIES)
202  endif(NOT BLAS_LIBRARIES)
203 endif (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
205 # BLAS in SCSL library?  (SGI/Cray Scientific Library)
206 if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
207  if(NOT BLAS_LIBRARIES)
208   check_fortran_libraries(
209   BLAS_LIBRARIES
210   BLAS
211   sgemm
212   ""
213   "scsl"
214   ""
215   )
216  endif(NOT BLAS_LIBRARIES)
217 endif (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
219 # BLAS in SGIMATH library?
220 if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
221  if(NOT BLAS_LIBRARIES)
222   check_fortran_libraries(
223   BLAS_LIBRARIES
224   BLAS
225   sgemm
226   ""
227   "complib.sgimath"
228   ""
229   )
230  endif(NOT BLAS_LIBRARIES)
231 endif (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
233 # BLAS in IBM ESSL library? (requires generic BLAS lib, too)
234 if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
235  if(NOT BLAS_LIBRARIES)
236   check_fortran_libraries(
237   BLAS_LIBRARIES
238   BLAS
239   sgemm
240   ""
241   "essl;blas"
242   ""
243   )
244  endif(NOT BLAS_LIBRARIES)
245 endif (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
247 #BLAS in acml library?
248 if (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
249  if(NOT BLAS_LIBRARIES)
250   check_fortran_libraries(
251   BLAS_LIBRARIES
252   BLAS
253   sgemm
254   ""
255   "acml"
256   ""
257   )
258  endif(NOT BLAS_LIBRARIES)
259 endif (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
261 # Apple BLAS library?
262 if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
263 if(NOT BLAS_LIBRARIES)
264   check_fortran_libraries(
265   BLAS_LIBRARIES
266   BLAS
267   cblas_dgemm
268   ""
269   "Accelerate"
270   ""
271   )
272  endif(NOT BLAS_LIBRARIES)
273 endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
275 if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
276  if ( NOT BLAS_LIBRARIES )
277     check_fortran_libraries(
278     BLAS_LIBRARIES
279     BLAS
280     cblas_dgemm
281     ""
282     "vecLib"
283     ""
284     )
285  endif ( NOT BLAS_LIBRARIES )
286 endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
287 # Generic BLAS library?
288 if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
289  if(NOT BLAS_LIBRARIES)
290   check_fortran_libraries(
291   BLAS_LIBRARIES
292   BLAS
293   sgemm
294   ""
295   "blas"
296   ""
297   )
298  endif(NOT BLAS_LIBRARIES)
299 endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
301 #BLAS in intel mkl 10 library? (em64t 64bit)
302 if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
303  if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
304   if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
305     find_package(Threads)
306   else(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
307     find_package(Threads REQUIRED)
308   endif(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
309   if (WIN32)
310   if(BLA_F95)
311     if(NOT BLAS95_LIBRARIES)
312     check_fortran_libraries(
313     BLAS95_LIBRARIES
314     BLAS
315     sgemm
316     ""
317     "mkl_blas95;mkl_intel_c;mkl_intel_thread;mkl_core;libguide40"
318     ""
319     )
320     endif(NOT BLAS95_LIBRARIES)
321   else(BLA_F95)
322     if(NOT BLAS_LIBRARIES)
323     check_fortran_libraries(
324     BLAS_LIBRARIES
325     BLAS
326     SGEMM
327     ""
328     "mkl_c_dll;mkl_intel_thread_dll;mkl_core_dll;libguide40"
329     ""
330     )
331     endif(NOT BLAS_LIBRARIES)
332   endif(BLA_F95)
333   else(WIN32)
334   if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
335     if(BLA_F95)
336       if(NOT BLAS95_LIBRARIES)
337       check_fortran_libraries(
338       BLAS95_LIBRARIES
339       BLAS
340       sgemm
341       ""
342       "mkl_blas95;mkl_intel;mkl_intel_thread;mkl_core;guide"
343       "${CMAKE_THREAD_LIBS_INIT}"
344       )
345       endif(NOT BLAS95_LIBRARIES)
346     else(BLA_F95)
347     if(NOT BLAS_LIBRARIES)
348       check_fortran_libraries(
349       BLAS_LIBRARIES
350       BLAS
351       sgemm
352       ""
353       "mkl_intel;mkl_intel_thread;mkl_core;guide"
354       "${CMAKE_THREAD_LIBS_INIT}"
355       )
356       endif(NOT BLAS_LIBRARIES)
357     endif(BLA_F95)
358   endif (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
359   if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
360    if(BLA_F95)
361     if(NOT BLAS95_LIBRARIES)
362       check_fortran_libraries(
363       BLAS95_LIBRARIES
364       BLAS
365       sgemm
366       ""
367       "mkl_blas95;mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
368       "${CMAKE_THREAD_LIBS_INIT}"
369       )
370     endif(NOT BLAS95_LIBRARIES)
371    else(BLA_F95)
372      if(NOT BLAS_LIBRARIES)
373       check_fortran_libraries(
374       BLAS_LIBRARIES
375       BLAS
376       sgemm
377       ""
378       "mkl_intel_lp64;mkl_intel_thread;mkl_core;guide"
379       "${CMAKE_THREAD_LIBS_INIT}"
380       )
381      endif(NOT BLAS_LIBRARIES)
382    endif(BLA_F95)
383   endif (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
384   endif (WIN32)
385   #older vesions of intel mkl libs
386   # BLAS in intel mkl library? (shared)
387   if(NOT BLAS_LIBRARIES)
388     check_fortran_libraries(
389     BLAS_LIBRARIES
390     BLAS
391     sgemm
392     ""
393     "mkl;guide"
394     "${CMAKE_THREAD_LIBS_INIT}"
395     )
396   endif(NOT BLAS_LIBRARIES)
397   #BLAS in intel mkl library? (static, 32bit)
398   if(NOT BLAS_LIBRARIES)
399     check_fortran_libraries(
400     BLAS_LIBRARIES
401     BLAS
402     sgemm
403     ""
404     "mkl_ia32;guide"
405     "${CMAKE_THREAD_LIBS_INIT}"
406     )
407   endif(NOT BLAS_LIBRARIES)
408   #BLAS in intel mkl library? (static, em64t 64bit)
409   if(NOT BLAS_LIBRARIES)
410     check_fortran_libraries(
411     BLAS_LIBRARIES
412     BLAS
413     sgemm
414     ""
415     "mkl_em64t;guide"
416     "${CMAKE_THREAD_LIBS_INIT}"
417     )
418   endif(NOT BLAS_LIBRARIES)
419  endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
420 endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
423 if(BLA_F95)
424  if(BLAS95_LIBRARIES)
425     set(BLAS95_FOUND TRUE)
426   else(BLAS95_LIBRARIES)
427     set(BLAS95_FOUND FALSE)
428   endif(BLAS95_LIBRARIES)
430   if(NOT BLAS_FIND_QUIETLY)
431     if(BLAS95_FOUND)
432       message(STATUS "A library with BLAS95 API found.")
433     else(BLAS95_FOUND)
434       if(BLAS_FIND_REQUIRED)
435         message(FATAL_ERROR
436         "A required library with BLAS95 API not found. Please specify library location.")
437       else(BLAS_FIND_REQUIRED)
438         message(STATUS
439         "A library with BLAS95 API not found. Please specify library location.")
440       endif(BLAS_FIND_REQUIRED)
441     endif(BLAS95_FOUND)
442   endif(NOT BLAS_FIND_QUIETLY)
443   set(BLAS_FOUND TRUE)
444   set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
445 else(BLA_F95)
446   if(BLAS_LIBRARIES)
447     set(BLAS_FOUND TRUE)
448   else(BLAS_LIBRARIES)
449     set(BLAS_FOUND FALSE)
450   endif(BLAS_LIBRARIES)
452   if(NOT BLAS_FIND_QUIETLY)
453     if(BLAS_FOUND)
454       message(STATUS "A library with BLAS API found.")
455     else(BLAS_FOUND)
456       if(BLAS_FIND_REQUIRED)
457         message(FATAL_ERROR
458         "A required library with BLAS API not found. Please specify library location."
459         )
460       else(BLAS_FIND_REQUIRED)
461         message(STATUS
462         "A library with BLAS API not found. Please specify library location."
463         )
464       endif(BLAS_FIND_REQUIRED)
465     endif(BLAS_FOUND)
466   endif(NOT BLAS_FIND_QUIETLY)
467 endif(BLA_F95)