FindBLAS.cmake 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406
  1. ###
  2. #
  3. # @copyright (c) 2009-2014 The University of Tennessee and The University
  4. # of Tennessee Research Foundation.
  5. # All rights reserved.
  6. # @copyright (c) 2012-2016 Inria. All rights reserved.
  7. # @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
  8. #
  9. ###
  10. #
  11. # - Find BLAS library
  12. # This module finds an installed fortran library that implements the BLAS
  13. # linear-algebra interface (see http://www.netlib.org/blas/).
  14. # The list of libraries searched for is taken
  15. # from the autoconf macro file, acx_blas.m4 (distributed at
  16. # http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
  17. #
  18. # This module sets the following variables:
  19. # BLAS_FOUND - set to true if a library implementing the BLAS interface
  20. # is found
  21. # BLAS_LINKER_FLAGS - uncached list of required linker flags (excluding -l
  22. # and -L).
  23. # BLAS_COMPILER_FLAGS - uncached list of required compiler flags (including -I for mkl headers).
  24. # BLAS_LIBRARIES - uncached list of libraries (using full path name) to
  25. # link against to use BLAS
  26. # BLAS95_LIBRARIES - uncached list of libraries (using full path name)
  27. # to link against to use BLAS95 interface
  28. # BLAS95_FOUND - set to true if a library implementing the BLAS f95 interface
  29. # is found
  30. # BLA_STATIC if set on this determines what kind of linkage we do (static)
  31. # BLA_VENDOR if set checks only the specified vendor, if not set checks
  32. # all the possibilities
  33. # BLAS_VENDOR_FOUND stores the BLAS vendor found
  34. # BLA_F95 if set on tries to find the f95 interfaces for BLAS/LAPACK
  35. # The user can give specific paths where to find the libraries adding cmake
  36. # options at configure (ex: cmake path/to/project -DBLAS_DIR=path/to/blas):
  37. # BLAS_DIR - Where to find the base directory of blas
  38. # BLAS_INCDIR - Where to find the header files
  39. # BLAS_LIBDIR - Where to find the library files
  40. # The module can also look for the following environment variables if paths
  41. # are not given as cmake variable: BLAS_DIR, BLAS_INCDIR, BLAS_LIBDIR
  42. # For MKL case and if no paths are given as hints, we will try to use the MKLROOT
  43. # environment variable
  44. # BLAS_VERBOSE Print some additional information during BLAS libraries detection
  45. ##########
  46. ### List of vendors (BLA_VENDOR) valid in this module
  47. ########## List of vendors (BLA_VENDOR) valid in this module
  48. ## Open (for OpenBlas), Eigen (for EigenBlas), Goto, ATLAS PhiPACK,
  49. ##  CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, IBMESSLMT
  50. ## Intel10_32 (intel mkl v10 32 bit), Intel10_64lp (intel mkl v10 64 bit,lp thread model, lp64 model),
  51. ## Intel10_64lp_seq (intel mkl v10 64 bit,sequential code, lp64 model),
  52. ## Intel( older versions of mkl 32 and 64 bit),
  53. ##  ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic
  54. # C/CXX should be enabled to use Intel mkl
  55. ###
  56. # We handle different modes to find the dependency
  57. #
  58. # - Detection if already installed on the system
  59. # - BLAS libraries can be detected from different ways
  60. # Here is the order of precedence:
  61. # 1) we look in cmake variable BLAS_LIBDIR or BLAS_DIR (we guess the libdirs) if defined
  62. # 2) we look in environment variable BLAS_LIBDIR or BLAS_DIR (we guess the libdirs) if defined
  63. # 3) we look in common environnment variables depending on the system (INCLUDE, C_INCLUDE_PATH, CPATH - LIB, DYLD_LIBRARY_PATH, LD_LIBRARY_PATH)
  64. # 4) we look in common system paths depending on the system, see for example paths contained in the following cmake variables:
  65. # - CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES, CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
  66. # - CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES, CMAKE_C_IMPLICIT_LINK_DIRECTORIES
  67. #
  68. #=============================================================================
  69. # Copyright 2007-2009 Kitware, Inc.
  70. #
  71. # Distributed under the OSI-approved BSD License (the "License");
  72. # see accompanying file Copyright.txt for details.
  73. #
  74. # This software is distributed WITHOUT ANY WARRANTY; without even the
  75. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  76. # See the License for more information.
  77. #=============================================================================
  78. # (To distribute this file outside of CMake, substitute the full
  79. # License text for the above reference.)
  80. ## Some macros to print status when search for headers and libs
  81. # This macro informs why the _lib_to_find file has not been found
  82. macro(Print_Find_Library_Blas_Status _libname _lib_to_find)
  83. # save _libname upper/lower case
  84. string(TOUPPER ${_libname} LIBNAME)
  85. string(TOLOWER ${_libname} libname)
  86. # print status
  87. #message(" ")
  88. if(${LIBNAME}_LIBDIR)
  89. message("${Yellow}${LIBNAME}_LIBDIR is defined but ${_lib_to_find}"
  90. "has not been found in ${ARGN}${ColourReset}")
  91. else()
  92. if(${LIBNAME}_DIR)
  93. message("${Yellow}${LIBNAME}_DIR is defined but ${_lib_to_find}"
  94. "has not been found in ${ARGN}${ColourReset}")
  95. else()
  96. message("${Yellow}${_lib_to_find} not found."
  97. "Nor ${LIBNAME}_DIR neither ${LIBNAME}_LIBDIR"
  98. "are defined so that we look for ${_lib_to_find} in"
  99. "system paths (Linux: LD_LIBRARY_PATH, Windows: LIB,"
  100. "Mac: DYLD_LIBRARY_PATH,"
  101. "CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES,"
  102. "CMAKE_C_IMPLICIT_LINK_DIRECTORIES)${ColourReset}")
  103. if(_lib_env)
  104. message("${Yellow}${_lib_to_find} has not been found in"
  105. "${_lib_env}${ColourReset}")
  106. endif()
  107. endif()
  108. endif()
  109. message("${BoldYellow}Please indicate where to find ${_lib_to_find}. You have three options:\n"
  110. "- Option 1: Provide the Installation directory of BLAS library with cmake option: -D${LIBNAME}_DIR=your/path/to/${libname}/\n"
  111. "- Option 2: Provide the directory where to find the library with cmake option: -D${LIBNAME}_LIBDIR=your/path/to/${libname}/lib/\n"
  112. "- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
  113. "- Option 4: If your library provides a PkgConfig file, make sure pkg-config finds your library${ColourReset}")
  114. endmacro()
  115. # This macro informs why the _lib_to_find file has not been found
  116. macro(Print_Find_Library_Blas_CheckFunc_Status _name)
  117. # save _libname upper/lower case
  118. string(TOUPPER ${_name} FUNCNAME)
  119. string(TOLOWER ${_name} funcname)
  120. # print status
  121. #message(" ")
  122. message("${Red}Libs have been found but check of symbol ${_name} failed "
  123. "with following libraries ${ARGN}${ColourReset}")
  124. message("${BoldRed}Please open your error file CMakeFiles/CMakeError.log"
  125. "to figure out why it fails${ColourReset}")
  126. #message(" ")
  127. endmacro()
  128. if (NOT BLAS_FOUND)
  129. set(BLAS_DIR "" CACHE PATH "Installation directory of BLAS library")
  130. if (NOT BLAS_FIND_QUIETLY)
  131. message(STATUS "A cache variable, namely BLAS_DIR, has been set to specify the install directory of BLAS")
  132. endif()
  133. endif()
  134. option(BLAS_VERBOSE "Print some additional information during BLAS libraries detection" OFF)
  135. mark_as_advanced(BLAS_VERBOSE)
  136. include(CheckFunctionExists)
  137. include(CheckFortranFunctionExists)
  138. set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  139. # Check the language being used
  140. get_property( _LANGUAGES_ GLOBAL PROPERTY ENABLED_LANGUAGES )
  141. if( _LANGUAGES_ MATCHES Fortran AND CMAKE_Fortran_COMPILER)
  142. set( _CHECK_FORTRAN TRUE )
  143. elseif( (_LANGUAGES_ MATCHES C) OR (_LANGUAGES_ MATCHES CXX) )
  144. set( _CHECK_FORTRAN FALSE )
  145. else()
  146. if(BLAS_FIND_REQUIRED)
  147. message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.")
  148. else()
  149. message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)")
  150. return()
  151. endif()
  152. endif()
  153. macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _thread)
  154. # This macro checks for the existence of the combination of fortran libraries
  155. # given by _list. If the combination is found, this macro checks (using the
  156. # Check_Fortran_Function_Exists macro) whether can link against that library
  157. # combination using the name of a routine given by _name using the linker
  158. # flags given by _flags. If the combination of libraries is found and passes
  159. # the link test, LIBRARIES is set to the list of complete library paths that
  160. # have been found. Otherwise, LIBRARIES is set to FALSE.
  161. # N.B. _prefix is the prefix applied to the names of all cached variables that
  162. # are generated internally and marked advanced by this macro.
  163. set(_libdir ${ARGN})
  164. set(_libraries_work TRUE)
  165. set(${LIBRARIES})
  166. set(_combined_name)
  167. set(ENV_MKLROOT "$ENV{MKLROOT}")
  168. set(ENV_BLAS_DIR "$ENV{BLAS_DIR}")
  169. set(ENV_BLAS_LIBDIR "$ENV{BLAS_LIBDIR}")
  170. if (NOT _libdir)
  171. if (BLAS_LIBDIR)
  172. list(APPEND _libdir "${BLAS_LIBDIR}")
  173. elseif (BLAS_DIR)
  174. list(APPEND _libdir "${BLAS_DIR}")
  175. list(APPEND _libdir "${BLAS_DIR}/lib")
  176. if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
  177. list(APPEND _libdir "${BLAS_DIR}/lib64")
  178. list(APPEND _libdir "${BLAS_DIR}/lib/intel64")
  179. else()
  180. list(APPEND _libdir "${BLAS_DIR}/lib32")
  181. list(APPEND _libdir "${BLAS_DIR}/lib/ia32")
  182. endif()
  183. elseif(ENV_BLAS_LIBDIR)
  184. list(APPEND _libdir "${ENV_BLAS_LIBDIR}")
  185. elseif(ENV_BLAS_DIR)
  186. list(APPEND _libdir "${ENV_BLAS_DIR}")
  187. list(APPEND _libdir "${ENV_BLAS_DIR}/lib")
  188. if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
  189. list(APPEND _libdir "${ENV_BLAS_DIR}/lib64")
  190. list(APPEND _libdir "${ENV_BLAS_DIR}/lib/intel64")
  191. else()
  192. list(APPEND _libdir "${ENV_BLAS_DIR}/lib32")
  193. list(APPEND _libdir "${ENV_BLAS_DIR}/lib/ia32")
  194. endif()
  195. else()
  196. if (ENV_MKLROOT)
  197. list(APPEND _libdir "${ENV_MKLROOT}/lib")
  198. if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
  199. list(APPEND _libdir "${ENV_MKLROOT}/lib64")
  200. list(APPEND _libdir "${ENV_MKLROOT}/lib/intel64")
  201. else()
  202. list(APPEND _libdir "${ENV_MKLROOT}/lib32")
  203. list(APPEND _libdir "${ENV_MKLROOT}/lib/ia32")
  204. endif()
  205. endif()
  206. if (WIN32)
  207. string(REPLACE ":" ";" _libdir2 "$ENV{LIB}")
  208. elseif (APPLE)
  209. string(REPLACE ":" ";" _libdir2 "$ENV{DYLD_LIBRARY_PATH}")
  210. else ()
  211. string(REPLACE ":" ";" _libdir2 "$ENV{LD_LIBRARY_PATH}")
  212. endif ()
  213. list(APPEND _libdir "${_libdir2}")
  214. list(APPEND _libdir "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
  215. list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
  216. endif()
  217. endif ()
  218. if (BLAS_VERBOSE)
  219. message("${Cyan}Try to find BLAS libraries: ${_list}")
  220. endif ()
  221. foreach(_library ${_list})
  222. set(_combined_name ${_combined_name}_${_library})
  223. if(_libraries_work)
  224. if (BLA_STATIC)
  225. if (WIN32)
  226. set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
  227. endif ()
  228. if (APPLE)
  229. set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
  230. else ()
  231. set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  232. endif ()
  233. else ()
  234. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  235. # for ubuntu's libblas3gf and liblapack3gf packages
  236. set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
  237. endif ()
  238. endif ()
  239. find_library(${_prefix}_${_library}_LIBRARY
  240. NAMES ${_library}
  241. HINTS ${_libdir}
  242. NO_DEFAULT_PATH
  243. )
  244. mark_as_advanced(${_prefix}_${_library}_LIBRARY)
  245. # Print status if not found
  246. # -------------------------
  247. if (NOT ${_prefix}_${_library}_LIBRARY AND NOT BLAS_FIND_QUIETLY AND BLAS_VERBOSE)
  248. Print_Find_Library_Blas_Status(blas ${_library} ${_libdir})
  249. endif ()
  250. set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
  251. set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
  252. endif(_libraries_work)
  253. endforeach(_library ${_list})
  254. if(_libraries_work)
  255. # Test this combination of libraries.
  256. if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND BLA_STATIC)
  257. list(INSERT ${LIBRARIES} 0 "-Wl,--start-group")
  258. list(APPEND ${LIBRARIES} "-Wl,--end-group")
  259. endif()
  260. set(CMAKE_REQUIRED_LIBRARIES "${_flags};${${LIBRARIES}};${_thread}")
  261. set(CMAKE_REQUIRED_FLAGS "${BLAS_COMPILER_FLAGS}")
  262. if (BLAS_VERBOSE)
  263. message("${Cyan}BLAS libs found for BLA_VENDOR ${BLA_VENDOR}."
  264. "Try to compile symbol ${_name} with following libraries:"
  265. "${CMAKE_REQUIRED_LIBRARIES}")
  266. endif ()
  267. if(NOT BLAS_FOUND)
  268. unset(${_prefix}${_combined_name}_WORKS CACHE)
  269. endif()
  270. if (_CHECK_FORTRAN)
  271. if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
  272. string(REPLACE "mkl_intel_lp64" "mkl_gf_lp64" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
  273. string(REPLACE "mkl_intel_ilp64" "mkl_gf_ilp64" CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
  274. endif()
  275. check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
  276. else()
  277. check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
  278. endif()
  279. mark_as_advanced(${_prefix}${_combined_name}_WORKS)
  280. set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
  281. # Print status if not found
  282. # -------------------------
  283. if (NOT _libraries_work AND NOT BLAS_FIND_QUIETLY AND BLAS_VERBOSE)
  284. Print_Find_Library_Blas_CheckFunc_Status(${_name} ${CMAKE_REQUIRED_LIBRARIES})
  285. endif ()
  286. set(CMAKE_REQUIRED_LIBRARIES)
  287. endif()
  288. if(_libraries_work)
  289. set(${LIBRARIES} ${${LIBRARIES}} ${_thread})
  290. else(_libraries_work)
  291. set(${LIBRARIES} FALSE)
  292. endif(_libraries_work)
  293. endmacro(Check_Fortran_Libraries)
  294. set(BLAS_LINKER_FLAGS)
  295. set(BLAS_LIBRARIES)
  296. set(BLAS95_LIBRARIES)
  297. if ($ENV{BLA_VENDOR} MATCHES ".+")
  298. set(BLA_VENDOR $ENV{BLA_VENDOR})
  299. else ()
  300. if(NOT BLA_VENDOR)
  301. set(BLA_VENDOR "All")
  302. endif()
  303. endif ()
  304. #BLAS in intel mkl 10 library? (em64t 64bit)
  305. if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
  306. if(NOT BLAS_LIBRARIES OR BLA_VENDOR MATCHES "Intel*")
  307. # Looking for include
  308. # -------------------
  309. # Add system include paths to search include
  310. # ------------------------------------------
  311. unset(_inc_env)
  312. set(ENV_MKLROOT "$ENV{MKLROOT}")
  313. set(ENV_BLAS_DIR "$ENV{BLAS_DIR}")
  314. set(ENV_BLAS_INCDIR "$ENV{BLAS_INCDIR}")
  315. if(ENV_BLAS_INCDIR)
  316. list(APPEND _inc_env "${ENV_BLAS_INCDIR}")
  317. elseif(ENV_BLAS_DIR)
  318. list(APPEND _inc_env "${ENV_BLAS_DIR}")
  319. list(APPEND _inc_env "${ENV_BLAS_DIR}/include")
  320. else()
  321. if (ENV_MKLROOT)
  322. list(APPEND _inc_env "${ENV_MKLROOT}/include")
  323. endif()
  324. # system variables
  325. if(WIN32)
  326. string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
  327. list(APPEND _inc_env "${_path_env}")
  328. else()
  329. string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
  330. list(APPEND _inc_env "${_path_env}")
  331. string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
  332. list(APPEND _inc_env "${_path_env}")
  333. string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
  334. list(APPEND _inc_env "${_path_env}")
  335. string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
  336. list(APPEND _inc_env "${_path_env}")
  337. endif()
  338. endif()
  339. list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
  340. list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
  341. list(REMOVE_DUPLICATES _inc_env)
  342. # set paths where to look for
  343. set(PATH_TO_LOOK_FOR "${_inc_env}")
  344. # Try to find the fftw header in the given paths
  345. # -------------------------------------------------
  346. # call cmake macro to find the header path
  347. if(BLAS_INCDIR)
  348. set(BLAS_mkl.h_DIRS "BLAS_mkl.h_DIRS-NOTFOUND")
  349. find_path(BLAS_mkl.h_DIRS
  350. NAMES mkl.h
  351. HINTS ${BLAS_INCDIR})
  352. else()
  353. if(BLAS_DIR)
  354. set(BLAS_mkl.h_DIRS "BLAS_mkl.h_DIRS-NOTFOUND")
  355. find_path(BLAS_mkl.h_DIRS
  356. NAMES mkl.h
  357. HINTS ${BLAS_DIR}
  358. PATH_SUFFIXES "include")
  359. else()
  360. set(BLAS_mkl.h_DIRS "BLAS_mkl.h_DIRS-NOTFOUND")
  361. find_path(BLAS_mkl.h_DIRS
  362. NAMES mkl.h
  363. HINTS ${PATH_TO_LOOK_FOR})
  364. endif()
  365. endif()
  366. mark_as_advanced(BLAS_mkl.h_DIRS)
  367. # If found, add path to cmake variable
  368. # ------------------------------------
  369. if (BLAS_mkl.h_DIRS)
  370. set(BLAS_INCLUDE_DIRS "${BLAS_mkl.h_DIRS}")
  371. else ()
  372. set(BLAS_INCLUDE_DIRS "BLAS_INCLUDE_DIRS-NOTFOUND")
  373. if(NOT BLAS_FIND_QUIETLY)
  374. message(STATUS "Looking for BLAS -- mkl.h not found")
  375. endif()
  376. endif()
  377. if (WIN32)
  378. string(REPLACE ":" ";" _libdir "$ENV{LIB}")
  379. elseif (APPLE)
  380. string(REPLACE ":" ";" _libdir "$ENV{DYLD_LIBRARY_PATH}")
  381. else ()
  382. string(REPLACE ":" ";" _libdir "$ENV{LD_LIBRARY_PATH}")
  383. endif ()
  384. list(APPEND _libdir "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}")
  385. list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
  386. # libiomp5
  387. # --------
  388. set(OMP_iomp5_LIBRARY "OMP_iomp5_LIBRARY-NOTFOUND")
  389. find_library(OMP_iomp5_LIBRARY
  390. NAMES iomp5
  391. HINTS ${_libdir}
  392. )
  393. mark_as_advanced(OMP_iomp5_LIBRARY)
  394. set(OMP_LIB "")
  395. # libgomp
  396. # -------
  397. set(OMP_gomp_LIBRARY "OMP_gomp_LIBRARY-NOTFOUND")
  398. find_library(OMP_gomp_LIBRARY
  399. NAMES gomp
  400. HINTS ${_libdir}
  401. )
  402. mark_as_advanced(OMP_gomp_LIBRARY)
  403. # choose one or another depending on the compilo
  404. if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
  405. if (OMP_gomp_LIBRARY)
  406. set(OMP_LIB "${OMP_gomp_LIBRARY}")
  407. endif()
  408. else(CMAKE_C_COMPILER_ID STREQUAL "Intel")
  409. if (OMP_iomp5_LIBRARY)
  410. set(OMP_LIB "${OMP_iomp5_LIBRARY}")
  411. endif()
  412. endif()
  413. if (UNIX AND NOT WIN32)
  414. # m
  415. find_library(M_LIBRARY
  416. NAMES m
  417. HINTS ${_libdir})
  418. mark_as_advanced(M_LIBRARY)
  419. if(M_LIBRARY)
  420. set(LM "-lm")
  421. else()
  422. set(LM "")
  423. endif()
  424. # Fortran
  425. set(LGFORTRAN "")
  426. if (CMAKE_C_COMPILER_ID MATCHES "GNU")
  427. find_library(
  428. FORTRAN_gfortran_LIBRARY
  429. NAMES gfortran
  430. HINTS ${_libdir}
  431. )
  432. mark_as_advanced(FORTRAN_gfortran_LIBRARY)
  433. if (FORTRAN_gfortran_LIBRARY)
  434. set(LGFORTRAN "${FORTRAN_gfortran_LIBRARY}")
  435. endif()
  436. elseif (CMAKE_C_COMPILER_ID MATCHES "Intel")
  437. find_library(
  438. FORTRAN_ifcore_LIBRARY
  439. NAMES ifcore
  440. HINTS ${_libdir}
  441. )
  442. mark_as_advanced(FORTRAN_ifcore_LIBRARY)
  443. if (FORTRAN_ifcore_LIBRARY)
  444. set(LGFORTRAN "{FORTRAN_ifcore_LIBRARY}")
  445. endif()
  446. endif()
  447. set(BLAS_COMPILER_FLAGS "")
  448. if (NOT BLA_VENDOR STREQUAL "Intel10_64lp_seq")
  449. if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
  450. list(APPEND BLAS_COMPILER_FLAGS "-openmp")
  451. endif()
  452. if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
  453. list(APPEND BLAS_COMPILER_FLAGS "-fopenmp")
  454. endif()
  455. endif()
  456. if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
  457. if (BLA_VENDOR STREQUAL "Intel10_32")
  458. list(APPEND BLAS_COMPILER_FLAGS "-m32")
  459. else()
  460. list(APPEND BLAS_COMPILER_FLAGS "-m64")
  461. endif()
  462. if (NOT BLA_VENDOR STREQUAL "Intel10_64lp_seq")
  463. list(APPEND OMP_LIB "-ldl")
  464. endif()
  465. if (ENV_MKLROOT)
  466. list(APPEND BLAS_COMPILER_FLAGS "-I${ENV_MKLROOT}/include")
  467. endif()
  468. endif()
  469. set(additional_flags "")
  470. if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
  471. set(additional_flags "-Wl,--no-as-needed")
  472. endif()
  473. endif ()
  474. if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
  475. if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  476. find_package(Threads)
  477. else()
  478. find_package(Threads REQUIRED)
  479. endif()
  480. set(BLAS_SEARCH_LIBS "")
  481. if(BLA_F95)
  482. set(BLAS_mkl_SEARCH_SYMBOL SGEMM)
  483. set(_LIBRARIES BLAS95_LIBRARIES)
  484. if (WIN32)
  485. if (BLA_STATIC)
  486. set(BLAS_mkl_DLL_SUFFIX "")
  487. else()
  488. set(BLAS_mkl_DLL_SUFFIX "_dll")
  489. endif()
  490. # Find the main file (32-bit or 64-bit)
  491. set(BLAS_SEARCH_LIBS_WIN_MAIN "")
  492. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  493. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  494. "mkl_blas95${BLAS_mkl_DLL_SUFFIX} mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
  495. endif()
  496. if (BLA_VENDOR STREQUAL "Intel10_64lp*" OR BLA_VENDOR STREQUAL "All")
  497. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  498. "mkl_blas95_lp64${BLAS_mkl_DLL_SUFFIX} mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}")
  499. endif ()
  500. # Add threading/sequential libs
  501. set(BLAS_SEARCH_LIBS_WIN_THREAD "")
  502. if (BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
  503. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  504. "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
  505. endif()
  506. if (NOT BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
  507. # old version
  508. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  509. "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  510. # mkl >= 10.3
  511. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  512. "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  513. endif()
  514. # Cartesian product of the above
  515. foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
  516. foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
  517. list(APPEND BLAS_SEARCH_LIBS
  518. "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
  519. endforeach()
  520. endforeach()
  521. else (WIN32)
  522. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  523. list(APPEND BLAS_SEARCH_LIBS
  524. "mkl_blas95 mkl_intel mkl_intel_thread mkl_core guide")
  525. endif ()
  526. if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
  527. # old version
  528. list(APPEND BLAS_SEARCH_LIBS
  529. "mkl_blas95 mkl_intel_lp64 mkl_intel_thread mkl_core guide")
  530. # mkl >= 10.3
  531. if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
  532. list(APPEND BLAS_SEARCH_LIBS
  533. "mkl_blas95_lp64 mkl_intel_lp64 mkl_intel_thread mkl_core")
  534. endif()
  535. if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
  536. list(APPEND BLAS_SEARCH_LIBS
  537. "mkl_blas95_lp64 mkl_intel_lp64 mkl_gnu_thread mkl_core")
  538. endif()
  539. endif ()
  540. if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
  541. list(APPEND BLAS_SEARCH_LIBS
  542. "mkl_intel_lp64 mkl_sequential mkl_core")
  543. if (BLA_VENDOR STREQUAL "Intel10_64lp_seq")
  544. set(OMP_LIB "")
  545. endif()
  546. endif ()
  547. endif (WIN32)
  548. else (BLA_F95)
  549. set(BLAS_mkl_SEARCH_SYMBOL sgemm)
  550. set(_LIBRARIES BLAS_LIBRARIES)
  551. if (WIN32)
  552. if (BLA_STATIC)
  553. set(BLAS_mkl_DLL_SUFFIX "")
  554. else()
  555. set(BLAS_mkl_DLL_SUFFIX "_dll")
  556. endif()
  557. # Find the main file (32-bit or 64-bit)
  558. set(BLAS_SEARCH_LIBS_WIN_MAIN "")
  559. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  560. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  561. "mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
  562. endif()
  563. if (BLA_VENDOR STREQUAL "Intel10_64lp*" OR BLA_VENDOR STREQUAL "All")
  564. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  565. "mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}")
  566. endif ()
  567. # Add threading/sequential libs
  568. set(BLAS_SEARCH_LIBS_WIN_THREAD "")
  569. if (NOT BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
  570. # old version
  571. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  572. "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  573. # mkl >= 10.3
  574. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  575. "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  576. endif()
  577. if (BLA_VENDOR STREQUAL "*_seq" OR BLA_VENDOR STREQUAL "All")
  578. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  579. "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
  580. endif()
  581. # Cartesian product of the above
  582. foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
  583. foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
  584. list(APPEND BLAS_SEARCH_LIBS
  585. "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
  586. endforeach()
  587. endforeach()
  588. else (WIN32)
  589. if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  590. list(APPEND BLAS_SEARCH_LIBS
  591. "mkl_intel mkl_intel_thread mkl_core guide")
  592. endif ()
  593. if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
  594. # old version
  595. list(APPEND BLAS_SEARCH_LIBS
  596. "mkl_intel_lp64 mkl_intel_thread mkl_core guide")
  597. # mkl >= 10.3
  598. if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
  599. list(APPEND BLAS_SEARCH_LIBS
  600. "mkl_intel_lp64 mkl_intel_thread mkl_core")
  601. endif()
  602. if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
  603. list(APPEND BLAS_SEARCH_LIBS
  604. "mkl_intel_lp64 mkl_gnu_thread mkl_core")
  605. endif()
  606. endif ()
  607. if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All")
  608. list(APPEND BLAS_SEARCH_LIBS
  609. "mkl_intel_lp64 mkl_sequential mkl_core")
  610. if (BLA_VENDOR STREQUAL "Intel10_64lp_seq")
  611. set(OMP_LIB "")
  612. endif()
  613. endif ()
  614. #older vesions of intel mkl libs
  615. if (BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All")
  616. list(APPEND BLAS_SEARCH_LIBS
  617. "mkl")
  618. list(APPEND BLAS_SEARCH_LIBS
  619. "mkl_ia32")
  620. list(APPEND BLAS_SEARCH_LIBS
  621. "mkl_em64t")
  622. endif ()
  623. endif (WIN32)
  624. endif (BLA_F95)
  625. foreach (IT ${BLAS_SEARCH_LIBS})
  626. string(REPLACE " " ";" SEARCH_LIBS ${IT})
  627. if (${_LIBRARIES})
  628. else ()
  629. check_fortran_libraries(
  630. ${_LIBRARIES}
  631. BLAS
  632. ${BLAS_mkl_SEARCH_SYMBOL}
  633. "${additional_flags}"
  634. "${SEARCH_LIBS}"
  635. "${OMP_LIB};${CMAKE_THREAD_LIBS_INIT};${LM}"
  636. )
  637. if(_LIBRARIES)
  638. set(BLAS_LINKER_FLAGS "${additional_flags}")
  639. endif()
  640. endif()
  641. endforeach ()
  642. if(NOT BLAS_FIND_QUIETLY)
  643. if(${_LIBRARIES})
  644. message(STATUS "Looking for MKL BLAS: found")
  645. else()
  646. message(STATUS "Looking for MKL BLAS: not found")
  647. endif()
  648. endif()
  649. if (${_LIBRARIES} AND NOT BLAS_VENDOR_FOUND)
  650. set (BLAS_VENDOR_FOUND "Intel MKL")
  651. endif()
  652. endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX)
  653. endif(NOT BLAS_LIBRARIES OR BLA_VENDOR MATCHES "Intel*")
  654. endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All")
  655. if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
  656. if(NOT BLAS_LIBRARIES)
  657. # gotoblas (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
  658. check_fortran_libraries(
  659. BLAS_LIBRARIES
  660. BLAS
  661. sgemm
  662. ""
  663. "goto2"
  664. ""
  665. )
  666. if(NOT BLAS_FIND_QUIETLY)
  667. if(BLAS_LIBRARIES)
  668. message(STATUS "Looking for Goto BLAS: found")
  669. else()
  670. message(STATUS "Looking for Goto BLAS: not found")
  671. endif()
  672. endif()
  673. endif()
  674. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  675. set (BLAS_VENDOR_FOUND "Goto")
  676. endif()
  677. endif (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
  678. # OpenBlas
  679. if (BLA_VENDOR STREQUAL "Open" OR BLA_VENDOR STREQUAL "All")
  680. if(NOT BLAS_LIBRARIES)
  681. # openblas (http://www.openblas.net/)
  682. check_fortran_libraries(
  683. BLAS_LIBRARIES
  684. BLAS
  685. sgemm
  686. ""
  687. "openblas"
  688. ""
  689. )
  690. if(NOT BLAS_FIND_QUIETLY)
  691. if(BLAS_LIBRARIES)
  692. message(STATUS "Looking for Open BLAS: found")
  693. else()
  694. message(STATUS "Looking for Open BLAS: not found")
  695. endif()
  696. endif()
  697. endif()
  698. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  699. set (BLAS_VENDOR_FOUND "Openblas")
  700. endif()
  701. endif (BLA_VENDOR STREQUAL "Open" OR BLA_VENDOR STREQUAL "All")
  702. # EigenBlas
  703. if (BLA_VENDOR STREQUAL "Eigen" OR BLA_VENDOR STREQUAL "All")
  704. if(NOT BLAS_LIBRARIES)
  705. # eigenblas (http://eigen.tuxfamily.org/index.php?title=Main_Page)
  706. check_fortran_libraries(
  707. BLAS_LIBRARIES
  708. BLAS
  709. sgemm
  710. ""
  711. "eigen_blas"
  712. ""
  713. )
  714. if(NOT BLAS_FIND_QUIETLY)
  715. if(BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  716. message(STATUS "Looking for Eigen BLAS: found")
  717. else()
  718. message(STATUS "Looking for Eigen BLAS: not found")
  719. endif()
  720. endif()
  721. endif()
  722. if(NOT BLAS_LIBRARIES)
  723. # eigenblas (http://eigen.tuxfamily.org/index.php?title=Main_Page)
  724. check_fortran_libraries(
  725. BLAS_LIBRARIES
  726. BLAS
  727. sgemm
  728. ""
  729. "eigen_blas_static"
  730. ""
  731. )
  732. if(NOT BLAS_FIND_QUIETLY)
  733. if(BLAS_LIBRARIES)
  734. message(STATUS "Looking for Eigen BLAS: found")
  735. else()
  736. message(STATUS "Looking for Eigen BLAS: not found")
  737. endif()
  738. endif()
  739. endif()
  740. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  741. set (BLAS_VENDOR_FOUND "Eigen")
  742. endif()
  743. endif (BLA_VENDOR STREQUAL "Eigen" OR BLA_VENDOR STREQUAL "All")
  744. if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
  745. if(NOT BLAS_LIBRARIES)
  746. # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
  747. check_fortran_libraries(
  748. BLAS_LIBRARIES
  749. BLAS
  750. dgemm
  751. ""
  752. "f77blas;atlas"
  753. ""
  754. )
  755. if(NOT BLAS_FIND_QUIETLY)
  756. if(BLAS_LIBRARIES)
  757. message(STATUS "Looking for Atlas BLAS: found")
  758. else()
  759. message(STATUS "Looking for Atlas BLAS: not found")
  760. endif()
  761. endif()
  762. endif()
  763. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  764. set (BLAS_VENDOR_FOUND "Atlas")
  765. endif()
  766. endif (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
  767. # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
  768. if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
  769. if(NOT BLAS_LIBRARIES)
  770. check_fortran_libraries(
  771. BLAS_LIBRARIES
  772. BLAS
  773. sgemm
  774. ""
  775. "sgemm;dgemm;blas"
  776. ""
  777. )
  778. if(NOT BLAS_FIND_QUIETLY)
  779. if(BLAS_LIBRARIES)
  780. message(STATUS "Looking for PhiPACK BLAS: found")
  781. else()
  782. message(STATUS "Looking for PhiPACK BLAS: not found")
  783. endif()
  784. endif()
  785. endif()
  786. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  787. set (BLAS_VENDOR_FOUND "PhiPACK")
  788. endif()
  789. endif (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
  790. # BLAS in Alpha CXML library?
  791. if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
  792. if(NOT BLAS_LIBRARIES)
  793. check_fortran_libraries(
  794. BLAS_LIBRARIES
  795. BLAS
  796. sgemm
  797. ""
  798. "cxml"
  799. ""
  800. )
  801. if(NOT BLAS_FIND_QUIETLY)
  802. if(BLAS_LIBRARIES)
  803. message(STATUS "Looking for CXML BLAS: found")
  804. else()
  805. message(STATUS "Looking for CXML BLAS: not found")
  806. endif()
  807. endif()
  808. endif()
  809. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  810. set (BLAS_VENDOR_FOUND "CXML")
  811. endif()
  812. endif (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
  813. # BLAS in Alpha DXML library? (now called CXML, see above)
  814. if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
  815. if(NOT BLAS_LIBRARIES)
  816. check_fortran_libraries(
  817. BLAS_LIBRARIES
  818. BLAS
  819. sgemm
  820. ""
  821. "dxml"
  822. ""
  823. )
  824. if(NOT BLAS_FIND_QUIETLY)
  825. if(BLAS_LIBRARIES)
  826. message(STATUS "Looking for DXML BLAS: found")
  827. else()
  828. message(STATUS "Looking for DXML BLAS: not found")
  829. endif()
  830. endif()
  831. endif()
  832. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  833. set (BLAS_VENDOR_FOUND "DXML")
  834. endif()
  835. endif (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
  836. # BLAS in Sun Performance library?
  837. if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
  838. if(NOT BLAS_LIBRARIES)
  839. check_fortran_libraries(
  840. BLAS_LIBRARIES
  841. BLAS
  842. sgemm
  843. "-xlic_lib=sunperf"
  844. "sunperf;sunmath"
  845. ""
  846. )
  847. if(BLAS_LIBRARIES)
  848. set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
  849. endif()
  850. if(NOT BLAS_FIND_QUIETLY)
  851. if(BLAS_LIBRARIES)
  852. message(STATUS "Looking for SunPerf BLAS: found")
  853. else()
  854. message(STATUS "Looking for SunPerf BLAS: not found")
  855. endif()
  856. endif()
  857. endif()
  858. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  859. set (BLAS_VENDOR_FOUND "SunPerf")
  860. endif()
  861. endif ()
  862. # BLAS in SCSL library? (SGI/Cray Scientific Library)
  863. if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
  864. if(NOT BLAS_LIBRARIES)
  865. check_fortran_libraries(
  866. BLAS_LIBRARIES
  867. BLAS
  868. sgemm
  869. ""
  870. "scsl"
  871. ""
  872. )
  873. if(NOT BLAS_FIND_QUIETLY)
  874. if(BLAS_LIBRARIES)
  875. message(STATUS "Looking for SCSL BLAS: found")
  876. else()
  877. message(STATUS "Looking for SCSL BLAS: not found")
  878. endif()
  879. endif()
  880. endif()
  881. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  882. set (BLAS_VENDOR_FOUND "SunPerf")
  883. endif()
  884. endif ()
  885. # BLAS in SGIMATH library?
  886. if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
  887. if(NOT BLAS_LIBRARIES)
  888. check_fortran_libraries(
  889. BLAS_LIBRARIES
  890. BLAS
  891. sgemm
  892. ""
  893. "complib.sgimath"
  894. ""
  895. )
  896. if(NOT BLAS_FIND_QUIETLY)
  897. if(BLAS_LIBRARIES)
  898. message(STATUS "Looking for SGIMATH BLAS: found")
  899. else()
  900. message(STATUS "Looking for SGIMATH BLAS: not found")
  901. endif()
  902. endif()
  903. endif()
  904. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  905. set (BLAS_VENDOR_FOUND "SGIMATH")
  906. endif()
  907. endif ()
  908. # BLAS in IBM ESSL library (requires generic BLAS lib, too)
  909. if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
  910. if(NOT BLAS_LIBRARIES)
  911. check_fortran_libraries(
  912. BLAS_LIBRARIES
  913. BLAS
  914. sgemm
  915. ""
  916. "essl;xlfmath;xlf90_r;blas"
  917. ""
  918. )
  919. if(NOT BLAS_FIND_QUIETLY)
  920. if(BLAS_LIBRARIES)
  921. message(STATUS "Looking for IBM ESSL BLAS: found")
  922. else()
  923. message(STATUS "Looking for IBM ESSL BLAS: not found")
  924. endif()
  925. endif()
  926. endif()
  927. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  928. set (BLAS_VENDOR_FOUND "IBM ESSL")
  929. endif()
  930. endif ()
  931. # BLAS in IBM ESSL_MT library (requires generic BLAS lib, too)
  932. if (BLA_VENDOR STREQUAL "IBMESSLMT" OR BLA_VENDOR STREQUAL "All")
  933. if(NOT BLAS_LIBRARIES)
  934. check_fortran_libraries(
  935. BLAS_LIBRARIES
  936. BLAS
  937. sgemm
  938. ""
  939. "esslsmp;xlsmp;xlfmath;xlf90_r;blas"
  940. ""
  941. )
  942. if(NOT BLAS_FIND_QUIETLY)
  943. if(BLAS_LIBRARIES)
  944. message(STATUS "Looking for IBM ESSL MT BLAS: found")
  945. else()
  946. message(STATUS "Looking for IBM ESSL MT BLAS: not found")
  947. endif()
  948. endif()
  949. endif()
  950. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  951. set (BLAS_VENDOR_FOUND "IBM ESSL MT")
  952. endif()
  953. endif ()
  954. #BLAS in acml library?
  955. if (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All")
  956. if( ((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
  957. ((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR
  958. ((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS)))
  959. # try to find acml in "standard" paths
  960. if( WIN32 )
  961. file( GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt" )
  962. else()
  963. file( GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt" )
  964. endif()
  965. if( WIN32 )
  966. file( GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples" )
  967. else()
  968. file( GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples" )
  969. endif()
  970. list(GET _ACML_ROOT 0 _ACML_ROOT)
  971. list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)
  972. if( _ACML_ROOT )
  973. get_filename_component( _ACML_ROOT ${_ACML_ROOT} PATH )
  974. if( SIZEOF_INTEGER EQUAL 8 )
  975. set( _ACML_PATH_SUFFIX "_int64" )
  976. else()
  977. set( _ACML_PATH_SUFFIX "" )
  978. endif()
  979. if( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
  980. set( _ACML_COMPILER32 "ifort32" )
  981. set( _ACML_COMPILER64 "ifort64" )
  982. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
  983. set( _ACML_COMPILER32 "sun32" )
  984. set( _ACML_COMPILER64 "sun64" )
  985. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" )
  986. set( _ACML_COMPILER32 "pgi32" )
  987. if( WIN32 )
  988. set( _ACML_COMPILER64 "win64" )
  989. else()
  990. set( _ACML_COMPILER64 "pgi64" )
  991. endif()
  992. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Open64" )
  993. # 32 bit builds not supported on Open64 but for code simplicity
  994. # We'll just use the same directory twice
  995. set( _ACML_COMPILER32 "open64_64" )
  996. set( _ACML_COMPILER64 "open64_64" )
  997. elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" )
  998. set( _ACML_COMPILER32 "nag32" )
  999. set( _ACML_COMPILER64 "nag64" )
  1000. else()
  1001. set( _ACML_COMPILER32 "gfortran32" )
  1002. set( _ACML_COMPILER64 "gfortran64" )
  1003. endif()
  1004. if( BLA_VENDOR STREQUAL "ACML_MP" )
  1005. set(_ACML_MP_LIB_DIRS
  1006. "${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib"
  1007. "${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib" )
  1008. else()
  1009. set(_ACML_LIB_DIRS
  1010. "${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib"
  1011. "${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib" )
  1012. endif()
  1013. endif(_ACML_ROOT)
  1014. elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)
  1015. set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})
  1016. endif()
  1017. if( BLA_VENDOR STREQUAL "ACML_MP" )
  1018. foreach( BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS})
  1019. check_fortran_libraries (
  1020. BLAS_LIBRARIES
  1021. BLAS
  1022. sgemm
  1023. "" "acml_mp;acml_mv" "" ${BLAS_ACML_MP_LIB_DIRS}
  1024. )
  1025. if( BLAS_LIBRARIES )
  1026. break()
  1027. endif()
  1028. endforeach()
  1029. elseif( BLA_VENDOR STREQUAL "ACML_GPU" )
  1030. foreach( BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS})
  1031. check_fortran_libraries (
  1032. BLAS_LIBRARIES
  1033. BLAS
  1034. sgemm
  1035. "" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS}
  1036. )
  1037. if( BLAS_LIBRARIES )
  1038. break()
  1039. endif()
  1040. endforeach()
  1041. else()
  1042. foreach( BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS} )
  1043. check_fortran_libraries (
  1044. BLAS_LIBRARIES
  1045. BLAS
  1046. sgemm
  1047. "" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS}
  1048. )
  1049. if( BLAS_LIBRARIES )
  1050. break()
  1051. endif()
  1052. endforeach()
  1053. endif()
  1054. # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
  1055. if(NOT BLAS_LIBRARIES)
  1056. check_fortran_libraries(
  1057. BLAS_LIBRARIES
  1058. BLAS
  1059. sgemm
  1060. ""
  1061. "acml;acml_mv"
  1062. ""
  1063. )
  1064. if(NOT BLAS_FIND_QUIETLY)
  1065. if(BLAS_LIBRARIES)
  1066. message(STATUS "Looking for ACML BLAS: found")
  1067. else()
  1068. message(STATUS "Looking for ACML BLAS: not found")
  1069. endif()
  1070. endif()
  1071. endif()
  1072. if(NOT BLAS_LIBRARIES)
  1073. check_fortran_libraries(
  1074. BLAS_LIBRARIES
  1075. BLAS
  1076. sgemm
  1077. ""
  1078. "acml_mp;acml_mv"
  1079. ""
  1080. )
  1081. if(NOT BLAS_FIND_QUIETLY)
  1082. if(BLAS_LIBRARIES)
  1083. message(STATUS "Looking for ACML BLAS: found")
  1084. else()
  1085. message(STATUS "Looking for ACML BLAS: not found")
  1086. endif()
  1087. endif()
  1088. endif()
  1089. if(NOT BLAS_LIBRARIES)
  1090. check_fortran_libraries(
  1091. BLAS_LIBRARIES
  1092. BLAS
  1093. sgemm
  1094. ""
  1095. "acml;acml_mv;CALBLAS"
  1096. ""
  1097. )
  1098. if(NOT BLAS_FIND_QUIETLY)
  1099. if(BLAS_LIBRARIES)
  1100. message(STATUS "Looking for ACML BLAS: found")
  1101. else()
  1102. message(STATUS "Looking for ACML BLAS: not found")
  1103. endif()
  1104. endif()
  1105. endif()
  1106. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  1107. set (BLAS_VENDOR_FOUND "ACML")
  1108. endif()
  1109. endif (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All") # ACML
  1110. # Apple BLAS library?
  1111. if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  1112. if(NOT BLAS_LIBRARIES)
  1113. check_fortran_libraries(
  1114. BLAS_LIBRARIES
  1115. BLAS
  1116. dgemm
  1117. ""
  1118. "Accelerate"
  1119. ""
  1120. )
  1121. if(NOT BLAS_FIND_QUIETLY)
  1122. if(BLAS_LIBRARIES)
  1123. message(STATUS "Looking for Apple BLAS: found")
  1124. else()
  1125. message(STATUS "Looking for Apple BLAS: not found")
  1126. endif()
  1127. endif()
  1128. endif()
  1129. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  1130. set (BLAS_VENDOR_FOUND "Apple Accelerate")
  1131. endif()
  1132. endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  1133. if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  1134. if ( NOT BLAS_LIBRARIES )
  1135. check_fortran_libraries(
  1136. BLAS_LIBRARIES
  1137. BLAS
  1138. dgemm
  1139. ""
  1140. "vecLib"
  1141. ""
  1142. )
  1143. if(NOT BLAS_FIND_QUIETLY)
  1144. if(BLAS_LIBRARIES)
  1145. message(STATUS "Looking for NAS BLAS: found")
  1146. else()
  1147. message(STATUS "Looking for NAS BLAS: not found")
  1148. endif()
  1149. endif()
  1150. endif ()
  1151. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  1152. set (BLAS_VENDOR_FOUND "NAS")
  1153. endif()
  1154. endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  1155. # Generic BLAS library?
  1156. if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  1157. set(BLAS_SEARCH_LIBS "blas;blas_LINUX;blas_MAC;blas_WINDOWS;refblas")
  1158. foreach (SEARCH_LIB ${BLAS_SEARCH_LIBS})
  1159. if (BLAS_LIBRARIES)
  1160. else ()
  1161. check_fortran_libraries(
  1162. BLAS_LIBRARIES
  1163. BLAS
  1164. sgemm
  1165. ""
  1166. "${SEARCH_LIB}"
  1167. "${LGFORTRAN}"
  1168. )
  1169. if(NOT BLAS_FIND_QUIETLY)
  1170. if(BLAS_LIBRARIES)
  1171. message(STATUS "Looking for Generic BLAS: found")
  1172. else()
  1173. message(STATUS "Looking for Generic BLAS: not found")
  1174. endif()
  1175. endif()
  1176. endif()
  1177. endforeach ()
  1178. if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
  1179. set (BLAS_VENDOR_FOUND "Netlib or other Generic libblas")
  1180. endif()
  1181. endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  1182. if(BLA_F95)
  1183. if(BLAS95_LIBRARIES)
  1184. set(BLAS95_FOUND TRUE)
  1185. else()
  1186. set(BLAS95_FOUND FALSE)
  1187. endif()
  1188. if(NOT BLAS_FIND_QUIETLY)
  1189. if(BLAS95_FOUND)
  1190. message(STATUS "A library with BLAS95 API found.")
  1191. message(STATUS "BLAS_LIBRARIES ${BLAS_LIBRARIES}")
  1192. else(BLAS95_FOUND)
  1193. message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but blas 95 libraries could not be found or check of symbols failed."
  1194. "\nPlease indicate where to find blas libraries. You have three options:\n"
  1195. "- Option 1: Provide the installation directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
  1196. "- Option 2: Provide the directory where to find BLAS libraries with cmake option: -DBLAS_LIBDIR=your/path/to/blas/libs\n"
  1197. "- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
  1198. "\nTo follow libraries detection more precisely you can activate a verbose mode with -DBLAS_VERBOSE=ON at cmake configure."
  1199. "\nYou could also specify a BLAS vendor to look for by setting -DBLA_VENDOR=blas_vendor_name."
  1200. "\nList of possible BLAS vendor: Goto, ATLAS PhiPACK, CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, Intel10_32 (intel mkl v10 32 bit),"
  1201. "Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model), Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),"
  1202. "Intel( older versions of mkl 32 and 64 bit), ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
  1203. if(BLAS_FIND_REQUIRED)
  1204. message(FATAL_ERROR
  1205. "A required library with BLAS95 API not found. Please specify library location.")
  1206. else()
  1207. message(STATUS
  1208. "A library with BLAS95 API not found. Please specify library location.")
  1209. endif()
  1210. endif(BLAS95_FOUND)
  1211. endif(NOT BLAS_FIND_QUIETLY)
  1212. set(BLAS_FOUND TRUE)
  1213. set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
  1214. else(BLA_F95)
  1215. if(BLAS_LIBRARIES)
  1216. set(BLAS_FOUND TRUE)
  1217. else()
  1218. set(BLAS_FOUND FALSE)
  1219. endif()
  1220. if(NOT BLAS_FIND_QUIETLY)
  1221. if(BLAS_FOUND)
  1222. message(STATUS "A library with BLAS API found.")
  1223. message(STATUS "BLAS_LIBRARIES ${BLAS_LIBRARIES}")
  1224. else(BLAS_FOUND)
  1225. message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but blas libraries could not be found or check of symbols failed."
  1226. "\nPlease indicate where to find blas libraries. You have three options:\n"
  1227. "- Option 1: Provide the installation directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
  1228. "- Option 2: Provide the directory where to find BLAS libraries with cmake option: -DBLAS_LIBDIR=your/path/to/blas/libs\n"
  1229. "- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
  1230. "\nTo follow libraries detection more precisely you can activate a verbose mode with -DBLAS_VERBOSE=ON at cmake configure."
  1231. "\nYou could also specify a BLAS vendor to look for by setting -DBLA_VENDOR=blas_vendor_name."
  1232. "\nList of possible BLAS vendor: Goto, ATLAS PhiPACK, CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, Intel10_32 (intel mkl v10 32 bit),"
  1233. "Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model), Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),"
  1234. "Intel( older versions of mkl 32 and 64 bit), ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
  1235. if(BLAS_FIND_REQUIRED)
  1236. message(FATAL_ERROR
  1237. "A required library with BLAS API not found. Please specify library location.")
  1238. else()
  1239. message(STATUS
  1240. "A library with BLAS API not found. Please specify library location.")
  1241. endif()
  1242. endif(BLAS_FOUND)
  1243. endif(NOT BLAS_FIND_QUIETLY)
  1244. endif(BLA_F95)
  1245. set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
  1246. if (BLAS_FOUND)
  1247. list(GET BLAS_LIBRARIES 0 first_lib)
  1248. get_filename_component(first_lib_path "${first_lib}" PATH)
  1249. if (${first_lib_path} MATCHES "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)")
  1250. string(REGEX REPLACE "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)" "" not_cached_dir "${first_lib_path}")
  1251. set(BLAS_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of BLAS library" FORCE)
  1252. else()
  1253. set(BLAS_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of BLAS library" FORCE)
  1254. endif()
  1255. endif()
  1256. mark_as_advanced(BLAS_DIR)
  1257. mark_as_advanced(BLAS_DIR_FOUND)