[CMake] Add external static libraries / ar-archives to a build.

Alan W. Irwin irwin at beluga.phys.uvic.ca
Tue Oct 21 12:26:49 EDT 2008


On 2008-10-21 10:06+0200 Martin Köhler wrote:

> Hi,
> I'm working on a library to solve sparse linear systems. All basic vector operations are realized by using the BLAS. The FindBLAS works fine but most of the blas implementations are provided as an ar-archive somewhere in the filesystem ( we use a standard blas, ATLAS, GotoBlas or malefactor specific variants). Is it possible to pass the wanted libblas.a as a parameter to cmake and add it to a target?
> For example when I want to use  the GotoBLAS  I want to call cmake this way:
> cmake -DBLAS=/path/to/lib/libgoto.a PATH_TO_SOURCE
>
> If I link the lib manually I enter
> gcc -o output myfile.c /path/to/lib/libgoto.a
>
> Is there an easy way to do so in cmake? The static linking is necessary because programs based on this library are executed on an MPI-Cluster and working with dynamic libraries is more than buggy.
>

Alin Elena is the official maintainer of FindBLAS.cmake. However, I created
the original primitive version of that Find module that he has so much
improved which is why I still have an on-going interest.

FindBLAS.cmake sharply improved for CMake-2.6.1 with a much longer list
of BLAS vendors and methods to pick the vendor.

Normally with that version you should be able to use the documented
BLA_VENDOR and BLA_STATIC variables to pick out whatever vendor version of
libBLAS that you want.  However, there is a problem in your case. I just
checked that version and there is no mention of GotoBLAS
(http://www.tacc.utexas.edu/resources/software/gotoblasfaq.php) in the long
list of other BLAS vendors that are covered.

Could you try installing CMake-2.6.1 (or 2.6.2) and edit FindBLAS.cmake to
add a CMake logic stanza corresponding to the GOTOBLAS vendor?  I think it
should look something like this from the above gotoblas FAQ.

if (BLA_VENDOR STREQUAL "GOTOBLAS" OR BLA_VENDOR STREQUAL "All")
  if(NOT BLAS_LIBRARIES)
   check_fortran_libraries(
   BLAS_LIBRARIES
   BLAS
   sgemm
   ""
   "goto;pthread"
   ""
   )
  endif(NOT BLAS_LIBRARIES)
endif (BLA_VENDOR STREQUAL "GOTOBLAS" OR BLA_VENDOR STREQUAL "All")

You may have to experiment a bit to get this to work.
For example, your vendor may have named the usual sgemm routine to something
else.  Also, the above FAQ says link with

g77 -o <your executable> <your object> -lgoto_xxx -lpthread

That's why I included pthread in the stanza above.  However, I am not sure
of the significance of that _xxx since you don't have it in the name of the
library that you used above.  However, if that is significant you will have
to change goto in the above suggested stanza to whatever is appropriate.

Once you have figured out the exact stanza variation that works for you,
please give feedback to the list on it so that Alin can incorporate it into
future versions.  It is only through feedback such as yours that the list of
the many BLAS vendors in FindBLAS.cmake can be extended and maintained.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list