[CMake] CMake library installations and pkg-config

Nick Appleton nick at appletonaudio.com
Wed Aug 31 08:51:22 EDT 2016


Hi,

I’ve been recently doing a bit of work for an open source project trying to extend it’s support for CMake. I’ve been trying to get CMake to be able to replicate most of the functionality which can be achieved with the existing autoconf-based infrastructure (and have had pretty good success) but am struggling to figure out how to get CMake to generate pkg-config files on unix-ey systems. I’ve done quite a lot of searching, but have not found anything which provides a good solution for our use case.

The project is called portaudio (a cross-platform, C, real-time audio library) and at present there is one CMakeLists.txt file which does everything (I’ve tried to keep it clean), you can see it here: https://app.assembla.com/spaces/portaudio/git/source/cmake_updates/CMakeLists.txt

It looks for various audio libraries which may be present on the system using find_package() and associates them with the library which it defines using target_link_libraries(). This is all great when my CMake project includes portaudio (via add_subdirectory() and target_link_libraries() with one of the portaudio library targets), but if I want “make install”-like functionality so that others can use a portaudio installation without requiring CMake, I would like to be able to generate a pkg-config file which contains the necessary linker arguments to pass when linking against the library. The generation of the pkg-config file is straight-forward using the configure_file() function, but I am struggling to find a way to: given a CMake target, create a variable containing the set of linker paths and library names to use in the pkg-config file.

Can anyone give me some hints as to whether this is possible?

Cheers,

Nick



More information about the CMake mailing list