FindLAPACK.cmake 4.7 KB

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