Adding alternative CMake support
Hi,
I had some issues with the existing CMake configurations.
Using find_package(blaze) only works if the library has been exportet, which requires CMake to configure the project. But that means that settings like multithreading or the BLAS/LAPACK libraries are already set when you attempt to use blaze.
In my opinion these settings should not be made when the library is exported, but imported. Since this is a header only library with nothing actually build I think this applies even more.
Also I had some issues finding MKL using FindBLAS and FindLAPACK. And from what I have seen this is not uncommon.
As a result I wrote a new CMake file to import Blaze. It works as a function instead of a find module. In my opinion this has some advantages. find_package is pretty restricted with its arguments, limiting flexibility and readability.
To import Blaze this way you use it like this:
IMPORT_BLAZE(
BLAS ON
THREADING C++11
CACHE auto
)
Aside from the import blaze can then be used like any find module. The only thing is that it requires the module paths to be appended with blaze and the function to be included like any other function. This is in my opinion a much cleaner way.
Since it is only a single CMake function file it does also not have any influence on the existing CMake files, allowing it to be used just like before. Therefore it introduces a second, completly independent way to include blaze.
The file is not finished yet, it's just a prototype. I was wondering if you would be interesting in adding it when it's finished?
Best regards
Thorsten
ps: Adding an export to the existing CMakeLists might allow usig it without manually appending the module paths
pps: I was thinking about extending it to include submodules like this
IMPORT_BLAZE(
THREADING C++11
COMPONENTS tensor
)
to import projects like BlazeTensor as well.
Comments (3)
-
-
-
assigned issue to
-
assigned issue to
-
- changed status to resolved
Summary
The feature has been implemented in pull request 34. It is immediately available via cloning the Blaze repository and will be officially released in Blaze 3.7.
Installation via CMake
The first step is the installation of the Blaze header files. The most convenient way to do this is via CMake. Linux and macOS users can use the following two lines to copy the Blaze headers in the
./blaze
subdirectory to the directory${CMAKE_INSTALL_PREFIX}/include
and the package configuration files to${CMAKE_INSTALL_PREFIX}/share/blaze/cmake
.cmake -DCMAKE_INSTALL_PREFIX=/usr/local/ sudo make install
Windows users can do the same via the cmake-gui. Alternatively, it is possible to include Blaze by adding the following lines in any
CMakeLists.txt
file:find_package( blaze ) if( blaze_FOUND ) add_library( blaze_target INTERFACE ) target_link_libraries( blaze_target INTERFACE blaze::blaze ) endif()
Alternatively Blaze provides the
./cmake/Blaze_Import
CMake function to import the Blaze library into CMake based projects. This approach includes the configuration step (see Step 2: Configuration). To do so you need to import the function file like any other module/function into your CMake project:list(APPEND CMAKE_MODULE_PATH ${BLAZE_LIBRARY_PATH}/cmake) include(Blaze_Import)
After importing the function script you can import and use the Blaze library:
Blaze_Import(ARGUMENTS) target_link_libraries(TARGET Blaze)
In this example,
TARGET
is the executable/library using Blaze andARGUMENTS
is the configuration you want for building Blaze. To configure Blaze using the import function you can set the input arguments like this example:Blaze_Import( QUIET BLAS on LAPACK on THREADING Boost CACHE_SIZE auto VECTORIZATION on STORAGE_ORDER rowMajor THRESHOLD_DMATDVECMULT 100000UL THRESHOLD_SMP_DVECDVECADD 1000000UL )
For more details about available configuration options please have a look at Configuration Files and the
Blaze_Import.cmake
function script. - Log in to comment
Hi Thorsten!
Any help that makes it easier to use and/or configure Blaze is very welcome. So please feel free to create a pull request with your final solution.
Best regards,
Klaus!