FindLAPACK.cmake 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
  134. if(NOT LAPACK_LIBRARIES)
  135. check_lapack_libraries(
  136. LAPACK_LIBRARIES
  137. LAPACK
  138. cheev
  139. ""
  140. "goto2"
  141. "${BLAS_LIBRARIES}"
  142. ""
  143. )
  144. endif(NOT LAPACK_LIBRARIES)
  145. endif (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
  146. #acml lapack
  147. if (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "ACML_MP" OR BLA_VENDOR STREQUAL "All")
  148. if (BLAS_LIBRARIES MATCHES ".+acml.+")
  149. set (LAPACK_LIBRARIES ${BLAS_LIBRARIES})
  150. endif ()
  151. endif (BLA_VENDOR STREQUAL "ACML" OR BLA_VENDOR STREQUAL "ACML_MP" OR BLA_VENDOR STREQUAL "All")
  152. # Apple LAPACK library?
  153. if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  154. if(NOT LAPACK_LIBRARIES)
  155. check_lapack_libraries(
  156. LAPACK_LIBRARIES
  157. LAPACK
  158. cheev
  159. ""
  160. "Accelerate"
  161. "${BLAS_LIBRARIES}"
  162. ""
  163. )
  164. endif(NOT LAPACK_LIBRARIES)
  165. endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  166. if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  167. if ( NOT LAPACK_LIBRARIES )
  168. check_lapack_libraries(
  169. LAPACK_LIBRARIES
  170. LAPACK
  171. cheev
  172. ""
  173. "vecLib"
  174. "${BLAS_LIBRARIES}"
  175. ""
  176. )
  177. endif ( NOT LAPACK_LIBRARIES )
  178. endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  179. # Generic LAPACK library?
  180. if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  181. if ( NOT LAPACK_LIBRARIES )
  182. check_lapack_libraries(
  183. LAPACK_LIBRARIES
  184. LAPACK
  185. cheev
  186. ""
  187. "lapack"
  188. "${BLAS_LIBRARIES}"
  189. ""
  190. )
  191. endif ( NOT LAPACK_LIBRARIES )
  192. endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  193. #intel lapack
  194. if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
  195. if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
  196. if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
  197. find_PACKAGE(Threads)
  198. else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
  199. find_package(Threads REQUIRED)
  200. endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
  201. if (BLA_F95)
  202. if(NOT LAPACK95_LIBRARIES)
  203. check_lapack_libraries(
  204. LAPACK95_LIBRARIES
  205. LAPACK
  206. cheev
  207. ""
  208. "mkl_lapack95"
  209. "${BLAS95_LIBRARIES}"
  210. "${CMAKE_THREAD_LIBS_INIT}"
  211. )
  212. endif(NOT LAPACK95_LIBRARIES)
  213. else(BLA_F95)
  214. if(NOT LAPACK_LIBRARIES)
  215. check_lapack_libraries(
  216. LAPACK_LIBRARIES
  217. LAPACK
  218. cheev
  219. ""
  220. "mkl_lapack"
  221. "${BLAS_LIBRARIES}"
  222. "${CMAKE_THREAD_LIBS_INIT}"
  223. )
  224. endif(NOT LAPACK_LIBRARIES)
  225. endif(BLA_F95)
  226. endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
  227. endif(BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
  228. else(BLAS_FOUND)
  229. message(STATUS "LAPACK requires BLAS")
  230. endif(BLAS_FOUND)
  231. if(BLA_F95)
  232. if(LAPACK95_LIBRARIES)
  233. set(LAPACK95_FOUND TRUE)
  234. else(LAPACK95_LIBRARIES)
  235. set(LAPACK95_FOUND FALSE)
  236. endif(LAPACK95_LIBRARIES)
  237. if(NOT LAPACK_FIND_QUIETLY)
  238. if(LAPACK95_FOUND)
  239. message(STATUS "A library with LAPACK95 API found.")
  240. else(LAPACK95_FOUND)
  241. if(LAPACK_FIND_REQUIRED)
  242. message(FATAL_ERROR
  243. "A required library with LAPACK95 API not found. Please specify library location."
  244. )
  245. else(LAPACK_FIND_REQUIRED)
  246. message(STATUS
  247. "A library with LAPACK95 API not found. Please specify library location."
  248. )
  249. endif(LAPACK_FIND_REQUIRED)
  250. endif(LAPACK95_FOUND)
  251. endif(NOT LAPACK_FIND_QUIETLY)
  252. set(LAPACK_FOUND "${LAPACK95_FOUND}")
  253. set(LAPACK_LIBRARIES "${LAPACK95_LIBRARIES}")
  254. else(BLA_F95)
  255. if(LAPACK_LIBRARIES)
  256. set(LAPACK_FOUND TRUE)
  257. else(LAPACK_LIBRARIES)
  258. set(LAPACK_FOUND FALSE)
  259. endif(LAPACK_LIBRARIES)
  260. if(NOT LAPACK_FIND_QUIETLY)
  261. if(LAPACK_FOUND)
  262. message(STATUS "A library with LAPACK API found.")
  263. else(LAPACK_FOUND)
  264. if(LAPACK_FIND_REQUIRED)
  265. message(FATAL_ERROR
  266. "A required library with LAPACK API not found. Please specify library location."
  267. )
  268. else(LAPACK_FIND_REQUIRED)
  269. message(STATUS
  270. "A library with LAPACK API not found. Please specify library location."
  271. )
  272. endif(LAPACK_FIND_REQUIRED)
  273. endif(LAPACK_FOUND)
  274. endif(NOT LAPACK_FIND_QUIETLY)
  275. endif(BLA_F95)