How to nicely handle lots of "define"-related commands

Started by
3 comments, last by floatingwoods 11 years, 5 months ago
Hello,

I have a rather large application that can be compiled for Windows with MFC, for Windows with Qt, for Mac with Qt or for Linux with Qt. For historical reasons I need to keep those 4 configurations in parallel.

I define sections of code for one platform, or for one compiler with "#ifdef BLABLA #else #endif" preprocessor commands. I also have many other defines that are related to the application functionality (e.g. EVALUATION, FULL, LICENSE_CHECK, etc.).

Until now, I had all those important definitions (and new definitions based on those initial definitions) in a precompiled header. But I feel that it is not really elegant. I don't care about compilation speed anyway.

Other people are using "config.h" files, that include all the major defines. But I feel that that 2. method is prone to errors (e.g. what if I forget to include that config header in one file? The file might still be compiled, but not in the desired way and that could cause errors difficult to track.)

Is there a 3rd way? Or any good suggestions?

Thanks!
Advertisement
I suppose the third option would be to pass the macro definitions to the compiler through the command line, which you could set up in your build system.
Thanks for the quick reply MJP!

That 3rd option is a bit tricky, since I have several compilers, and on top of that, I wouldn't be able to pass-in conditional definitions, like:


#define COMPILING_FULL VERSION
//#define COMPILING_EVALUATION_VERSION

#ifdef COMPILING_FULL_VERSION
#define DO_LICENSE_CHECK
#define INCLUDE_ADDITIONAL_FEATURES
#endif

#ifdef COMPILING_EVALUATION_VERSION
#define DISPLAY_EVALUATION_BANNER
#define FORBID_SAVING
#endif


above is a very simple example, but it shows what I need to be doing.

So, between method 1 & 2, which one would be the most appropriate, or the more conventional?
There's another option which is usually employed in large software codebases: create a config.h and then #include that at the top of your (mandatory) PCH.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Thanks ApochPiQ!!

This topic is closed to new replies.

Advertisement