patch applied (cabal): Use pkg-config to check for the packages specified in "pkgconfig-depends:"

Duncan Coutts duncan.coutts at
Fri Aug 31 14:45:30 EDT 2007

On Fri, 2007-08-31 at 11:21 -0700, Duncan Coutts wrote:
> Fri Aug 31 10:10:14 PDT 2007  Duncan Coutts <duncan at>
>   * Use pkg-config to check for the packages specified in "pkgconfig-depends:"
>   And fill out the includeDirs, extraLibs, extraLibDirs, ccOptions and ldOptions
>   with the results from pkg-config --cflags --libs

I'm particularly pleased with this. I asked some time ago on this list
if anyone minded adding support for pkg-config and got a favourable

It might seem a bit like we're hard coding features that ought to be
implemented in Setup.hs files but I think this one has a particularly
high power to weight ratio as SPJ would put it. It's just one field in
the .cabal file that follows existing syntax and in the implementation
it's less than 70 lines of code to do the checking for packages and
getting the various flags.

It's also fairly comparable with similar things we already support on
some systems, namely frameworks on OSX and we should but do not yet
support assemblies on Windows.

Frameworks and Assemblies are OS-specific ways of nicely bundling all
the info necessary to link to a package. They have names, versions etc
and the system linkers know how to deal with them.

The nearest equivalent for C packages on unix (though it's also
supported on OSX and Windows) is pkg-config. Libraries install a .pc
file which pkg-config uses to tell build systems how to find and link to
named, versioned packages.

pkg-config can tell us all the C flags and linker flags we need to use a
particular package. On a modern Linux distro there are many hundreds of
C libraries that provide pkg-config .pc files.

So for the increasing number of packages that are binding C libs that
use pkg-config it should now be really easy. No need to put lots of
custom code in Setup.lhs, just add to the .cabal file:

pkgconfig-depends: sdl >= 1.2

or whatever. It follows the same syntax as for build-depends and
build-tools, that is a list package names with optional version ranges. 

The only difference is that pkg-config package names are a bit more
permissive in what characters they allow in names, eg:

pkgconfig-depends: gtk+-2.0 >= 2.10, libcdio_paranoia > 0.7 && < 1.0

BTW, if anyone has got a better suggestion for the name of the field
then just say so.


More information about the cabal-devel mailing list