Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find BLAS include directory with CMake

Tags:

cmake

blas

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.

like image 687
Søren V. Poulsen Avatar asked Sep 28 '16 13:09

Søren V. Poulsen


1 Answers

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/")
like image 66
paul-g Avatar answered Oct 21 '22 23:10

paul-g