While this looks simple, it has two small problems which aren't all that fun.

Firstly, it had what was really quite easily arguably a bug in that it didn't halt the qmake process if a requested package didn't exist. It would happily tell you it didn't exist, and then continue as if nothing had gone wrong, a very annoying problem in large projects:

$ cat test.proCONFIG += link_pkgconfigPKGCONFIG += foobar

$ qmake test.pro:Package foobar was not found in the pkg-config search path.Perhaps you should add the directory containing `foobar.pc'to the PKG_CONFIG_PATH environment variableNo package 'foobar' found

$ echo $?0

Secondly, it wasn't possible to (easily) check for optional dependencies and enable/disable functionality depending on the result of that check.

This has now changed! Thanks to Oswald for merging merge request 1022 into Qt, PKGCONFIG will, in the future, stop on error, and (even more fun) - we can now use the shiny new qmake packagesExist() test function to detect whether a library is installed:

CONFIG += link_pkgconfig

packagesExist(glib-2.0) { DEFINES += HAS_GLIB PKGCONFIG += glib-2.0}

// and in the code:#ifdef HAS_GLIB // use glib here#endif

Much thanks to Marco for prompting me to finally try fix this (I've eternally been annoyed by it, but someone else being frustrated by it made me leap into action), as well as to Oswald, Marius and Arvid for their review and comments during writing, and finally to Murray and Mathias for respectively reporting and trying to patch the first issue in this post, a fact I only became aware of *after* finishing my patch. Great minds think alike, it seems!

The thoughts and opinions of an open source & mobile gadget enthusiast who ran away from Australia and is now surviving in the middle of nowhere in Norway while learning how to love snow, ice, and all things Scandinavian.