FindLAPACK.cmake 9.4 KB

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