9

In CMake I use find_package(BLAS REQUIRED) and I use the BLAS_FOUND, BLAS_LINKER_FLAGS, BLAS_LIBRARIES variables as appropriate.

My question is, how do I, based on the BLAS implementation that has been selected, find the include directory that should be included in CMake?

BLAS_INCLUDE_DIR is not being set on macOS for either the Accelerate framework nor OpenBLAS. Also it's not part of the documentation for FindBLAS.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
  • there should be a cmake-config file provided by BLAS which sets those variables. You can check in there what is set. – Hayt Sep 28 '16 at 13:33
  • 1
    @Hayt: There is no cmake-config file supplied with BLAS, there is only [FindBLAS.cmake](https://github.com/Kitware/CMake/blob/master/Modules/FindBLAS.cmake) script supplied with CMake. This script sets only *linker-related* variables (`BLAS_LIBRARIES` and `BLAS_LINKER_FLAGS`). – Tsyvarev Sep 28 '16 at 19:23
  • then you will have to set the include dir yourself. find_package() only sets the variables which are in the FindBLAS.cmake – Hayt Sep 29 '16 at 07:09
  • Some BLASes don't provide the `cblas.h` header. oneAPI MKL provides a header named `mkl_cblas.h`. Also worth noting that you should link to `BLAS::BLAS` rather than using the variables these days. – Alex Reinking Feb 15 '23 at 20:53

1 Answers1

2

If there isn't a script already provided, you can write one yourself or extend the existing FindBLAS.cmake to set required path (BLAS_INCLUDE_DIRS).

For example you could use find_path in order to search for the directory containing some standard BLAS include files, or specifically the ones required in your project. You can include as default common directories where you might expect BLAS to be installed, or paths based on environment variables. An example for Linux:

find_path(BLAS_INCLUDE_DIRS cblas.h
  /usr/include
  /usr/local/include
  $ENV{BLAS_HOME}/include)

This will search for cblas.h in /usr/include/, /usr/local/include, $ENV{BLAS_HOME}/include and set the found path in BLAS_INCLUDE_DIRS.

You can add this script in a src/cmake/FindBLAS.cmake file in your project and then tell your top level Cmake file about it with:

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/src/cmake/")
paul-g
  • 3,797
  • 2
  • 21
  • 36