On 2008-01-28 19:45-0800 Radu Serban wrote:

Hi,

I have a couple of questions related to using pkg-config in CMake:

1) Using information returned by the macro pkg_check_module from FindPkgConfig.cmake

This should be straightforward but I just cannot get it to work. Say I create my own library "mylib" which depends on a module "cvodes" which comes with a cvodes.pc file. Adding pkg_check_modules(CVODES cvodes) in CMakelists.txt correctly extracts all the information from cvodes.pc and sets the variables:
===========================
cvodes pkgconfig results:
===========================
PKG_CONFIG_FOUND 1
PKG_CONFIG_EXECUTABLE /usr/bin/pkg-config
CVODES_FOUND 1
CVODES_LIBRARIES sundials_cvodes;sundials_nvecserial;sundials_nvecparallel;m
CVODES_LIBRARY_DIRS /home/radu/CODES/NREL/lib
CVODES_LDFLAGS -L/home/radu/CODES/NREL/lib;-lsundials_cvodes;-lsundials_nvecserial;-lsundials_nvecparallel;-lm
CVODES_LDFLAGS_OTHERS
CVODES_INCLUDE_DIRS /home/radu/CODES/NREL/include
CVODES_CFLAGS -I/home/radu/CODES/NREL/include
CVODES_CFLAGS_OTHERS
============================
I then use include_directories(${CVODES_INCLUDE_DIRS}) and successfully build the library mylib.

But then I'd like to build an example which must be linked with mylib and all CVODES libraries and this is where I got stuck... How do I use the above information? I have
 ADD_EXECUTABLE(testS testS.c)
 TARGET_LINK_LIBRARIES(testS as2)
but how about the CVODES libraries? What's the proper way of linking the target testS to these libraries? I tried unsuccessfully all sort of combinations using TARGET_LINK_LIBRARIES and SET_TARGET_PROPERTIES...

The above commands should be all you need.  CMake is smart enough to keep
track of linking information for each library and use that for each
executable linked to that library.  So it has all the information it needs
to use the correct linking model for any given platform. So I suggest you
test the linking yourself (e.g., with the "ldd -r" command if you have a
Linux platform) and/or run "make VERBOSE=1" to make sure the linking was set
up correctly by CMake.



2) Creating a *.pc file for a project.

Suppose my project creates a library "mylib" which requires the BLAS library. Since I do not have a blas.pc file, I simply use some FindBLAS.cmake file which finds the BLAS library as /usr/lib/libblas.so. When I create mylib.pc I cannot use something like "Requires: blas" because there is no blas.pc so I need to add the BLAS libraries under the "Libs" keyword. Does CMake provide a way of generating the proper string to be added to "Libs:"?

Use TARGET_LINK_LIBRARIES which can accept target names for CMake-generated
libraries as above, full pathnames of external libraries such as libblas, or
even -L and -l options for specifying libraries (not recommended since rpath
does not work right for the build tree in this case).  Those
various possibilities have never been documented, but the PLplot build (for
example) depends on this behaviour for CMake.

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
__________________________
_______________________________________________
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to