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.

419 lines
13 KiB

  1. # Find BLAS library
  2. #
  3. # This module finds an installed library that implements the BLAS
  4. # linear-algebra interface (see http://www.netlib.org/blas/).
  5. # The list of libraries searched for is mainly taken
  6. # from the autoconf macro file, acx_blas.m4 (distributed at
  7. # http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
  8. #
  9. # This module sets the following variables:
  10. # BLAS_FOUND - set to true if a library implementing the BLAS interface
  11. # is found
  12. # BLAS_INCLUDE_DIR - Directories containing the BLAS header files
  13. # BLAS_DEFINITIONS - Compilation options to use BLAS
  14. # BLAS_LINKER_FLAGS - Linker flags to use BLAS (excluding -l
  15. # and -L).
  16. # BLAS_LIBRARIES_DIR - Directories containing the BLAS libraries.
  17. # May be null if BLAS_LIBRARIES contains libraries name using full path.
  18. # BLAS_LIBRARIES - List of libraries to link against BLAS interface.
  19. # May be null if the compiler supports auto-link (e.g. VC++).
  20. # BLAS_USE_FILE - The name of the cmake module to include to compile
  21. # applications or libraries using BLAS.
  22. #
  23. # This module was modified by CGAL team:
  24. # - find libraries for a C++ compiler, instead of Fortran
  25. # - added BLAS_INCLUDE_DIR, BLAS_DEFINITIONS and BLAS_LIBRARIES_DIR
  26. # - removed BLAS95_LIBRARIES
  27. include(CheckFunctionExists)
  28. # This macro checks for the existence of the combination of fortran libraries
  29. # given by _list. If the combination is found, this macro checks (using the
  30. # check_function_exists macro) whether can link against that library
  31. # combination using the name of a routine given by _name using the linker
  32. # flags given by _flags. If the combination of libraries is found and passes
  33. # the link test, LIBRARIES is set to the list of complete library paths that
  34. # have been found and DEFINITIONS to the required definitions.
  35. # Otherwise, LIBRARIES is set to FALSE.
  36. # N.B. _prefix is the prefix applied to the names of all cached variables that
  37. # are generated internally and marked advanced by this macro.
  38. macro(check_fortran_libraries DEFINITIONS LIBRARIES _prefix _name _flags _list _path)
  39. #message("DEBUG: check_fortran_libraries(${_list} in ${_path})")
  40. # Check for the existence of the libraries given by _list
  41. set(_libraries_found TRUE)
  42. set(_libraries_work FALSE)
  43. set(${DEFINITIONS} "")
  44. set(${LIBRARIES} "")
  45. set(_combined_name)
  46. foreach(_library ${_list})
  47. set(_combined_name ${_combined_name}_${_library})
  48. if(_libraries_found)
  49. # search first in ${_path}
  50. find_library(${_prefix}_${_library}_LIBRARY
  51. NAMES ${_library}
  52. PATHS ${_path} NO_DEFAULT_PATH
  53. )
  54. # if not found, search in environment variables and system
  55. if ( WIN32 )
  56. find_library(${_prefix}_${_library}_LIBRARY
  57. NAMES ${_library}
  58. PATHS ENV LIB
  59. )
  60. elseif ( APPLE )
  61. find_library(${_prefix}_${_library}_LIBRARY
  62. NAMES ${_library}
  63. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH
  64. )
  65. else ()
  66. find_library(${_prefix}_${_library}_LIBRARY
  67. NAMES ${_library}
  68. PATHS /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH
  69. )
  70. endif()
  71. mark_as_advanced(${_prefix}_${_library}_LIBRARY)
  72. set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
  73. set(_libraries_found ${${_prefix}_${_library}_LIBRARY})
  74. endif(_libraries_found)
  75. endforeach(_library ${_list})
  76. if(_libraries_found)
  77. set(_libraries_found ${${LIBRARIES}})
  78. endif()
  79. # Test this combination of libraries with the Fortran/f2c interface.
  80. # We test the Fortran interface first as it is well standardized.
  81. if(_libraries_found AND NOT _libraries_work)
  82. set(${DEFINITIONS} "-D${_prefix}_USE_F2C")
  83. set(${LIBRARIES} ${_libraries_found})
  84. # Some C++ linkers require the f2c library to link with Fortran libraries.
  85. # I do not know which ones, thus I just add the f2c library if it is available.
  86. find_package( F2C QUIET )
  87. if ( F2C_FOUND )
  88. set(${DEFINITIONS} ${${DEFINITIONS}} ${F2C_DEFINITIONS})
  89. set(${LIBRARIES} ${${LIBRARIES}} ${F2C_LIBRARIES})
  90. endif()
  91. set(CMAKE_REQUIRED_DEFINITIONS ${${DEFINITIONS}})
  92. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}})
  93. #message("DEBUG: CMAKE_REQUIRED_DEFINITIONS = ${CMAKE_REQUIRED_DEFINITIONS}")
  94. #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
  95. # Check if function exists with f2c calling convention (ie a trailing underscore)
  96. check_function_exists(${_name}_ ${_prefix}_${_name}_${_combined_name}_f2c_WORKS)
  97. set(CMAKE_REQUIRED_DEFINITIONS} "")
  98. set(CMAKE_REQUIRED_LIBRARIES "")
  99. mark_as_advanced(${_prefix}_${_name}_${_combined_name}_f2c_WORKS)
  100. set(_libraries_work ${${_prefix}_${_name}_${_combined_name}_f2c_WORKS})
  101. endif(_libraries_found AND NOT _libraries_work)
  102. # If not found, test this combination of libraries with a C interface.
  103. # A few implementations (ie ACML) provide a C interface. Unfortunately, there is no standard.
  104. if(_libraries_found AND NOT _libraries_work)
  105. set(${DEFINITIONS} "")
  106. set(${LIBRARIES} ${_libraries_found})
  107. set(CMAKE_REQUIRED_DEFINITIONS "")
  108. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}})
  109. #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
  110. check_function_exists(${_name} ${_prefix}_${_name}${_combined_name}_WORKS)
  111. set(CMAKE_REQUIRED_LIBRARIES "")
  112. mark_as_advanced(${_prefix}_${_name}${_combined_name}_WORKS)
  113. set(_libraries_work ${${_prefix}_${_name}${_combined_name}_WORKS})
  114. endif(_libraries_found AND NOT _libraries_work)
  115. # on failure
  116. if(NOT _libraries_work)
  117. set(${DEFINITIONS} "")
  118. set(${LIBRARIES} FALSE)
  119. endif()
  120. #message("DEBUG: ${DEFINITIONS} = ${${DEFINITIONS}}")
  121. #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
  122. endmacro(check_fortran_libraries)
  123. #
  124. # main
  125. #
  126. # Is it already configured?
  127. if (BLAS_LIBRARIES_DIR OR BLAS_LIBRARIES)
  128. set(BLAS_FOUND TRUE)
  129. else()
  130. # reset variables
  131. set( BLAS_INCLUDE_DIR "" )
  132. set( BLAS_DEFINITIONS "" )
  133. set( BLAS_LINKER_FLAGS "" )
  134. set( BLAS_LIBRARIES "" )
  135. set( BLAS_LIBRARIES_DIR "" )
  136. #
  137. # If Unix, search for BLAS function in possible libraries
  138. #
  139. # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
  140. if(NOT BLAS_LIBRARIES)
  141. check_fortran_libraries(
  142. BLAS_DEFINITIONS
  143. BLAS_LIBRARIES
  144. BLAS
  145. sgemm
  146. ""
  147. "cblas;f77blas;atlas"
  148. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  149. )
  150. endif()
  151. # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
  152. if(NOT BLAS_LIBRARIES)
  153. check_fortran_libraries(
  154. BLAS_DEFINITIONS
  155. BLAS_LIBRARIES
  156. BLAS
  157. sgemm
  158. ""
  159. "sgemm;dgemm;blas"
  160. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  161. )
  162. endif()
  163. # BLAS in Alpha CXML library?
  164. if(NOT BLAS_LIBRARIES)
  165. check_fortran_libraries(
  166. BLAS_DEFINITIONS
  167. BLAS_LIBRARIES
  168. BLAS
  169. sgemm
  170. ""
  171. "cxml"
  172. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  173. )
  174. endif()
  175. # BLAS in Alpha DXML library? (now called CXML, see above)
  176. if(NOT BLAS_LIBRARIES)
  177. check_fortran_libraries(
  178. BLAS_DEFINITIONS
  179. BLAS_LIBRARIES
  180. BLAS
  181. sgemm
  182. ""
  183. "dxml"
  184. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  185. )
  186. endif()
  187. # BLAS in Sun Performance library?
  188. if(NOT BLAS_LIBRARIES)
  189. check_fortran_libraries(
  190. BLAS_DEFINITIONS
  191. BLAS_LIBRARIES
  192. BLAS
  193. sgemm
  194. "-xlic_lib=sunperf"
  195. "sunperf;sunmath"
  196. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  197. )
  198. if(BLAS_LIBRARIES)
  199. # Extra linker flag
  200. set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
  201. endif()
  202. endif()
  203. # BLAS in SCSL library? (SGI/Cray Scientific Library)
  204. if(NOT BLAS_LIBRARIES)
  205. check_fortran_libraries(
  206. BLAS_DEFINITIONS
  207. BLAS_LIBRARIES
  208. BLAS
  209. sgemm
  210. ""
  211. "scsl"
  212. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  213. )
  214. endif()
  215. # BLAS in SGIMATH library?
  216. if(NOT BLAS_LIBRARIES)
  217. check_fortran_libraries(
  218. BLAS_DEFINITIONS
  219. BLAS_LIBRARIES
  220. BLAS
  221. sgemm
  222. ""
  223. "complib.sgimath"
  224. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  225. )
  226. endif()
  227. # BLAS in IBM ESSL library? (requires generic BLAS lib, too)
  228. if(NOT BLAS_LIBRARIES)
  229. check_fortran_libraries(
  230. BLAS_DEFINITIONS
  231. BLAS_LIBRARIES
  232. BLAS
  233. sgemm
  234. ""
  235. "essl;blas"
  236. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  237. )
  238. endif()
  239. #BLAS in intel mkl 10 library? (em64t 64bit)
  240. if(NOT BLAS_LIBRARIES)
  241. check_fortran_libraries(
  242. BLAS_DEFINITIONS
  243. BLAS_LIBRARIES
  244. BLAS
  245. sgemm
  246. ""
  247. "mkl_intel_lp64;mkl_intel_thread;mkl_core;guide;pthread"
  248. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  249. )
  250. endif()
  251. ### windows version of intel mkl 10?
  252. if(NOT BLAS_LIBRARIES)
  253. check_fortran_libraries(
  254. BLAS_DEFINITIONS
  255. BLAS_LIBRARIES
  256. BLAS
  257. SGEMM
  258. ""
  259. "mkl_c_dll;mkl_intel_thread_dll;mkl_core_dll;libguide40"
  260. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  261. )
  262. endif()
  263. #older versions of intel mkl libs
  264. # BLAS in intel mkl library? (shared)
  265. if(NOT BLAS_LIBRARIES)
  266. check_fortran_libraries(
  267. BLAS_DEFINITIONS
  268. BLAS_LIBRARIES
  269. BLAS
  270. sgemm
  271. ""
  272. "mkl;guide;pthread"
  273. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  274. )
  275. endif()
  276. #BLAS in intel mkl library? (static, 32bit)
  277. if(NOT BLAS_LIBRARIES)
  278. check_fortran_libraries(
  279. BLAS_DEFINITIONS
  280. BLAS_LIBRARIES
  281. BLAS
  282. sgemm
  283. ""
  284. "mkl_ia32;guide;pthread"
  285. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  286. )
  287. endif()
  288. #BLAS in intel mkl library? (static, em64t 64bit)
  289. if(NOT BLAS_LIBRARIES)
  290. check_fortran_libraries(
  291. BLAS_DEFINITIONS
  292. BLAS_LIBRARIES
  293. BLAS
  294. sgemm
  295. ""
  296. "mkl_em64t;guide;pthread"
  297. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  298. )
  299. endif()
  300. #BLAS in acml library?
  301. if(NOT BLAS_LIBRARIES)
  302. check_fortran_libraries(
  303. BLAS_DEFINITIONS
  304. BLAS_LIBRARIES
  305. BLAS
  306. sgemm
  307. ""
  308. "acml"
  309. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  310. )
  311. endif()
  312. # Apple BLAS library?
  313. if(NOT BLAS_LIBRARIES)
  314. check_fortran_libraries(
  315. BLAS_DEFINITIONS
  316. BLAS_LIBRARIES
  317. BLAS
  318. sgemm
  319. ""
  320. "Accelerate"
  321. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  322. )
  323. endif()
  324. if ( NOT BLAS_LIBRARIES )
  325. check_fortran_libraries(
  326. BLAS_DEFINITIONS
  327. BLAS_LIBRARIES
  328. BLAS
  329. sgemm
  330. ""
  331. "vecLib"
  332. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  333. )
  334. endif ( NOT BLAS_LIBRARIES )
  335. # Generic BLAS library?
  336. # This configuration *must* be the last try as this library is notably slow.
  337. if ( NOT BLAS_LIBRARIES )
  338. check_fortran_libraries(
  339. BLAS_DEFINITIONS
  340. BLAS_LIBRARIES
  341. BLAS
  342. sgemm
  343. ""
  344. "blas"
  345. "${CGAL_TAUCS_LIBRARIES_DIR} ENV BLAS_LIB_DIR"
  346. )
  347. endif()
  348. if(BLAS_LIBRARIES_DIR OR BLAS_LIBRARIES)
  349. set(BLAS_FOUND TRUE)
  350. else()
  351. set(BLAS_FOUND FALSE)
  352. endif()
  353. if(NOT BLAS_FIND_QUIETLY)
  354. if(BLAS_FOUND)
  355. message(STATUS "A library with BLAS API found.")
  356. else(BLAS_FOUND)
  357. if(BLAS_FIND_REQUIRED)
  358. message(FATAL_ERROR "A required library with BLAS API not found. Please specify library location.")
  359. else()
  360. message(STATUS "A library with BLAS API not found. Please specify library location.")
  361. endif()
  362. endif(BLAS_FOUND)
  363. endif(NOT BLAS_FIND_QUIETLY)
  364. # Add variables to cache
  365. set( BLAS_INCLUDE_DIR "${BLAS_INCLUDE_DIR}"
  366. CACHE PATH "Directories containing the BLAS header files" FORCE )
  367. set( BLAS_DEFINITIONS "${BLAS_DEFINITIONS}"
  368. CACHE STRING "Compilation options to use BLAS" FORCE )
  369. set( BLAS_LINKER_FLAGS "${BLAS_LINKER_FLAGS}"
  370. CACHE STRING "Linker flags to use BLAS" FORCE )
  371. set( BLAS_LIBRARIES "${BLAS_LIBRARIES}"
  372. CACHE FILEPATH "BLAS libraries name" FORCE )
  373. set( BLAS_LIBRARIES_DIR "${BLAS_LIBRARIES_DIR}"
  374. CACHE PATH "Directories containing the BLAS libraries" FORCE )
  375. #message("DEBUG: BLAS_INCLUDE_DIR = ${BLAS_INCLUDE_DIR}")
  376. #message("DEBUG: BLAS_DEFINITIONS = ${BLAS_DEFINITIONS}")
  377. #message("DEBUG: BLAS_LINKER_FLAGS = ${BLAS_LINKER_FLAGS}")
  378. #message("DEBUG: BLAS_LIBRARIES = ${BLAS_LIBRARIES}")
  379. #message("DEBUG: BLAS_LIBRARIES_DIR = ${BLAS_LIBRARIES_DIR}")
  380. #message("DEBUG: BLAS_FOUND = ${BLAS_FOUND}")
  381. endif(BLAS_LIBRARIES_DIR OR BLAS_LIBRARIES)