FindLAPACK.cmake 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. #
  18. include(CheckFortranFunctionExists)
  19. set(LAPACK_FOUND FALSE)
  20. macro(Check_Lapack_Libraries LIBRARIES _prefix _name _flags _list _blas)
  21. # This macro checks for the existence of the combination of fortran libraries
  22. # given by _list. If the combination is found, this macro checks (using the
  23. # Check_Fortran_Function_Exists macro) whether can link against that library
  24. # combination using the name of a routine given by _name using the linker
  25. # flags given by _flags. If the combination of libraries is found and passes
  26. # the link test, LIBRARIES is set to the list of complete library paths that
  27. # have been found. Otherwise, LIBRARIES is set to FALSE.
  28. # N.B. _prefix is the prefix applied to the names of all cached variables that
  29. # are generated internally and marked advanced by this macro.
  30. set(_libraries_work TRUE)
  31. set(${LIBRARIES})
  32. set(_combined_name)
  33. foreach(_library ${_list})
  34. set(_combined_name ${_combined_name}_${_library})
  35. if(_libraries_work)
  36. IF (WIN32)
  37. find_library(${_prefix}_${_library}_LIBRARY
  38. NAMES ${_library}
  39. PATHS ENV LIB
  40. )
  41. ENDIF (WIN32)
  42. if(APPLE)
  43. find_library(${_prefix}_${_library}_LIBRARY
  44. NAMES ${_library}
  45. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
  46. )
  47. else(APPLE)
  48. find_library(${_prefix}_${_library}_LIBRARY
  49. NAMES ${_library}
  50. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
  51. )
  52. endif(APPLE)
  53. mark_as_advanced(${_prefix}_${_library}_LIBRARY)
  54. set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
  55. set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
  56. endif(_libraries_work)
  57. endforeach(_library ${_list})
  58. if(_libraries_work)
  59. # Test this combination of libraries.
  60. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas})
  61. #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
  62. check_fortran_function_exists(${_name} ${_prefix}${_combined_name}_WORKS)
  63. set(CMAKE_REQUIRED_LIBRARIES)
  64. mark_as_advanced(${_prefix}${_combined_name}_WORKS)
  65. set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
  66. #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
  67. endif(_libraries_work)
  68. if(NOT _libraries_work)
  69. set(${LIBRARIES} FALSE)
  70. endif(NOT _libraries_work)
  71. endmacro(Check_Lapack_Libraries)
  72. set(LAPACK_LINKER_FLAGS)
  73. set(LAPACK_LIBRARIES)
  74. set(LAPACK95_LIBRARIES)
  75. if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
  76. find_package(BLAS)
  77. else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
  78. find_package(BLAS REQUIRED)
  79. endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
  80. if(BLAS_FOUND)
  81. set(LAPACK_LINKER_FLAGS ${BLAS_LINKER_FLAGS})
  82. #intel lapack
  83. if(NOT LAPACK_LIBRARIES)
  84. check_lapack_libraries(
  85. LAPACK_LIBRARIES
  86. LAPACK
  87. cheev
  88. ""
  89. "mkl_lapack"
  90. "${BLAS_LIBRARIES}"
  91. )
  92. endif(NOT LAPACK_LIBRARIES)
  93. if(NOT LAPACK95_LIBRARIES)
  94. check_lapack_libraries(
  95. LAPACK95_LIBRARIES
  96. LAPACK
  97. cheev
  98. ""
  99. "mkl_lapack95"
  100. "${BLAS_LIBRARIES}"
  101. )
  102. endif(NOT LAPACK95_LIBRARIES)
  103. #acml lapack
  104. if(NOT LAPACK_LIBRARIES)
  105. check_lapack_libraries(
  106. LAPACK_LIBRARIES
  107. LAPACK
  108. cheev
  109. ""
  110. "acml"
  111. "${BLAS_LIBRARIES}"
  112. )
  113. endif(NOT LAPACK_LIBRARIES)
  114. # Apple LAPACK library?
  115. if(NOT LAPACK_LIBRARIES)
  116. check_lapack_libraries(
  117. LAPACK_LIBRARIES
  118. LAPACK
  119. cheev
  120. ""
  121. "Accelerate"
  122. "${BLAS_LIBRARIES}"
  123. )
  124. endif(NOT LAPACK_LIBRARIES)
  125. if ( NOT LAPACK_LIBRARIES )
  126. check_lapack_libraries(
  127. LAPACK_LIBRARIES
  128. LAPACK
  129. cheev
  130. ""
  131. "vecLib"
  132. "${BLAS_LIBRARIES}"
  133. )
  134. endif ( NOT LAPACK_LIBRARIES )
  135. # Generic LAPACK library?
  136. if ( NOT LAPACK_LIBRARIES )
  137. check_lapack_libraries(
  138. LAPACK_LIBRARIES
  139. LAPACK
  140. cheev
  141. ""
  142. "lapack"
  143. "${BLAS_LIBRARIES}"
  144. )
  145. endif ( NOT LAPACK_LIBRARIES )
  146. else(BLAS_FOUND)
  147. message(STATUS "LAPACK requires BLAS")
  148. endif(BLAS_FOUND)
  149. if(LAPACK_LIBRARIES)
  150. set(LAPACK_FOUND TRUE)
  151. else(LAPACK_LIBRARIES)
  152. set(LAPACK_FOUND FALSE)
  153. endif(LAPACK_LIBRARIES)
  154. if(NOT LAPACK_FIND_QUIETLY)
  155. if(LAPACK_FOUND)
  156. message(STATUS "A library with LAPACK API found.")
  157. else(LAPACK_FOUND)
  158. if(LAPACK_FIND_REQUIRED)
  159. message(FATAL_ERROR
  160. "A required library with LAPACK API not found. Please specify library location."
  161. )
  162. else(LAPACK_FIND_REQUIRED)
  163. message(STATUS
  164. "A library with LAPACK API not found. Please specify library location."
  165. )
  166. endif(LAPACK_FIND_REQUIRED)
  167. endif(LAPACK_FOUND)
  168. endif(NOT LAPACK_FIND_QUIETLY)