- CMake Cookbook
- Radovan Bast Roberto Di Remigio
- 266字
- 2025-04-04 16:17:18
How it works
FindBLAS.cmake and FindLAPACK.cmake will look in standard locations for libraries offering the standard BLAS and LAPACK APIs. For the former, the module will look for the Fortran implementation of the SGEMM function, for single-precision matrix-matrix products for general matrices. For the latter, the module searches for the Fortran implementation of the CHEEV function, for the calculation of eigenvalues and eigenvectors of complex, Hermitian matrices. These lookups are carried out internally by compiling a small program calling these functions and trying to link against the candidate libraries. If that fails, it signals that a compliant library is not available on the system.
Every compiler performs name-mangling of symbols when generating machine code and unfortunately conventions for this operation are not universal, but compiler-dependent. To overcome this difficulty, we have used the FortranCInterface module (https://cmake.org/cmake/help/v3.5/module/FortranCInterface.html) to both verify that the Fortran and C/C++ compilers work together and to generate a Fortran-C interface header fc_mangle.h which is compatible with the compiler in question. The generated fc_mangle.h must then be included in the interface header files CxxBLAS.hpp and CxxLAPACK.hpp. We had to add C and Fortran support to the list of LANGUAGES in order to use FortranCInterface. Of course we could have defined own preprocessor definitions instead, however at the price of limited portability.
We will discuss the interoperability of Fortran and C more closely in Chapter 9, Mixed-language Projects.