Sunday 24 February 2008
Checking more than one version with pkg-config
By hub, Sunday 24 February 2008 at 11:17 :: Gnome
Sometime you have to check for different versions of a packages with pkg-config
because of new APIs. I had to query the lazyweb and I ended up finding something. Here is the configure.ac snippet I wrote:
GNOMEVFS_VER=0 PKG_CHECK_MODULES(GNOMEVFS, [gnome-vfs-2.0 >= 2.14], [ GNOMEVFS_VER=214 ], [ PKG_CHECK_MODULES(GNOMEVFS, [gnome-vfs-2.0 >= 2.12]) GNOMEVFS_VER=212 ]) GNOMEVFS_CFLAGS="$GNOMEVFS_CFLAGS -DGNOMEVFS_VER=$GNOMEVFS_VER"
Something I haven't seen often is that PKG_CHECK_MODULES
allow found and not found action blocks (yes this is in pkg-config main page). The default not found action is to fail.
The above code works as follow: check the highest version you need, if not found check the one you can eventually go away with. Define a symbol with a numeric version and pass it to the modules CFLAGS.
Then in the code do:
#if GNOMEVFS_VER >= 214 ... #endif