Sign in to follow this  
floatingwoods

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

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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:

[code]
#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
[/code]

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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this