FindBLAS.cmake 42 KB

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