FindLAPACK.cmake 8.6 KB

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