FindLAPACK.cmake 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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/).
  4. #
  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).
  7. #
  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 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
  25. #=============================================================================
  26. # Copyright 2007-2009 Kitware, Inc.
  27. #
  28. # Distributed under the OSI-approved BSD License (the "License");
  29. # see accompanying file Copyright.txt for details.
  30. #
  31. # This software is distributed WITHOUT ANY WARRANTY; without even the
  32. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  33. # See the License for more information.
  34. #=============================================================================
  35. # (To distributed this file outside of CMake, substitute the full
  36. # License text for the above reference.)
  37. get_property(_LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES)
  38. if(NOT _LANGUAGES_ MATCHES Fortran)
  39. if(LAPACK_FIND_REQUIRED)
  40. message(FATAL_ERROR
  41. "FindLAPACK is Fortran-only so Fortran must be enabled.")
  42. else(LAPACK_FIND_REQUIRED)
  43. message(STATUS "Looking for LAPACK... - NOT found (Fortran not enabled)")
  44. return()
  45. endif(LAPACK_FIND_REQUIRED)
  46. endif(NOT _LANGUAGES_ MATCHES Fortran)
  47. include(CheckFortranFunctionExists)
  48. set(LAPACK_FOUND FALSE)
  49. set(LAPACK95_FOUND FALSE)
  50. macro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas _threads)
  51. # This macro checks for the existence of the combination of fortran libraries
  52. # given by _list. If the combination is found, this macro checks (using the
  53. # Check_Fortran_Function_Exists macro) whether can link against that library
  54. # combination using the name of a routine given by _name using the linker
  55. # flags given by _flags. If the combination of libraries is found and passes
  56. # the link test, LIBRARIES is set to the list of complete library paths that
  57. # have been found. Otherwise, LIBRARIES is set to FALSE.
  58. # N.B. _prefix is the prefix applied to the names of all cached variables that
  59. # are generated internally and marked advanced by this macro.
  60. set(_libraries_work TRUE)
  61. set(${LIBRARIES})
  62. set(_combined_name)
  63. foreach(_library ${_list})
  64. set(_combined_name ${_combined_name}_${_library})
  65. if(_libraries_work)
  66. IF (WIN32)
  67. if(BLA_STATIC)
  68. set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll")
  69. endif(BLA_STATIC)
  70. find_library(${_prefix}_${_library}_LIBRARY
  71. NAMES ${_library}
  72. PATHS ENV LIB
  73. )
  74. ENDIF (WIN32)
  75. if(APPLE)
  76. if(BLA_STATIC)
  77. set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so;.dylib")
  78. endif(BLA_STATIC)
  79. find_library(${_prefix}_${_library}_LIBRARY
  80. NAMES ${_library}
  81. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
  82. )
  83. else(APPLE)
  84. if(BLA_STATIC)
  85. set(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so")
  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 LD_LIBRARY_PATH
  90. )
  91. endif(APPLE)
  92. mark_as_advanced(${_prefix}_${_library}_LIBRARY)
  93. set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
  94. set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
  95. endif(_libraries_work)
  96. endforeach(_library ${_list})
  97. if(_libraries_work)
  98. # Test this combination of libraries.
  99. if(UNIX AND BLA_STATIC)
  100. set(CMAKE_REQUIRED_LIBRARIES ${_flags} "-Wl,--start-group ${${LIBRARIES}} ${_blas};-Wl,--end-group" ${_threads})
  101. else(UNIX AND BLA_STATIC)
  102. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas} ${_threads})
  103. endif(UNIX AND BLA_STATIC)
  104. # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
  105. check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
  106. set(CMAKE_REQUIRED_LIBRARIES)
  107. mark_as_advanced(${_prefix}${_combined_name}_WORKS)
  108. set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
  109. #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
  110. endif(_libraries_work)
  111. if(_libraries_work)
  112. set(${LIBRARIES} ${${LIBRARIES}} ${_blas})
  113. else(_libraries_work)
  114. set(${LIBRARIES} FALSE)
  115. endif(_libraries_work)
  116. endmacro(Check_Lapack_Libraries)
  117. set(LAPACK_LINKER_FLAGS)
  118. set(LAPACK_LIBRARIES)
  119. set(LAPACK95_LIBRARIES)
  120. if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
  121. find_package(BLAS)
  122. else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
  123. find_package(BLAS REQUIRED)
  124. endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
  125. if(BLAS_FOUND)
  126. set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
  127. if ($ENV{BLA_VENDOR} MATCHES ".+")
  128. set(BLA_VENDOR $ENV{BLA_VENDOR})
  129. else ($ENV{BLA_VENDOR} MATCHES ".+")
  130. if(NOT BLA_VENDOR)
  131. set(BLA_VENDOR "All")
  132. endif(NOT BLA_VENDOR)
  133. endif ($ENV{BLA_VENDOR} MATCHES ".+")
  134. #acml lapack
  135. if (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
  136. if(NOT LAPACK_LIBRARIES)
  137. check_lapack_libraries(
  138. LAPACK_LIBRARIES
  139. LAPACK
  140. cheev
  141. ""
  142. "acml"
  143. ""
  144. ""
  145. )
  146. endif(NOT LAPACK_LIBRARIES)
  147. endif (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "All")
  148. # Apple LAPACK library?
  149. if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  150. if(NOT LAPACK_LIBRARIES)
  151. check_lapack_libraries(
  152. LAPACK_LIBRARIES
  153. LAPACK
  154. cheev
  155. ""
  156. "Accelerate"
  157. "${BLAS_LIBRARIES}"
  158. ""
  159. )
  160. endif(NOT LAPACK_LIBRARIES)
  161. endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  162. if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  163. if ( NOT LAPACK_LIBRARIES )
  164. check_lapack_libraries(
  165. LAPACK_LIBRARIES
  166. LAPACK
  167. cheev
  168. ""
  169. "vecLib"
  170. "${BLAS_LIBRARIES}"
  171. ""
  172. )
  173. endif ( NOT LAPACK_LIBRARIES )
  174. endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  175. # Generic LAPACK library?
  176. if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  177. if ( NOT LAPACK_LIBRARIES )
  178. check_lapack_libraries(
  179. LAPACK_LIBRARIES
  180. LAPACK
  181. cheev
  182. ""
  183. "lapack"
  184. "${BLAS_LIBRARIES}"
  185. ""
  186. )
  187. endif ( NOT LAPACK_LIBRARIES )
  188. endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  189. #intel lapack
  190. if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
  191. if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
  192. if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
  193. find_PACKAGE(Threads)
  194. else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
  195. find_package(Threads REQUIRED)
  196. endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
  197. if (BLA_F95)
  198. if(NOT LAPACK95_LIBRARIES)
  199. check_lapack_libraries(
  200. LAPACK95_LIBRARIES
  201. LAPACK
  202. cheev
  203. ""
  204. "mkl_lapack95"
  205. "${BLAS95_LIBRARIES}"
  206. "${CMAKE_THREAD_LIBS_INIT}"
  207. )
  208. endif(NOT LAPACK95_LIBRARIES)
  209. else(BLA_F95)
  210. if(NOT LAPACK_LIBRARIES)
  211. check_lapack_libraries(
  212. LAPACK_LIBRARIES
  213. LAPACK
  214. cheev
  215. ""
  216. "mkl_lapack"
  217. "${BLAS_LIBRARIES}"
  218. "${CMAKE_THREAD_LIBS_INIT}"
  219. )
  220. endif(NOT LAPACK_LIBRARIES)
  221. endif(BLA_F95)
  222. endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
  223. endif(BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
  224. else(BLAS_FOUND)
  225. message(STATUS "LAPACK requires BLAS")
  226. endif(BLAS_FOUND)
  227. if(BLA_F95)
  228. if(LAPACK95_LIBRARIES)
  229. set(LAPACK95_FOUND TRUE)
  230. else(LAPACK95_LIBRARIES)
  231. set(LAPACK95_FOUND FALSE)
  232. endif(LAPACK95_LIBRARIES)
  233. if(NOT LAPACK_FIND_QUIETLY)
  234. if(LAPACK95_FOUND)
  235. message(STATUS "A library with LAPACK95 API found.")
  236. else(LAPACK95_FOUND)
  237. if(LAPACK_FIND_REQUIRED)
  238. message(FATAL_ERROR
  239. "A required library with LAPACK95 API not found. Please specify library location."
  240. )
  241. else(LAPACK_FIND_REQUIRED)
  242. message(STATUS
  243. "A library with LAPACK95 API not found. Please specify library location."
  244. )
  245. endif(LAPACK_FIND_REQUIRED)
  246. endif(LAPACK95_FOUND)
  247. endif(NOT LAPACK_FIND_QUIETLY)
  248. set(LAPACK_FOUND "${LAPACK95_FOUND}")
  249. set(LAPACK_LIBRARIES "${LAPACK95_LIBRARIES}")
  250. else(BLA_F95)
  251. if(LAPACK_LIBRARIES)
  252. set(LAPACK_FOUND TRUE)
  253. else(LAPACK_LIBRARIES)
  254. set(LAPACK_FOUND FALSE)
  255. endif(LAPACK_LIBRARIES)
  256. if(NOT LAPACK_FIND_QUIETLY)
  257. if(LAPACK_FOUND)
  258. message(STATUS "A library with LAPACK API found.")
  259. else(LAPACK_FOUND)
  260. if(LAPACK_FIND_REQUIRED)
  261. message(FATAL_ERROR
  262. "A required library with LAPACK API not found. Please specify library location."
  263. )
  264. else(LAPACK_FIND_REQUIRED)
  265. message(STATUS
  266. "A library with LAPACK API not found. Please specify library location."
  267. )
  268. endif(LAPACK_FIND_REQUIRED)
  269. endif(LAPACK_FOUND)
  270. endif(NOT LAPACK_FIND_QUIETLY)
  271. endif(BLA_F95)