瀏覽代碼

FindBLAS: optionally query pkg-config for a library

This is more or less what Gentoo implements for years, but in a more
sophisticated version that uses the target mode now offered by
pkg_check_modules().
Rolf Eike Beer 8 年之前
父節點
當前提交
a9c42e3ec0
共有 1 個文件被更改,包括 19 次插入0 次删除
  1. 19 0
      Modules/FindBLAS.cmake

+ 19 - 0
Modules/FindBLAS.cmake

@@ -27,10 +27,17 @@
 #     to link against to use BLAS95 interface
 #   BLAS95_FOUND - set to true if a library implementing the BLAS f95 interface
 #     is found
+#
+# The following variables can be used to control this module:
+#
+# ::
+#
 #   BLA_STATIC  if set on this determines what kind of linkage we do (static)
 #   BLA_VENDOR  if set checks only the specified vendor, if not set checks
 #      all the possibilities
 #   BLA_F95     if set on tries to find the f95 interfaces for BLAS/LAPACK
+#   BLA_PREFER_PKGCONFIG  if set pkg-config will be used to search for a BLAS
+#      library first and if one is found that is preferred
 #
 # List of vendors (BLA_VENDOR) valid in this module:
 #
@@ -79,6 +86,18 @@ if( NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_C
   endif()
 endif()
 
+if(BLA_PREFER_PKGCONFIG)
+  find_package(PkgConfig)
+  pkg_check_modules(PKGC_BLAS IMPORTED_TARGET blas)
+  if(PKGC_BLAS_FOUND)
+    set(BLAS_LIBRARIES PkgConfig::PKGC_BLAS)
+    find_package_handle_standard_args(BLAS
+                                      REQUIRED_VARS BLAS_LIBRARIES
+                                      VERSION_VAR PKGC_BLAS_VERSION)
+    return()
+  endif()
+endif()
+
 macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _thread)
 # This macro checks for the existence of the combination of fortran libraries
 # given by _list.  If the combination is found, this macro checks (using the