Skip to content

config.h is evil

Monday, 6 June 2011  |  David Faure

We often need to check for a system function or library availability, like HAVE_XZ_SUPPORT, and we put that into a cmake-generated file like config.h (much better than -DFOO because changing that requires recompiling everything).

That's fine. However a single config.h at the toplevel of kdelibs is not modular; every change requires recompiling everything, and at some point we would like to split up the libraries to make their adoption easier by other people.

So the idea -- which was started long ago, before kde-4.0 -- is to split that up into one (or more) generated file(s) per library. Modularity "FTW", as kids say these days.

If you would like to help with that work, it's quite easy, see this commit for an example, or this commit for another one (as you can see, this might require duplicating some one-liner checks in some cases, but that's fine, it's the price of modularization).

If you're more adventurous, do it like kdelibs/kdecore/compression, which uses #cmakedefine01 instead of #cmakedefine, in order to always define the symbol (to 0 or 1) in the header file, and then port the code to use #if instead of #ifdef. This is much nicer in fact, because if you forget to include the right <config-foo.h> header, then gcc will warn about it. With ifdef it would just never compile the code in question...

Well, there you go, kdelibs is all yours, I'll go to other issues now :)