Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 floatingwoods   Members   -  Reputation: 292

Like
0Likes
Like

Posted 18 November 2012 - 02:19 PM

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!

Sponsor:

#2 MJP   Moderators   -  Reputation: 11294

Like
5Likes
Like

Posted 18 November 2012 - 02:53 PM

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.

#3 floatingwoods   Members   -  Reputation: 292

Like
0Likes
Like

Posted 18 November 2012 - 03:02 PM

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?

#4 ApochPiQ   Moderators   -  Reputation: 15683

Like
3Likes
Like

Posted 18 November 2012 - 04:17 PM

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.

#5 floatingwoods   Members   -  Reputation: 292

Like
0Likes
Like

Posted 18 November 2012 - 05:07 PM

Thanks ApochPiQ!!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS