You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

273 lines
9.7 KiB

  1. # Find LAPACK library
  2. #
  3. # This module finds an installed library that implements the LAPACK
  4. # linear-algebra interface (see http://www.netlib.org/lapack/).
  5. # The approach follows mostly 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_INCLUDE_DIR - Directories containing the LAPACK header files
  12. # LAPACK_DEFINITIONS - Compilation options to use LAPACK
  13. # LAPACK_LINKER_FLAGS - Linker flags to use LAPACK (excluding -l
  14. # and -L).
  15. # LAPACK_LIBRARIES_DIR - Directories containing the LAPACK libraries.
  16. # May be null if LAPACK_LIBRARIES contains libraries name using full path.
  17. # LAPACK_LIBRARIES - List of libraries to link against LAPACK interface.
  18. # May be null if the compiler supports auto-link (e.g. VC++).
  19. # LAPACK_USE_FILE - The name of the cmake module to include to compile
  20. # applications or libraries using LAPACK.
  21. #
  22. # This module was modified by CGAL team:
  23. # - find libraries for a C++ compiler, instead of Fortran
  24. # - added LAPACK_INCLUDE_DIR, LAPACK_DEFINITIONS and LAPACK_LIBRARIES_DIR
  25. # - removed LAPACK95_LIBRARIES
  26. include(CheckFunctionExists)
  27. # This macro checks for the existence of the combination of fortran libraries
  28. # given by _list. If the combination is found, this macro checks (using the
  29. # check_function_exists macro) whether can link against that library
  30. # combination using the name of a routine given by _name using the linker
  31. # flags given by _flags. If the combination of libraries is found and passes
  32. # the link test, LIBRARIES is set to the list of complete library paths that
  33. # have been found and DEFINITIONS to the required definitions.
  34. # Otherwise, LIBRARIES is set to FALSE.
  35. # N.B. _prefix is the prefix applied to the names of all cached variables that
  36. # are generated internally and marked advanced by this macro.
  37. macro(check_lapack_libraries DEFINITIONS LIBRARIES _prefix _name _flags _list _blas _path)
  38. #message("DEBUG: check_lapack_libraries(${_list} in ${_path} with ${_blas})")
  39. # Check for the existence of the libraries given by _list
  40. set(_libraries_found TRUE)
  41. set(_libraries_work FALSE)
  42. set(${DEFINITIONS} "")
  43. set(${LIBRARIES} "")
  44. set(_combined_name)
  45. foreach(_library ${_list})
  46. set(_combined_name ${_combined_name}_${_library})
  47. if(_libraries_found)
  48. # search first in ${_path}
  49. find_library(${_prefix}_${_library}_LIBRARY
  50. NAMES ${_library}
  51. PATHS ${_path} NO_DEFAULT_PATH
  52. )
  53. # if not found, search in environment variables and system
  54. if ( WIN32 )
  55. find_library(${_prefix}_${_library}_LIBRARY
  56. NAMES ${_library}
  57. PATHS ENV LIB
  58. )
  59. elseif ( APPLE )
  60. find_library(${_prefix}_${_library}_LIBRARY
  61. NAMES ${_library}
  62. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
  63. )
  64. else ()
  65. find_library(${_prefix}_${_library}_LIBRARY
  66. NAMES ${_library}
  67. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
  68. )
  69. endif()
  70. mark_as_advanced(${_prefix}_${_library}_LIBRARY)
  71. set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
  72. set(_libraries_found ${${_prefix}_${_library}_LIBRARY})
  73. endif(_libraries_found)
  74. endforeach(_library ${_list})
  75. if(_libraries_found)
  76. set(_libraries_found ${${LIBRARIES}})
  77. endif()
  78. # Test this combination of libraries with the Fortran/f2c interface.
  79. # We test the Fortran interface first as it is well standardized.
  80. if(_libraries_found AND NOT _libraries_work)
  81. set(${DEFINITIONS} "-D${_prefix}_USE_F2C")
  82. set(${LIBRARIES} ${_libraries_found})
  83. # Some C++ linkers require the f2c library to link with Fortran libraries.
  84. # I do not know which ones, thus I just add the f2c library if it is available.
  85. find_package( F2C QUIET )
  86. if ( F2C_FOUND )
  87. set(${DEFINITIONS} ${${DEFINITIONS}} ${F2C_DEFINITIONS})
  88. set(${LIBRARIES} ${${LIBRARIES}} ${F2C_LIBRARIES})
  89. endif()
  90. set(CMAKE_REQUIRED_DEFINITIONS ${${DEFINITIONS}})
  91. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas})
  92. #message("DEBUG: CMAKE_REQUIRED_DEFINITIONS = ${CMAKE_REQUIRED_DEFINITIONS}")
  93. #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
  94. # Check if function exists with f2c calling convention (ie a trailing underscore)
  95. check_function_exists(${_name}_ ${_prefix}_${_name}_${_combined_name}_f2c_WORKS)
  96. set(CMAKE_REQUIRED_DEFINITIONS} "")
  97. set(CMAKE_REQUIRED_LIBRARIES "")
  98. mark_as_advanced(${_prefix}_${_name}_${_combined_name}_f2c_WORKS)
  99. set(_libraries_work ${${_prefix}_${_name}_${_combined_name}_f2c_WORKS})
  100. endif(_libraries_found AND NOT _libraries_work)
  101. # If not found, test this combination of libraries with a C interface.
  102. # A few implementations (ie ACML) provide a C interface. Unfortunately, there is no standard.
  103. if(_libraries_found AND NOT _libraries_work)
  104. set(${DEFINITIONS} "")
  105. set(${LIBRARIES} ${_libraries_found})
  106. set(CMAKE_REQUIRED_DEFINITIONS "")
  107. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_blas})
  108. #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
  109. check_function_exists(${_name} ${_prefix}_${_name}${_combined_name}_WORKS)
  110. set(CMAKE_REQUIRED_LIBRARIES "")
  111. mark_as_advanced(${_prefix}_${_name}${_combined_name}_WORKS)
  112. set(_libraries_work ${${_prefix}_${_name}${_combined_name}_WORKS})
  113. endif(_libraries_found AND NOT _libraries_work)
  114. # on failure
  115. if(NOT _libraries_work)
  116. set(${DEFINITIONS} "")
  117. set(${LIBRARIES} FALSE)
  118. endif()
  119. #message("DEBUG: ${DEFINITIONS} = ${${DEFINITIONS}}")
  120. #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
  121. endmacro(check_lapack_libraries)
  122. #
  123. # main
  124. #
  125. # LAPACK requires BLAS
  126. if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
  127. find_package(BLAS)
  128. else()
  129. find_package(BLAS REQUIRED)
  130. endif()
  131. if (NOT BLAS_FOUND)
  132. message(STATUS "LAPACK requires BLAS.")
  133. set(LAPACK_FOUND FALSE)
  134. # Is it already configured?
  135. elseif (LAPACK_LIBRARIES_DIR OR LAPACK_LIBRARIES)
  136. set(LAPACK_FOUND TRUE)
  137. else()
  138. # reset variables
  139. set( LAPACK_INCLUDE_DIR "" )
  140. set( LAPACK_DEFINITIONS "" )
  141. set( LAPACK_LINKER_FLAGS "" ) # unused (yet)
  142. set( LAPACK_LIBRARIES "" )
  143. set( LAPACK_LIBRARIES_DIR "" )
  144. #
  145. # If Unix, search for LAPACK function in possible libraries
  146. #
  147. #intel mkl lapack?
  148. if(NOT LAPACK_LIBRARIES)
  149. check_lapack_libraries(
  150. LAPACK_DEFINITIONS
  151. LAPACK_LIBRARIES
  152. LAPACK
  153. cheev
  154. ""
  155. "mkl_lapack"
  156. "${BLAS_LIBRARIES}"
  157. "${CGAL_TAUCS_LIBRARIES_DIR} ENV LAPACK_LIB_DIR"
  158. )
  159. endif()
  160. #acml lapack?
  161. if(NOT LAPACK_LIBRARIES)
  162. check_lapack_libraries(
  163. LAPACK_DEFINITIONS
  164. LAPACK_LIBRARIES
  165. LAPACK
  166. cheev
  167. ""
  168. "acml"
  169. "${BLAS_LIBRARIES}"
  170. "${CGAL_TAUCS_LIBRARIES_DIR} ENV LAPACK_LIB_DIR"
  171. )
  172. endif()
  173. # Apple LAPACK library?
  174. if(NOT LAPACK_LIBRARIES)
  175. check_lapack_libraries(
  176. LAPACK_DEFINITIONS
  177. LAPACK_LIBRARIES
  178. LAPACK
  179. cheev
  180. ""
  181. "Accelerate"
  182. "${BLAS_LIBRARIES}"
  183. "${CGAL_TAUCS_LIBRARIES_DIR} ENV LAPACK_LIB_DIR"
  184. )
  185. endif()
  186. if ( NOT LAPACK_LIBRARIES )
  187. check_lapack_libraries(
  188. LAPACK_DEFINITIONS
  189. LAPACK_LIBRARIES
  190. LAPACK
  191. cheev
  192. ""
  193. "vecLib"
  194. "${BLAS_LIBRARIES}"
  195. "${CGAL_TAUCS_LIBRARIES_DIR} ENV LAPACK_LIB_DIR"
  196. )
  197. endif ( NOT LAPACK_LIBRARIES )
  198. # Generic LAPACK library?
  199. # This configuration *must* be the last try as this library is notably slow.
  200. if ( NOT LAPACK_LIBRARIES )
  201. check_lapack_libraries(
  202. LAPACK_DEFINITIONS
  203. LAPACK_LIBRARIES
  204. LAPACK
  205. cheev
  206. ""
  207. "lapack"
  208. "${BLAS_LIBRARIES}"
  209. "${CGAL_TAUCS_LIBRARIES_DIR} ENV LAPACK_LIB_DIR"
  210. )
  211. endif()
  212. if(LAPACK_LIBRARIES_DIR OR LAPACK_LIBRARIES)
  213. set(LAPACK_FOUND TRUE)
  214. else()
  215. set(LAPACK_FOUND FALSE)
  216. endif()
  217. if(NOT LAPACK_FIND_QUIETLY)
  218. if(LAPACK_FOUND)
  219. message(STATUS "A library with LAPACK API found.")
  220. else(LAPACK_FOUND)
  221. if(LAPACK_FIND_REQUIRED)
  222. message(FATAL_ERROR "A required library with LAPACK API not found. Please specify library location.")
  223. else()
  224. message(STATUS "A library with LAPACK API not found. Please specify library location.")
  225. endif()
  226. endif(LAPACK_FOUND)
  227. endif(NOT LAPACK_FIND_QUIETLY)
  228. # Add variables to cache
  229. set( LAPACK_INCLUDE_DIR "${LAPACK_INCLUDE_DIR}"
  230. CACHE PATH "Directories containing the LAPACK header files" FORCE )
  231. set( LAPACK_DEFINITIONS "${LAPACK_DEFINITIONS}"
  232. CACHE STRING "Compilation options to use LAPACK" FORCE )
  233. set( LAPACK_LINKER_FLAGS "${LAPACK_LINKER_FLAGS}"
  234. CACHE STRING "Linker flags to use LAPACK" FORCE )
  235. set( LAPACK_LIBRARIES "${LAPACK_LIBRARIES}"
  236. CACHE FILEPATH "LAPACK libraries name" FORCE )
  237. set( LAPACK_LIBRARIES_DIR "${LAPACK_LIBRARIES_DIR}"
  238. CACHE PATH "Directories containing the LAPACK libraries" FORCE )
  239. #message("DEBUG: LAPACK_INCLUDE_DIR = ${LAPACK_INCLUDE_DIR}")
  240. #message("DEBUG: LAPACK_DEFINITIONS = ${LAPACK_DEFINITIONS}")
  241. #message("DEBUG: LAPACK_LINKER_FLAGS = ${LAPACK_LINKER_FLAGS}")
  242. #message("DEBUG: LAPACK_LIBRARIES = ${LAPACK_LIBRARIES}")
  243. #message("DEBUG: LAPACK_LIBRARIES_DIR = ${LAPACK_LIBRARIES_DIR}")
  244. #message("DEBUG: LAPACK_FOUND = ${LAPACK_FOUND}")
  245. endif(NOT BLAS_FOUND)